def load_functions(cls, read, read_all_strings, bits=None): if bits is None: bits = BitAccess(512 * 1024) head = PdbFileHeader(read, bits) reader = PdbStreamHelper(read, head.page_size) directory = MsfDirectory(reader, head, bits) bits1 = BitAccess(512 * 1024) directory.streams[1].read(reader, bits1) name_index, ver, sig, age, guid = PdbFile.load_name_index(bits1) try: name_stream = name_index['/NAMES'] except KeyError: raise PdbException('No "/names" stream') bitsn = BitAccess(512 * 1024) directory.streams[name_stream].read(reader, bitsn) names = PdbFile.load_name_stream(bitsn) bits3 = BitAccess(512 * 1024) directory.streams[3].read(reader, bits3) modules, header = PdbFile.load_dbi_stream(bits3, read_all_strings) func_list = [] # PdbFunction source_dictionary = {} # string -> PdbSource if modules is not None: for m in range(0, len(modules)): if modules[m].stream > 0: bitsm = BitAccess(512 * 1024) directory.streams[modules[m].stream].read(reader, bitsm) PdbFile.load_funcs_from_dbi_module(bitsm, modules[m], names, func_list, read_all_strings, directory, name_index, reader, source_dictionary) funcs = func_list sources = source_dictionary.values() # After reading the functions, apply the token remapping table if it exists. if header.sn_token_rid_map != 0 and header.sn_token_rid_map != 0xffff: directory.streams[header.sn_token_rid_map].read(reader, bits) rid_map = bits.read_uint32(directory.streams[header.sn_token_rid_map].length() / 4) for func in funcs: func.token = 0x06000000 | rid_map[func.token & 0xffffff] funcs.sort(PdbFunction.by_address_and_token) #funcs.sort(PdbFunction.by_token) return funcs, ver, sig, age, guid, sources
def get_pdb_properties(cls, pdb_file): '''Gets the properties of a given pdb. Throws IOException on error''' bits = BitAccess(512 * 1024) with open(pdb_file, 'rb') as pdb_stream: header = PdbFileHeader(pdb_stream, bits) reader = PdbStreamHelper(pdb_stream, header.page_size) directory = MsfDirectory(reader, header, bits) directory.streams[1].read(reader, bits) bits.read_int32() # 0..3 Version bits.read_int32() # 4..7 Signature age = bits.read_int32() # 8..11 Age guid = bits.read_guid() # 12..27 GUID return guid, age
def load_functions(cls, read, read_all_strings, bits=None): if bits is None: bits = BitAccess(512 * 1024) head = PdbFileHeader(read, bits) reader = PdbStreamHelper(read, head.page_size) directory = MsfDirectory(reader, head, bits) bits1 = BitAccess(512 * 1024) directory.streams[1].read(reader, bits1) name_index, ver, sig, age, guid = PdbFile.load_name_index(bits1) try: name_stream = name_index['/NAMES'] except KeyError: raise PdbException('No "/names" stream') bitsn = BitAccess(512 * 1024) directory.streams[name_stream].read(reader, bitsn) names = PdbFile.load_name_stream(bitsn) bits3 = BitAccess(512 * 1024) directory.streams[3].read(reader, bits3) modules, header = PdbFile.load_dbi_stream(bits3, read_all_strings) func_list = [] # PdbFunction source_dictionary = {} # string -> PdbSource if modules is not None: for m in range(0, len(modules)): if modules[m].stream > 0: bitsm = BitAccess(512 * 1024) directory.streams[modules[m].stream].read(reader, bitsm) PdbFile.load_funcs_from_dbi_module( bitsm, modules[m], names, func_list, read_all_strings, directory, name_index, reader, source_dictionary) funcs = func_list sources = source_dictionary.values() # After reading the functions, apply the token remapping table if it exists. if header.sn_token_rid_map != 0 and header.sn_token_rid_map != 0xffff: directory.streams[header.sn_token_rid_map].read(reader, bits) rid_map = bits.read_uint32( directory.streams[header.sn_token_rid_map].length() / 4) for func in funcs: func.token = 0x06000000 | rid_map[func.token & 0xffffff] funcs.sort(PdbFunction.by_address_and_token) #funcs.sort(PdbFunction.by_token) return funcs, ver, sig, age, guid, sources