def _parseGeneral(lines, efifilepath): """ For MSFT, ICC, EBC @param lines line array for map file @return a list which element hold (PcdName, Offset, SectionName) """ status = 0 #0 - beginning of file; 1 - PE section definition; 2 - symbol table secs = [] # key = section name bPcds = [] symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)') for line in lines: line = line.strip() if startPatternGeneral.match(line): status = 1 continue if addressPatternGeneral.match(line): status = 2 continue if line.startswith("entry point at"): status = 3 continue if status == 1 and len(line) != 0: m = secReGeneral.match(line) assert m is not None, "Fail to parse the section in map file , line is %s" % line sec_no, sec_start, sec_length, sec_name, sec_class = m.groups(0) secs.append([int(sec_no, 16), int(sec_start, 16), int(sec_length, 16), sec_name, sec_class]) if status == 2 and len(line) != 0: m = symRe.match(line) assert m is not None, "Fail to parse the symbol in map file, line is %s" % line sec_no, sym_offset, sym_name, vir_addr = m.groups(0) sec_no = int(sec_no, 16) sym_offset = int(sym_offset, 16) vir_addr = int(vir_addr, 16) m2 = symPattern.match(sym_name) if m2 is not None: # fond a binary pcd entry in map file for sec in secs: if sec[0] == sec_no and (sym_offset >= sec[1] and sym_offset < sec[1] + sec[2]): bPcds.append([m2.groups(0)[0], sec[3], sym_offset, vir_addr, sec_no]) if len(bPcds) == 0: return None # get section information from efi file efisecs = PeImageClass(efifilepath).SectionHeaderList if efisecs is None or len(efisecs) == 0: return None pcds = [] for pcd in bPcds: index = 0 for efisec in efisecs: index = index + 1 if pcd[1].strip() == efisec[0].strip(): pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]]) elif pcd[4] == index: pcds.append([pcd[0], efisec[2] + pcd[2], efisec[0]]) return pcds