Git Product home page Git Product logo

capstone-bindings-zig's Introduction

capstone-bindings-zig

Introduction

Capstone natively works with Zig because of translate-c, but i always find it more pleasent to use Zig's features whenever i write anything, so i decided to create those bindings.

Example

Simple example, i believe i snatched it from some of the tests in capstone itself.

Remarks

Warning

The bindings should fully work, however they are not battle-tested yet. If you encounter any Issues / Bugs / API Concerns, please open an Issue.

Future plans

The API is probably not 100% as i want it yet, so changes are to be expected, and that's where especially you, the user comes into play. If you have ideas on how to improve the API design, don't shy away from creating an issue.

Example

const std = @import("std");
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 });
    }
}

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

License

I am not an expert on licenses, but from my understanding bindings can have a different license. So if you're using it in your project, make sure to actually verify that it is compatible with the actual capstone license.

capstone-bindings-zig's People

Contributors

soratenshi avatar atipls avatar

Stargazers

 avatar Silver avatar raf avatar

Watchers

 avatar

Forkers

atipls

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.