diff options
| author | Gabriel Schneider <[email protected]> | 2026-04-06 16:02:29 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-06-08 23:05:25 -0300 |
| commit | f014ba6efb32a80d4f4790880fa88b907b82d756 (patch) | |
| tree | 8cf48255ea8ada324d1876c4ef0c25ecf50b30cd | |
| parent | 4c12cb8aa39035c6ece5efad0971c6de4c2898fe (diff) | |
| download | codenomicon-f014ba6efb32a80d4f4790880fa88b907b82d756.tar.gz codenomicon-f014ba6efb32a80d4f4790880fa88b907b82d756.zip | |
Fix elfo output when no escape codes are supported
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/elfo.zig | 12 | ||||
| -rw-r--r-- | tmp | bin | 0 -> 61772 bytes |
3 files changed, 7 insertions, 6 deletions
@@ -5,3 +5,4 @@ dirty-pin zig-pkg zig-out *a.out +.claude diff --git a/src/elfo.zig b/src/elfo.zig index 264ba4d..e07620c 100644 --- a/src/elfo.zig +++ b/src/elfo.zig @@ -19,7 +19,7 @@ pub fn main(init: std.process.Init.Minimal) !void { _ = args.next(); // skip argv[0] var buffer: [64]u8 = undefined; - const stderr = try io.lockStderr(&buffer, .escape_codes); + const stderr = try io.lockStderr(&buffer, null); // const hook = hooks.init( // if (meta.gdb) .breakpoint else .none, @@ -69,9 +69,9 @@ pub fn printElf( var reader = f.reader(io, buffer); const header = try std.elf.Header.read(&reader.interface); - var handle: usize = undefined; - defer _ = cs.cs_close(@ptrCast(&handle)); - const opts: struct { arch: u64, mode: u64 } = switch (header.machine) { + var cs_handle: usize = undefined; + defer _ = cs.cs_close(@ptrCast(&cs_handle)); + const cs_opts: struct { arch: u64, mode: u64 } = switch (header.machine) { .X86_64 => .{ .arch = cs.CS_ARCH_X86, .mode = cs.CS_MODE_64 }, // The arm mode isn't working with symbols on the .text section correctly .ARM => .{ .arch = cs.CS_ARCH_ARM, .mode = if (header.is_64) cs.CS_MODE_64 else cs.CS_MODE_32 }, @@ -81,7 +81,7 @@ pub fn printElf( }, }; - std.debug.assert(cs.cs_open(@intCast(opts.arch), @intCast(opts.mode), @ptrCast(&handle)) == cs.CS_ERR_OK); + std.debug.assert(cs.cs_open(@intCast(cs_opts.arch), @intCast(cs_opts.mode), @ptrCast(&cs_handle)) == cs.CS_ERR_OK); const shstrtab = blk: { var section_it = header.iterateSectionHeaders(&reader); @@ -290,7 +290,7 @@ pub fn printElf( // TODO: use iter API // https://www.capstone-engine.org/iteration.html // const count = cs.cs_disasm_iter(handle, section_slice.?.ptr, section_slice.?.len, section.sh_addr, @ptrCast(&insn)); - const count = cs.cs_disasm(handle, section_slice.?.ptr, section_slice.?.len, section.sh_addr, 0, @ptrCast(&insn)); + const count = cs.cs_disasm(cs_handle, section_slice.?.ptr, section_slice.?.len, section.sh_addr, 0, @ptrCast(&insn)); break :blk insn[0..count]; }; |
