1. Rewriting hello world

1.1. Disassemble

Ddisasm can be used to disassemble a binary into the GTIRB representation:

ddisasm examples/ex1/ex --ir ex.gtirb

1.2. Transform (optional)

Once you have the GTIRB representation, you can make programmatic changes to the binary using GTIRB or gtirb-rewriting. Take a look at GTIRB’s Documentation and gtirb-rewriting’s Documentation for information about how to examine and transform GTIRB files.

1.3. Reassemble

Once you have made changes to the GTIRB, you can use gtirb-pprinter to produce a new version of the binary:

gtirb-pprinter ex.gtirb -b ex_rewritten

Internally, gtirb-pprinter will generate an assembly file and invoke the compiler/assembler (e.g. gcc) to produce a new binary. gtirb-pprinter will take care or generating all the necessary command line options to generate a new binary, including compilation options, library dependencies, or version linker scripts.

You can also use gtirb-pprinter to generate an assembly listing for manual modification:

gtirb-pprinter ex.gtirb --asm ex.s

This assembly listing can then be manually recompiled:

gcc -nostartfiles ex.s -o ex_rewritten

1.4. Run

You can run the rewritten program now:

./ex_rewritten

Congratulations!