def test_prepare(self): ef = UnpreparedElfFile() sect = UnpreparedElfSection(ef, "test_sect") symtab = UnpreparedElfSymbolTable(ef, ".symtab") for name in ["foo", "bar"]: symtab.add_symbol(ElfSymbol(name, sect)) ef.wordsize = 32 ef.endianess = "<" symtab = symtab.prepare(0x1000, 1, 0)
def _prepare_symbols(self): """Prepare symbol information for the file.""" all_symbols = self.special_symbols[:] for section in self.sections: all_symbols += section.symbols all_symbols.sort(key=lambda x: (x.name, x.value, x.type)) if all_symbols: # Create symbol table symbol_table = self.find_section_named(".symtab") if not symbol_table: symbol_table = UnpreparedElfSymbolTable(".symtab") self.sections.append(symbol_table) symbol_table.clear_table() # Create symbol string table string_table = self.create_and_replace(UnpreparedElfStringTable, ".strtab") symbol_table.link = string_table # Populate the string and symbol tables for symbol in all_symbols: symbol_table.add_symbol(symbol) for symbol in symbol_table.int_syms: string_table.add_string(symbol.name)
def add_symbols(self, symbols): """ Add a list of symbols to this files symbol table. If the symbol table doesn't exit yet, it will be created. symbols: a list of ElfSymbol objects """ symtab = self.get_symbol_table() if symtab is None: # we need to create a symbol table string_table = UnpreparedElfStringTable(self, ".strtab") symtab = UnpreparedElfSymbolTable(self, ".symtab", link=string_table) self.sections.append(string_table) self.sections.append(symtab) for sym in symbols: symtab.add_symbol(sym)
def test_add_symbols(self): ef = UnpreparedElfFile() sect = UnpreparedElfSection(ef, "test_sect") symtab = UnpreparedElfSymbolTable(ef, ".symtab") for name in ["foo", "bar"]: symtab.add_symbol(ElfSymbol(name, sect)) ef = UnpreparedElfFile() sect = UnpreparedElfSection(ef, "test_ect") strtab = UnpreparedElfStringTable(ef, ".strtab") symtab = UnpreparedElfSymbolTable(ef, ".symtab", link=strtab) for name in ["foo", "bar"]: symtab.add_symbol(ElfSymbol(name, sect))
def test_get_file_data(self): ef = UnpreparedElfFile() symtab = UnpreparedElfSymbolTable(ef, ".symtab") self.assertRaises(NotImplementedError, symtab.get_file_data)
def test_init(self): ef = UnpreparedElfFile() symtab = UnpreparedElfSymbolTable(ef, ".symtab")