Esempio n. 1
0
def get_next_map_token(scanner):
    """ Parses next section/symbol from map file

        Scans through the .map file tracked by input MapScannerTracker looking
        for Symbols defined in .map file. Returns the first symbol encountered.

        Args:
            scanner: MapScannerTracker with current tracking info

        Returns:
            Symbol object representing next symbol found. None when EOF is 
            reached
    """
    for line in scanner.fh:
        # look for memory map section
        m = re.search('^Memory Map of the image$', line)
        if m:
            scanner.in_mem_map = True
            continue

        # look for symbols (ish)
        if scanner.in_mem_map:
            m = re.search('((0x)?[0-9A-Fa-f]+)\s+((0x)?[0-9A-Fa-f]+)\s+' + \
                          '([A-Za-z]+)\s+([A-Za-z]+)\s+([0-9]+)\s+(\*\s*)?' + \
                          '([A-Za-z0-9\._]+)\s+([A-Za-z0-9_]+\.lib)', 
                          line)
            if m:
                sym = MapParser.Symbol(int(m.group(1),0), 
                                       int(m.group(3),0), 
                                       "", 
                                       m.group(10),
                                       get_segment(m.group(5), m.group(6)),
                                       m.group(9))
                return sym

    # indicate done scanning
    return None
Esempio n. 2
0
def get_next_map_token(scanner):
    """ Parses next section/symbol from map file

        Scans through the .map file tracked by input MapScannerTracker looking
        for Symbols defined in .map file. Returns the first symbol encountered.

        Args:
            scanner: MapScannerTracker with current tracking info

        Returns:
            Symbol object representing next symbol found. None when EOF is 
            reached
    """
    for line in scanner.fh:
        # look for section header ,support for QSEE.map
        m = re.search('^([0-9a-zA-Z_]+)' + \
                      '(\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+))?\s*$',
        line)
        if m:
            if m.group(2) != None:
                section = MapParser.Section(m.group(1), int(m.group(3), 0),
                                            int(m.group(4), 0))
                scanner.curr_section = section
                #return (section, None)
            else:
                scanner.curr_section_name = m.group(1)
                scanner.split_line_section = True
            continue

        # handle split line header
        if scanner.split_line_section:
            m = re.search('^\s+(0x[0-9a-fA-F]*)\s+(0x[0-9a-fA-F]+)\s*$', line)
            scanner.split_line_section = False
            if m:
                section = MapParser.Section(scanner.curr_section_name,
                                            int(m.group(1), 0),
                                            int(m.group(2), 0))
                scanner.curr_section = section
                #return (section, None)
            continue

        # look for symbol
        m = re.search('^\s?\\(?(\\.?[0-9a-zA-Z_\.]+)(\s+[0-9a-zA-Z_.]+)?(\s+[a-zA-Z_]+\s?\\))?' + \
                      '(\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+.*?([a-zA-Z_0-9]+.lib)+\\((.*)\\))?\s*$',
                      line)
        if m and scanner.curr_section != None:
            if re.search('^debug_', m.group(1)):
                continue
            if m.group(4) != None:
                symbol = MapParser.Symbol(int(m.group(5), 0),
                                          int(m.group(6), 0), m.group(8),
                                          m.group(7),
                                          extract_segment(m.group(1)),
                                          m.group(1))
                #return (scanner.curr_section, symbol)
                scanner.split_line_symbol = False
                return symbol
            elif not "0x" in m.group(1):
                scanner.curr_symbol = m.group(1)
                scanner.split_line_symbol = True
                continue

        # handle split line symbol
        if scanner.split_line_symbol:
            m = re.search('^\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+.*?' + \
                          '([a-zA-Z_0-9]+.lib)+\\((.*)\\)\s*$',
                          line)
            #scanner.split_line_symbol = False
            if m:
                symbol = MapParser.Symbol(int(m.group(1), 0),
                                          int(m.group(2), 0), m.group(4),
                                          m.group(3),
                                          extract_segment(scanner.curr_symbol),
                                          scanner.curr_symbol)
                #return (scanner.curr_section, symbol)
                return symbol
            continue

        # end section on empty line
        m = re.search('^$', line)
        if m:
            scanner.split_line_section = False
            scanner.split_line_symbol = False
            scanner.curr_section = None
            scanner.curr_section_name = ''
            scanner.curr_symbol = None

        # clear split line flags if no matches
        scanner.split_line_section = False
        scanner.split_line_symbol = False

    # indicate done scanning
    #return (None, None)
    return None
Esempio n. 3
0
def get_next_map_token(scanner):
    """ Parses next section/symbol from map file

        Scans through the .map file tracked by input MapScannerTracker looking
        for Symbols defined in .map file. Returns the first symbol encountered.

        Args:
            scanner: MapScannerTracker with current tracking info

        Returns:
            Symbol object representing next symbol found. None when EOF is 
            reached
    """
    for line in scanner.fh:
        # look for section header
        m = re.search('^([0-9_A-Z]+)'+\
                      '(\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+(#)\s+([a-zA-Z]+:)' + \
                      '\s+(0x[0-9a-fA-F,]+)\s+([a-zA-Z:]+)\s+(0x[0-9a-fA-F]+))?\s*$',
                      line)
        if m:
            if m.group(2) != None:
                section = MapParser.Section(m.group(1), int(m.group(3), 0),
                                            int(m.group(4), 0))
                scanner.curr_section = section
                #return (section, None)
            else:
                scanner.curr_section_name = m.group(1)
                scanner.split_line_section = True
            continue

        # handle split line header
        if scanner.split_line_section:
            m = re.search('^\s+(0x[0-9a-fA-F]*)\s+(0x[0-9a-fA-F]+)\s*$', line)
            scanner.split_line_section = False
            if m:
                section = MapParser.Section(scanner.curr_section_name,
                                            int(m.group(1), 0),
                                            int(m.group(2), 0))
                scanner.curr_section = section
                #return (section, None)
            continue

        # look for COMMON symbol

        m = re.search('^([\*\.a-zA-Z0-9_]+)(\([\a-zA-Z\s]+\))(\s+(0x' + \
                      '[0-9a-fA-F]+)\s+.*?([^\\\\/]+\\.lib)\\((.*)\\)(\s+[#A-Z_,\|0-9]+))?\s*$',
                      line)
        if m:
            if scanner.curr_section != None:
                if m.group(2) == "(COMMON )":
                    scanner.split_line_symbol = True
                    scanner.curr_symbol = "COMMON"
                else:
                    scanner.split_line_symbol = False
                    scanner.curr_symbol = None
                continue

        # handle split line symbol
        if scanner.split_line_symbol:
            m = re.search('^\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+.*?' + \
                          '([^\\\\/]+\\.lib)\\((.*)\\)(\s+[#A-Z_,\|0-9]+)\s*$',
                          line)
            if m:
                symbol = MapParser.Symbol(int(m.group(1), 0),
                                          int(m.group(2), 0), m.group(4),
                                          m.group(3),
                                          extract_segment(scanner.curr_symbol),
                                          scanner.curr_symbol,
                                          scanner.curr_section)
                return symbol
            continue
        # look for other symbol
        m = re.search('^([\.a-zA-Z0-9_]+)(\s+(0x[0-9a-fA-F]+)\s+(0x' + \
                      '[0-9a-fA-F]+)\s+.*?([^\\\\/]+\\.lib)\\((.*)\\))(\s+[#A-Z_,\|0-9]*)\s*$',
                      line)
        if m and scanner.curr_section != None:
            scanner.curr_symbol = m.group(1)
            if m.group(2) != None:
                symbol = MapParser.Symbol(int(m.group(3), 0),
                                          int(m.group(4), 0), m.group(6),
                                          m.group(5),
                                          extract_segment(m.group(1)),
                                          m.group(1), scanner.curr_section)
                return symbol
            else:
                scanner.split_line_symbol = True
            continue

        # handle split line symbol
        if scanner.split_line_symbol:
            m = re.search('^\s+(0x[0-9a-fA-F]+)\s+(0x[0-9a-fA-F]+)\s+.*?' + \
                          '([^\\\\/]+\\.lib)\\((.*)\\)\s*$',
                          line)
            scanner.split_line_symbol = False
            if m:
                symbol = MapParser.Symbol(int(m.group(1), 0),
                                          int(m.group(2), 0), m.group(4),
                                          m.group(3),
                                          extract_segment(scanner.curr_symbol),
                                          scanner.curr_symbol,
                                          scanner.curr_section)
                #return (scanner.curr_section, symbol)
                return symbol
            continue

        # end section on empty line
        m = re.search('^$', line)
        if m:
            scanner.split_line_section = False
            scanner.split_line_symbol = False
            scanner.curr_section = None
            scanner.curr_section_name = ''
            scanner.curr_symbol = None

        # clear split line flags if no matches
        scanner.split_line_section = False
        scanner.split_line_symbol = False

    # indicate done scanning
    #return (None, None)
    return None