Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,29 @@ const cs = @import("capstone-z");
const CODE = "\x55\x48\x8b\x05\xb8\x13\x00\x00\xe9\xea\xbe\xad\xde\xff\x25\x23\x01\x00\x00\xe8\xdf\xbe\xad\xde\x74\xff";

pub fn main() !void {
try cs.setup.initCapstone(std.heap.page_allocator);

var handle = try cs.open(cs.Arch.X86, cs.Mode.@"64");
defer cs.close(&handle) catch |e| {
std.debug.print("handle not closed cuz: {any}\n", .{e});
unreachable;
};

const disass = try cs.disasm(handle, CODE, 0x1000, 0);
defer cs.free(disass);

for (disass, 0..) |insn, i| {
std.debug.print("{d}: {*}: 0x{x}\t{s}\t{s}\n", .{ i, &disass.ptr[i], insn.address, insn.mnemonic, insn.op_str });
var handle = try cs.ManagedHandle.init(cs.Arch.X86, cs.Mode.@"64", .{
.syntax = .INTEL,
.detail = true,
.mnemonic = &.{.{ .id = cs.c.X86_INS_JMP, .mnemonic = "our_jmp" }},
});
defer handle.deinit();

var iter = handle.disasmIter(CODE, 0x1000);
var index: usize = 0;
while (iter.next()) |insn| : (index += 1) {
std.debug.print("{d}: 0x{x}\t{s}\t{s}\n", .{ index, insn.address, insn.mnemonic, insn.op_str });
}
}
```

that gives the following output:
```
0: src.insn.Insn@7feca4d0b000: 0x1000 push rbp
1: src.insn.Insn@7feca4d0b0f8: 0x1001 mov rax, qword ptr [rip + 0x13b8]
2: src.insn.Insn@7feca4d0b1f0: 0x1008 jmp 0xffffffffdeadcef7
3: src.insn.Insn@7feca4d0b2e8: 0x100d jmp qword ptr [rip + 0x123]
4: src.insn.Insn@7feca4d0b3e0: 0x1013 call 0xffffffffdeadcef7
5: src.insn.Insn@7feca4d0b4d8: 0x1018 je 0x1019
0: 0x1000 push rbp
1: 0x1001 mov rax, qword ptr [rip + 0x13b8]
2: 0x1008 our_jmp 0xffffffffdeadcef7
3: 0x100d our_jmp qword ptr [rip + 0x123]
4: 0x1013 call 0xffffffffdeadcef7
5: 0x1018 je 0x1019
```

## License
Expand Down