GrammaTech / gtirb

Intermediate Representation for Binary analysis and transformation
https://grammatech.github.io/gtirb/
Other
305 stars 36 forks source link

C++:How to insert assembly instructions containing labels? #66

Open shuxinsun opened 3 months ago

shuxinsun commented 3 months ago

I am trying to insert assembly instructions containing labels into a GTIRB file. Specifically, I want to insert a jmp label, where the label is added using the GTIRB addSymbol() function.

Currently, the method I found for inserting assembly instructions involves converting the instructions into binary sequences using Keystone and then using the provided insertBytes() function. However, there is an issue because Keystone cannot handle labels within the assembly instructions.

Therefore, I would like to know if there are any other ways in GTIRB that I might have overlooked to achieve the insertion of assembly instructions containing labels into a GTIRB file?

aeflores commented 2 months ago

Hi @shuxinsun, I'd suggest trying out our gtirb-rewriting library https://github.com/GrammaTech/gtirb-rewriting this allows you to do higher level modifications to gtirb much more easily.

In particular, take a look at the getting started guide https://github.com/GrammaTech/gtirb-rewriting/blob/main/doc/Getting-Started.md. gtirb-rewriting supports inserting assembly with labels https://github.com/GrammaTech/gtirb-rewriting/blob/main/doc/Getting-Started.md#labels