Пример #1
0
    def testEmbedDataNoSym(self):
        """Test for GetSymbolFileOffset() getting no symbols"""
        if not elf.ELF_TOOLS:
            self.skipTest('Python elftools not available')

        fname = self.ElfTestFile('embed_data')
        offset = elf.GetSymbolFileOffset(fname, ['missing_sym'])
        self.assertEqual({}, offset)
Пример #2
0
 def testEmbedFail(self):
     """Test calling GetSymbolFileOffset() without elftools"""
     try:
         old_val = elf.ELF_TOOLS
         elf.ELF_TOOLS = False
         fname = self.ElfTestFile('embed_data')
         with self.assertRaises(ValueError) as e:
             elf.GetSymbolFileOffset(fname, ['embed_start', 'embed_end'])
         self.assertIn("Python: No module named 'elftools'",
                       str(e.exception))
     finally:
         elf.ELF_TOOLS = old_val
Пример #3
0
    def testEmbedData(self):
        """Test for the GetSymbolFileOffset() function"""
        if not elf.ELF_TOOLS:
            self.skipTest('Python elftools not available')

        fname = self.ElfTestFile('embed_data')
        offset = elf.GetSymbolFileOffset(fname, ['embed_start', 'embed_end'])
        start = offset['embed_start'].offset
        end = offset['embed_end'].offset
        data = tools.read_file(fname)
        embed_data = data[start:end]
        expect = struct.pack('<III', 0x1234, 0x5678, 0)
        self.assertEqual(expect, embed_data)
Пример #4
0
def show_event_spy_list(fname, endian):
    """Show a the event-spy- list from a U-Boot image

    Args:
        fname (str): Filename of ELF file
        endian (str): Endianness to use ('little', 'big', 'auto')
    """
    syms = elf.GetSymbolFileOffset(fname, [PREFIX])
    data = tools.read_file(fname)
    print('%-20s  %-30s  %s' % ('Event type', 'Id', 'Source location'))
    print('%-20s  %-30s  %s' % ('-' * 20, '-' * 30, '-' * 30))
    for name, sym in syms.items():
        m_evtype = RE_EVTYPE.search(name)
        evtype = m_evtype.group(1)
        show_sym(fname, data, endian, evtype, sym)