How zyantific/zasm works
Project type and purpose
• Zasm is a C++ library for assembling, decoding, formatting, and serializing x86-64 machine code.
• It sits on top of the Zydis decoder/encoder backend to provide a higher-level API (Program, Assembler, Serializer, Decoder).
File structure
• Top-level directories:
• zasm/include & zasm/src: the core library modules
• examples: client code demonstrating usage
• benchmark: performance tests using the library
• tests: unit tests exercising all features
• thirdparty: build/tooling support (cmkr/CMake)
• Within zasm/include & src, submodules reflect architectural areas:
• core: streams, error handling, pools, strong types
• decoder: binary→Instruction
• encoder/formatter: Instruction→binary text/format
• program: node container (instructions, labels, sections)
• serialization: converting Program nodes into flat binary
• x86: assembler macros, register definitions, emitter
Extract insights from README
• Main API abstractions: Program, Assembler, Serializer, Decoder
• Design goals: lightweight, node-based code manipulation, accurate operand/flag info
• Builder uses CMake + cmkr for build configuration
• Examples & tests demonstrate all paths
Main components and their interactions
• Clients (examples, benchmarks, tests) → Zasm API
• Zasm API layers:
a. Program: holds node list (instructions, labels, data, sections)
b. Assembler: emits nodes into Program (uses x86 assembler)
c. Decoder: uses Zydis to parse existing binary into Instruction nodes
d. Serializer: walks Program nodes, emits raw binary, produces metadata (label addresses, relocations)
• Core utilities (memory/file streams, stringpool, objectpool, error handling) support all layers
• Encoder/formatter: depth of instruction encoding & textual representation
• x86 module: CPU-specific encodings, mnemonics, register definitions, emitter logic
• External dependency: Zydis (third-party library)
Architectural patterns & design principles
• Node-based doubly linked list (Program) allows insertion, removal, reordering
• Separation of concerns:
• decoding (binary→node) vs. assembly (API calls→node)
• serialization (node→binary) vs. formatting (node→text)
• Factory/generator pattern in Assembler (generated member functions per instruction)
• Strongly typed operands & flags
Detail level
• Don’t just show “Library”—split it into its submodules (Program, Assembler, Decoder, Serializer).
• That Program is the central node container.
• How x86-specific code sits under Assembler/Encoder.
• External Zydis dependency both in Decoder and Encoder phases.
• Lifecycles: decode → transform → serialize.