예제 #1
0
 def get_extdef_symbols(self, machos) -> list:
     '''
     get external reference symbol indices
     '''
     temp_list = []
     temp_s = SymbolTable.SymbolTable(machos)
     for (nlist, name) in temp_s.extdefsyms:
         temp_list.append({"Symbol":name.decode("utf-8", errors="ignore"),
                           "Description":""})
     return temp_list
예제 #2
0
 def get_local_symbols(self,machos) -> list:
     '''
     get local symbols
     '''
     _list = []
     s = SymbolTable.SymbolTable(machos)
     for (nlist, name) in s.localsyms:
         _list.append({  "Symbol":name.decode("utf-8",errors="ignore"),
                         "Description":""})
     return _list
예제 #3
0
 def get_undef_symbols(self, machos) -> list:
     '''
     get undefined symbols
     '''
     temp_list = []
     temp_s = SymbolTable.SymbolTable(machos)
     for (nlist, name) in temp_s.undefsyms:
         temp_list.append({"Symbol":name.decode("utf-8", errors="ignore"),
                           "Description":""})
     return temp_list
예제 #4
0
    def _load_symbol_table(self):
        stable = MachOLoaderSymbolTable.SymbolTable(self._header.parent)

        # Parse out stable.extdefsyms
        for esym in stable.extdefsyms:
            sym = esym[0]
            sym_str = esym[1] # No need to decode, apparently :-)
            s = SymbolTableSymbol(self, sym_str, sym.n_type, sym.n_sect, sym.n_desc, sym.n_value - self.linked_base) 
            self.symbols.add(s)

        # Parse out stable.undefsyms
        for usym in stable.undefsyms:
            sym = usym[0]
            sym_str = usym[1]
            s = SymbolTableSymbol(self, sym_str, sym.n_type, sym.n_sect, sym.n_desc, sym.n_value - self.linked_base) 
            self.symbols.add(s)

        for lsym in stable.localsyms:
            sym = lsym[0]
            sym_str = lsym[1]
            s = SymbolTableSymbol(self, sym_str, sym.n_type, sym.n_sect, sym.n_desc, sym.n_value - self.linked_base) 
            self.symbols.add(s)
예제 #5
0
# load commands
for c in a.headers[0].commands:
    print(c[0])
    if c[0].cmd == 25:
        print(c[1])
        for section in c[2]:
            print(section.segname.strip(b'\0'), section.sectname.strip(b'\0'),
                  hex(section.addr), hex(section.size), "@", hex(c[1].fileoff))
            #print(dir(section))
            if c[1].filesize > 0:
                hexdump(section.section_data)

# this parser is wrong (fixed with 64-bit one)
from macholib import SymbolTable
sym = SymbolTable.SymbolTable(a)

syms = {}
for l in sym.nlists:
    print(l)
    if l[0].n_value != 0:
        syms[l[1]] = l[0].n_value

for k, v in syms.items():
    print(k, hex(v))

from termcolor import colored


def compare(x, y):
    ss = []