Ejemplo n.º 1
0
 def format_name(self, name, addr, bases, sorted_mods):
     if name == "unknown":
         idx = bisect.bisect_right(bases, addr) - 1
         mod_base, mod_size, mod_name = sorted_mods[idx]
         if mod_base <= addr < mod_base + mod_size:
             name = str(mod_name) + ("+%#x" % (addr - mod_base))
     else:
         # Try to undecorate
         mod, fn = name.split('!', 1)
         fn = fn.rsplit('+', 1)
         if len(fn) > 1:
             fn, offset = fn
         else:
             fn, offset = fn[0], ""
         fn = und.undname(fn)
         name = '!'.join((mod, fn))
         if offset: name = "+".join((name, offset))
     return name
Ejemplo n.º 2
0
 def _parseSymbols(self, pdb):
     try:
         sects = pdb.STREAM_SECT_HDR_ORIG.sections
         omap = pdb.STREAM_OMAP_FROM_SRC
     except AttributeError:
         sects = pdb.STREAM_SECT_HDR.sections
         omap = DummyOmap()
     gsyms = pdb.STREAM_GSYM
     for sym in gsyms.globals:
         try:
             off = sym.offset
             if len(sects) < sym.segment:
                 continue
             virt_base = sects[sym.segment - 1].VirtualAddress
             function_address = (self._base_addr +
                                 omap.remap(off + virt_base))
             demangled_name = undname(sym.name)
             if sym.symtype == 2:
                 # print("0x%x + 0x%x + 0x%x = 0x%x: %s || %s (type: %d)" % (self._base_addr, off, virt_base, function_address, sym.name, demangled_name, sym.symtype))
                 self._func_symbols[function_address] = demangled_name
         except AttributeError:
             pass
Ejemplo n.º 3
0
def make_pdb_profile(filepath):
    filepath = filepath + ".pdb"
    pdb = pdbparse.parse(filepath)

    try:
        sects = pdb.STREAM_SECT_HDR_ORIG.sections
        omap = pdb.STREAM_OMAP_FROM_SRC
    except AttributeError as e:
        # In this case there is no OMAP, so we use the given section
        # headers and use the identity function for omap.remap
        sects = pdb.STREAM_SECT_HDR.sections
        omap = DummyOmap()

    gsyms = pdb.STREAM_GSYM
    profile = {"$FUNCTIONS": {}, "$CONSTANTS": {}, "$STRUCTS": {}}
    struct_specs = {
        structName: process_struct(pdb.STREAM_TPI.structures[structName])
        for structName in pdb.STREAM_TPI.structures.keys()
    }
    for structName, structFields in struct_specs.items():
        profile["$STRUCTS"][structName] = structFields

    for sym in gsyms.globals:
        try:
            off = sym.offset
            sym_name = sym.name
            virt_base = sects[sym.segment - 1].VirtualAddress
            mapped = omap.remap(off + virt_base)
            is_function = (sym.symtype & 2) == 2
        except IndexError as e:
            # skip symbol because segment was not found
            continue
        except AttributeError as e:
            # missing offset in symbol?
            continue

        if sym_name.startswith("?"):
            sym_name = undname(sym_name)

        if is_function:
            profile["$FUNCTIONS"][sym_name] = mapped
        else:
            profile["$CONSTANTS"][sym_name] = mapped

    guid = pdb.STREAM_PDB.GUID
    guid_str = "%.8X%.4X%.4X%s" % (guid.Data1, guid.Data2, guid.Data3,
                                   guid.Data4.hex().upper())
    symstore_hash = "%s%s" % (guid_str, pdb.STREAM_PDB.Age)
    base_fn = os.path.splitext(os.path.basename(filepath))[0]

    profile["$METADATA"] = {
        "GUID_AGE":
        symstore_hash,
        "PDBFile":
        os.path.basename(filepath),
        "ProfileClass":
        base_fn[0].upper() + base_fn[1:].lower(),
        "Timestamp":
        pdb.STREAM_PDB.TimeDateStamp.replace(
            tzinfo=None).strftime("%Y-%m-%d %H:%M:%SZ"),
        "Type":
        "Profile",
        "Version":
        pdb.STREAM_PDB.Version
    }
    print(json.dumps(profile, indent=4, sort_keys=True))