wrote horrible hack for the PLT problem

This commit is contained in:
George Hotz 2015-03-21 13:42:49 -07:00
parent ed3bd00c42
commit ade5599f35
5 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -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'])

BIN
tests_manual/double_link Executable file

Binary file not shown.

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include <math.h>
int main(int argc) {
printf("hello: %f\n", sin(argc));
}

BIN
tests_manual/double_link_64 Executable file

Binary file not shown.