For example I have following c++ source file
// define global variables here
int Label = 1234;
char Hash[] = "0x11231abc";
compile this to *.o file, and may be later linked to an executable binary. Is it possible to get the value from ELF file by using some existing tools, like readelf, objdump?
Is it possible to get the value from ELF file by using some existing tools, like readelf, objdump?
Whether this is possible at all depends on how exactly these variables are used, whether they are local or global, whether they have their address taken, which compiler is used and what optimizations are in effect.
If the variables are global and the code is not optimized, sure some combination of readelf
and objdump
commands could possibly get you the answer.
In general, GDB would be a better tool to use here.