zasm Documentation

repository·master·Indexed 19 days ago

https://github.com/zyantific/zasm

A flexible, lightweight C++ library for manipulating and generating x86-64 code using Zydis as a backend. It features a node-based Program representation, an Assembler for emitting instructions, a Serializer for binary conversion, and a Decoder for converting binary data into Instruction objects.

Tokens
472
Snippets
2
Records
3
Agent score
16%

What's inside zasm

  1. How Zasm's core components work together

    master

    Zasm is designed as a high-level assembler and decoder for x86-64 code, using Zydis as a backend. It operates through four primary abstractions:

    1. Program: The central container. It acts as a doubly linked list of nodes (instructions, labels, data, sections, etc.), allowing you to easily insert, remove, or re-order code elements.
    2. Assembler: The interface used to populate a Program. It provides member functions to emit instructions and data at a specific cursor position within the program.
    3. Serializer: Converts the Program nodes into actual binary. Once serialized, you can query the resulting binary for label addresses, relocation information, and section data.
    4. Decoder: Converts existing binary data into Instruction objects, which can then be used directly or inserted into a Program for manipulation.
  2. Build Zasm from source

    master

    Zasm uses CMake and cmkr for its build system. You can build the library using the following commands from the root directory of the repository.

    To build the Release version:

    cmake . -B build
    cmake --build build --config Release

    To build the library including the test suite:

    cmake . -B build -DZASM_BUILD_TESTS=ON
  3. Use the Assembler to generate instructions

    master

    The Assembler class provides a high-level API for emitting x86-64 instructions into a Program. The API is inspired by AsmJit. To emit an instruction, you call the corresponding member function on the assembler instance, passing in operands.

    Example of emitting mov rax, -1:

    // Assuming 'assembler' is an instance of the Assembler class
    // and 'operands' is the namespace for instruction operands
    assembler.mov(operands::rax, operands::Imm(-1));
    // To emit mov rax, -1
    asssembler.mov(operands::rax, operands::Imm(-1));