modify build-id in the notes section of the elf file

跟風遠走 提交于 2021-01-29 13:49:31

问题


I need to modify a build-id in the notes section of the ELF file. I see there are plenty of tools to read elf but not to modify them. I found elfedit but it doesn't seem to do what I need. Is it even possible?

Here is the output of readelf

$ readelf -n myelffile 
Displaying notes found in: .note.ABI-tag
  Owner                Data size        Description
  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)
    OS: Linux, ABI: 3.14.0

Displaying notes found in: .note.gnu.build-id
  Owner                Data size        Description
  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)
    Build ID: d75a086c288c582036b0562908304bc3a8033235

I'm trying to modify .note.gnu.build-id section.


回答1:


Is it even possible?

Yes. This is one of the easier modifications, since the data in the note is completely arbitrary, and no other data refer to it.

All you have to do is find the .note section, decode each note in turn until you find the one with NT_GNU_BUILD_ID type, and overwrite its data with same-length bytes of your choosing.

Are you aware of the linker --build-id 0x.... option which allows you to put in whatever hex data you desire at link time? If you can relink your binary, then you wouldn't need to modify the build-id note, as the linker will happily put your data there during the initial link.



来源:https://stackoverflow.com/questions/63382584/modify-build-id-in-the-notes-section-of-the-elf-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!