From f014ba6efb32a80d4f4790880fa88b907b82d756 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 6 Apr 2026 16:02:29 -0300 Subject: Fix elfo output when no escape codes are supported --- src/elfo.zig | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/elfo.zig') 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]; }; -- cgit v1.3