diff --git a/static2/builtin/loader.py b/static2/builtin/loader.py index dba20cc4..726297aa 100644 --- a/static2/builtin/loader.py +++ b/static2/builtin/loader.py @@ -34,10 +34,15 @@ def load_binary(static): if addr != 0 and slen > 0: static.add_memory_chunk(addr, section.data()) + if static.debug >= 1: + print "** found section", section.name, type(section) + + if isinstance(section, RelocationSection): symtable = elf.get_section(section['sh_link']) if symtable.is_null(): continue + for rel in section.iter_relocations(): symbol = symtable.get_symbol(rel['r_info_sym']) if static.debug >= 1: #suppress output for testing @@ -46,13 +51,39 @@ def load_binary(static): static[rel['r_offset']]['name'] = "__"+symbol.name ncount += 1 + # hacks for PLT + # TODO: this is fucking terrible + if section.name == '.rel.plt': + # first symbol is blank + plt_symbols = [] + for rel in section.iter_relocations(): + symbol = symtable.get_symbol(rel['r_info_sym']) + plt_symbols.append(symbol.name) + + # does this change? + PLT_ENTRY_SIZE = 0x10 + + for section in elf.iter_sections(): + if section.name == ".plt": + for name, addr in zip(plt_symbols, + range(section['sh_addr'] + PLT_ENTRY_SIZE, + section['sh_addr'] + PLT_ENTRY_SIZE + PLT_ENTRY_SIZE*len(plt_symbols), + PLT_ENTRY_SIZE)): + static[addr]['name'] = name + print plt_symbols, section['sh_addr'] + + if isinstance(section, SymbolTableSection): for nsym, symbol in enumerate(section.iter_symbols()): + #print symbol['st_info'], symbol.name, hex(symbol['st_value']) if symbol['st_value'] != 0 and symbol.name != "" and symbol['st_info']['type'] == "STT_FUNC": if static.debug >= 1: - print "Symbol",symbol['st_value'], symbol.name + print "Symbol",hex(symbol['st_value']), symbol.name static[symbol['st_value']]['name'] = symbol.name ncount += 1 + + # parse the DynamicSection to get the libraries + #if isinstance(section, DynamicSection): if static.debug >= 1: print "** found %d names" % ncount diff --git a/static2/static2.py b/static2/static2.py index 87244561..5d8735a8 100755 --- a/static2/static2.py +++ b/static2/static2.py @@ -227,6 +227,13 @@ if __name__ == "__main__": for a in sorted(b.addresses): print " ",hex(a),static._insert_names(static[a]['instruction']) + + # print symbols + print "symbols" + names = static.get_tags(['name']) + for addr in names: + print "%8x: %s" % (addr, names[addr]['name']) + #print static['functions'] #print static[main]['instruction'], map(hex, static[main]['crefs']) diff --git a/tests_manual/double_link b/tests_manual/double_link new file mode 100755 index 00000000..8a2e90fd Binary files /dev/null and b/tests_manual/double_link differ diff --git a/tests_manual/double_link.c b/tests_manual/double_link.c new file mode 100644 index 00000000..43b8318c --- /dev/null +++ b/tests_manual/double_link.c @@ -0,0 +1,8 @@ +#include +#include + +int main(int argc) { + printf("hello: %f\n", sin(argc)); +} + + diff --git a/tests_manual/double_link_64 b/tests_manual/double_link_64 new file mode 100755 index 00000000..e1e5e232 Binary files /dev/null and b/tests_manual/double_link_64 differ