Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficiently adding a new section in an ELF file

I want to add a new section to an ELF file (say E) which stores the integrity hash of .text section. Assume I chunk the .text section into T1,T2..Tn and get the hash H1,H2..Hn and add all hashes to the E in a new .my_hash section.

One naive way to do this would be to

  • Scan file E and compute/store the hashes in a separate binary file B
  • Convert B to B.o file
  • Do objcopy --rename_section to rename .data section to .my_hash section
  • Finally merge E.o (which assume I also have before generating E) and B.o

Any better way to do this?

like image 949
Paarth Avatar asked Jan 25 '26 14:01

Paarth


1 Answers

Use objcopy --add-section. You may want --set-section-flags as well.

like image 180
Tom Tromey Avatar answered Jan 28 '26 10:01

Tom Tromey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!