Intel® X86 Encoder Decoder
Loading...
Searching...
No Matches
Examples of using Intel® XED

The source code for the examples is in the "examples" subdirectory.

To compile the examples manually please see Small Examples of using Intel® XED

There are several examples, mainly:

  • xed.c: This is the main Intel® XED example. It's a complete example touching down on most of Intel® XED's capabilities and APIs, including decoding, encoding, image file reading and chip-check APIs and functionality.
  • xed-dec.c: A quintessential decoder example that uses most of the decode APIs. It is recommended for users who want to deeply understand the numerous APIs for decoded instructions and their usages. This is included in the "Small Examples" section below. It is a good example for using the major decoder APIs. This example supports emitting detailed instruction metadata: prefixes, CPUID leaves, rounding modes, branch-hints, flags, operands and more. This example can also elaborate on EVEX/VEX prefix bit info using a specified verbosity mode. It supports CPUID-based defeaturing as well.
  • xed-enc.c: A lightweight encoder example used to parse command line arguments and encode them into a stream of bytes. For more insight on the encode request syntax and the encoder examples, please see Intel® XED command interface page.
  • xed-dec-control.c: A simple decoder example with different disassembly output formats. It contains highly descriptive usages of the new decode-with-features APIs.
  • xed-enc-direct.c: A simple non-dynamic encoder example using the high-level encoding API.
  • xed-enc-override.c: A non-dynamic example that shows how to patch (modify) the xed_encoder_instruction data structure yielded from the encoder.
  • xed-enc-asmparse.c: A unique encoder example showcasing how to process command-line encode requests in assembly format It allows processing multiple requests separated by a semicolon. This is different from other encoder examples in that the input is not in Intel® XED encode request format.

Other specific use-case examples:

  • xed-enc2.c: This example showcase the use of ENC2 encode APIs. ENC2 is our much faster, low-level encoder.
  • xed-dec-agen.c: Creates an artificial AGEN (address generation) calculator for testing and works as a valuable example for using xed_agen API.
  • xed-dec-ild.c: An example for using the instruction length decoder API. This example loads only the xed-ild library.
  • xed-tables.c: An example that shows how to access Intel® XED's internal tables, which contain static data for all Intel® XED-supported instructions.
  • xed-rep-string.c: Shows the use of the REP prefix APIs, which basically returns the non-REP variant of a REP ICLASS and vice versa.

The above examples use the following utilities to process different inputs:

  • xed-util-disas-elf: Used to disassemble ELF (Executable and Linkable Format) binaries. If the binary contains DWARF debugging information (generated by the compiler in a specific format), this example can map addresses to source code line numbers, making it easier to correlate the disassembled code with the original source code.
  • xed-util-disas-macho: Useful for disassembling Mach-O binaries on macOS.
  • xed-util-disas-hex: Used to disassemble hexadecimal byte sequences from a file.
  • xed-util-disas-raw: Used to disassemble raw binary data.
  • xed-util-disas-pecoff: Used to disassemble PE/COFF (Portable Executable/Common Object File Format) binaries on Windows.
  • xed-util-enc-lang: A very detailed component that shows how to parse encode requests from the command line and then perform the encoding.
  • xed-util-dot: Generates a dependency graph from a set of decoded instructions and pours the results into a dot file. The dot file can be converted into a .png to visualize the results. Each node represents an instruction, an edge is added based on dependency between involved regs (RAW, WAW, WAR).

The examples are described in the following subsections: