示例#1
0
def _parseForGCC(lines, efifilepath):
    """ Parse map file generated by GCC linker """
    dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')
    status = 0
    imageBase = -1
    sections = []
    bpcds = []
    for index, line in enumerate(lines):
        line = line.strip()
        # status machine transection
        if status == 0 and line == "Memory Configuration":
            status = 1
            continue
        elif status == 1 and line == 'Linker script and memory map':
            status = 2
            continue
        elif status == 2 and line == 'START GROUP':
            status = 3
            continue

        # status handler
        if status == 3:
            m = valuePatternGcc.match(line)
            if m is not None:
                sections.append(m.groups(0))
        if status == 3:
            m = dataPattern.match(line)
            if m is not None:
                if lines[index + 1]:
                    PcdName = m.groups(0)[0]
                    m = pcdPatternGcc.match(lines[index + 1].strip())
                    if m is not None:
                        bpcds.append(
                            (PcdName, int(m.groups(0)[0],
                                          16), int(sections[-1][1],
                                                   16), sections[-1][0]))

    # get section information from efi file
    efisecs = PeImageClass(efifilepath).SectionHeaderList
    if efisecs is None or len(efisecs) == 0:
        return None
    #redirection
    redirection = 0
    for efisec in efisecs:
        for section in sections:
            if section[0].strip() == efisec[0].strip() and section[0].strip(
            ) == '.text':
                redirection = int(section[1], 16) - efisec[1]
    pcds = []
    for pcd in bpcds:
        for efisec in efisecs:
            if pcd[1] >= efisec[1] and pcd[1] < efisec[1] + efisec[3]:
                #assert efisec[0].strip() == pcd[3].strip() and efisec[1] + redirection == pcd[2], "There are some differences between map file and efi file"
                pcds.append([
                    pcd[0], efisec[2] + pcd[1] - efisec[1] - redirection,
                    efisec[0]
                ])
    return pcds
示例#2
0
def _parseForGCC(lines, efifilepath):
    """ Parse map file generated by GCC linker """
    dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')
    status = 0
    imageBase = -1
    sections = []
    bpcds = []
    for index, line in enumerate(lines):
        line = line.strip()
        # status machine transection
        if status == 0 and line == "Memory Configuration":
            status = 1
            continue
        elif status == 1 and line == 'Linker script and memory map':
            status = 2
            continue
        elif status ==2 and line == 'START GROUP':
            status = 3
            continue

        # status handler
        if status == 3:
            m = valuePatternGcc.match(line)
            if m is not None:
                sections.append(m.groups(0))
        if status == 3:
            m = dataPattern.match(line)
            if m is not None:
                if lines[index + 1]:
                    PcdName = m.groups(0)[0]
                    m = pcdPatternGcc.match(lines[index + 1].strip())
                    if m is not None:
                        bpcds.append((PcdName, int(m.groups(0)[0], 16), int(sections[-1][1], 16), sections[-1][0]))

    # get section information from efi file
    efisecs = PeImageClass(efifilepath).SectionHeaderList
    if efisecs is None or len(efisecs) == 0:
        return None
    #redirection
    redirection = 0
    for efisec in efisecs:
        for section in sections:
            if section[0].strip() == efisec[0].strip() and section[0].strip() == '.text':
                redirection = int(section[1], 16) - efisec[1]
    pcds = []
    for pcd in bpcds:
        for efisec in efisecs:
            if pcd[1] >= efisec[1] and pcd[1] < efisec[1]+efisec[3]:
                #assert efisec[0].strip() == pcd[3].strip() and efisec[1] + redirection == pcd[2], "There are some differences between map file and efi file"
                pcds.append([pcd[0], efisec[2] + pcd[1] - efisec[1] - redirection, efisec[0]])
    return pcds