I will take a stab at the first question since Samir answered the second one so well.
The symbol's name will be in one of the STRTAB
sections, and then there will be an entry in the symbol table (one of the SYMTAB
or DYNSYM
sections) which references that string by an offset in the containing section. The entry in the symbol table can tell you the index of the section this symbol is found in, but not where it is used.
For that you need to check the relocation table, contained in sections of type REL
; common names include .rel.dyn
, .rel.plt
. A relocation table lists all the references to symbol in one other code section, i.e. code and relocation sections are paired. Each entry in the table is one "usage" of a symbol, and contains the offset in the corresponding section where the usage is and the index of the symbol in the symbol table.
If you can use the readelf
utility, you can easily use readelf -r <binary> | grep <symbol name>
to get all the references to a symbol.
If you are set on using hexedit/cannot use readelf, then you would need to
Find the offset of the symbol name string in the binary, what section that is in, and then get the offset of that string in that section;
Look through all the entries in the symbol table and find which one(s) match that name (st_name
== offset of string in the string section);
Look through all entries in each relocation table to find symbol usages of that symbol in the corresponding code section for that table. The r_info
field of each entry contains the index of the symbol table entry it references (this index is bitmapped to part of r_info
, and at different places for 32- and 64-bit).
All relocation entries matching that symbol table index are usages of your string somewhere.
More info: