GrammaTech / gtirb

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

Is there any simple way to add/delete instruction or data section etc?? #44

Closed swang206 closed 2 years ago

swang206 commented 3 years ago

I just read code from gtirb-stack-stamp, but I feel it is too complex and not generic. It does not work on windows executable for example. https://github.com/GrammaTech/gtirb-stack-stamp/blob/5586ffb6e8ba2e929f974bb225335777e99721a5/src/gtirb_stack_stamp.cpp#L114

For example, I want to modify a string literal in the binary, it looks it is very hard with this.

jdorn-gt commented 3 years ago

You may find gtirb-rewriting more convenient as a starting point. It is a Python API for modifying the code represented by a GTIRB IR. The getting started guide in that repository has some examples of how to add or delete instructions.

Neither gtirb-rewriting nor gtirb-stack-stamp includes any examples of modifying string literals. To do that, you will need to find the Symbol referring to the literal you want to change, get the Symbol's referent, then get the referent's ByteInterval so you can modify the bytes at that location. If the new string is a different size than the original, you will also need to update the referent's size appropriately.