1

I would like to modify the value of a global variable in an elf file i.e.

int variable = 10;

I see that first I would have to open the elf file. This answer has a short program to open up an elf file,

finding integer declared variables in ELF executable using a hex editor

then I would've to find the virtual address of the global variable using maybe readelf as in this other solution

https://stackoverflow.com/questions/20671194/finding-integer-declared-variables-in-elf-executable-using-a-hex-editor

but instead of modifying the variable using a hex editor, I want to edit it in C using the Section header(Sdhr) struct members from the elf.h file. Hopefully my question makes sense...

PolarBear
  • 41
  • 7
  • 1
    Your question does make sense but it is a bit too broad to be answered concisely. Suggest using libelf from [elfutils](https://sourceware.org/elfutils/) to read and write the elf data. – kaylum Jun 12 '20 at 04:35
  • Well, go ahead and try it. – the busybee Jun 12 '20 at 06:03
  • thanks for the answers. I just found this book https://www.dbooks.org/libelf-by-example-1587/read/ l think its intended for the same library. might be a good starting point... – PolarBear Jun 12 '20 at 14:01
  • @kaylum does elfutils work on Ubuntu? or is it just intended for Red Hat only? – PolarBear Jun 16 '20 at 16:06
  • elfutils doesn't care about the specific Linux distro. If it is Linux then it will almost certainly work. – kaylum Jun 16 '20 at 22:41
  • @kaylum hey thanks. I was able to install elf utils this morning. I was wondering if there is a wiki or any other documentation on how to use elfutils. I couldn't find much so far. I would really appreciate it. – PolarBear Jun 16 '20 at 22:54

0 Answers0