List global variables in executable
Domanda
How can I dump all the global variables and the address offsets in my executable?
This is on os x, app developed with xcode compiled with gcc.
Thank you
Soluzione
If Compiled to Mach-O
Either use otool
or the cctools
.
If Compiled to ELF
You should be able to do this with objdump
and/or readelf
.
I don't have a *nix system at hand here, but objdump -s -j .data
should be getting you rather close enough.
Altri suggerimenti
An easy way to get a list of global variables and their offsets from an executable on macOS (original question) is to use the nm
tool. Without any additional keys, it gives the variables and their offsets.
Example:
$ nm <some binary>
...
U __ZTVN10__cxxabiv117__class_type_infoE
U __ZTVN10__cxxabiv120__si_class_type_infoE
000000010006e248 s __ZTVN7testing17TestEventListenerE
000000010006e1c0 s __ZTVN7testing22EmptyTestEventListenerE
000000010006dfa8 s __ZTVN7testing31TestPartResultReporterInterfaceE
000000010006d860 S __ZTVN7testing32ScopedFakeTestPartResultReporterE
000000010006d8d8 S __ZTVN7testing4TestE
...
Check man nm
for the explanation of the codes like U
, s
, S
, etc.
In case you also want to look for string constants, there is another tool strings
:
$ strings <some binary> -o -t x
will give you a list of string literals and their offsets.
See man strings
for more details.