def testParseSymbolText(self):
   symbol_text = (
       '0 g     F .text  e8 Foo\n'
       '0000dead  w    F .text  000000e8 .hidden Bar\n'
       'deadbeef l     O .bss   00000004 .hidden Woooo\n'
       'deadbee g     O .rodata        00000008 __Hooo_ooo\n'
       'deadbee g       .rodata        00000000 __foo_doo_coo_end\n'
   )
   symbols = sa.ParseSymbolText(symbol_text)
   expect_symbols = [sa.Symbol(0x0, 'F', 0xe8, 'Foo'),
                     sa.Symbol(0xdead, 'F', 0xe8, 'Bar'),
                     sa.Symbol(0xdeadbeef, 'O', 0x4, 'Woooo'),
                     sa.Symbol(0xdeadbee, 'O', 0x8, '__Hooo_ooo'),
                     sa.Symbol(0xdeadbee, 'O', 0x0, '__foo_doo_coo_end')]
   self.assertEqual(symbols, expect_symbols)
 def testAnalyzeFunction(self):
     analyzer = sa.ArmAnalyzer()
     symbol = sa.Symbol(0x10, 'F', 0x100, 'foo')
     instructions = [
         (0x10, 'push', '{r4, r5, r6, r7, lr}'),
         (0x12, 'subw', 'sp, sp, #16	; 0x10'),
         (0x16, 'movs', 'lr, r1'),
         (0x18, 'beq.n', '26 <foo+0x26>'),
         (0x1a, 'bl', '30 <foo+0x30>'),
         (0x1e, 'bl', 'deadbeef <bar>'),
         (0x22, 'blx', '0 <woo>'),
         (0x26, 'push', '{r1}'),
         (0x28, 'stmdb', 'sp!, {r4, r5, r6, r7, r8, r9, lr}'),
         (0x2c, 'stmdb', 'sp!, {r4}'),
         (0x30, 'stmdb', 'sp, {r4}'),
         (0x34, 'bx.n', '10 <foo>'),
         (0x36, 'bx.n', 'r3'),
         (0x38, 'ldr', 'pc, [r10]'),
     ]
     (size, callsites) = analyzer.AnalyzeFunction(symbol, instructions)
     self.assertEqual(size, 72)
     expect_callsites = [
         sa.Callsite(0x1e, 0xdeadbeef, False),
         sa.Callsite(0x22, 0x0, False),
         sa.Callsite(0x34, 0x10, True),
         sa.Callsite(0x36, None, True),
         sa.Callsite(0x38, None, True)
     ]
     self.assertEqual(callsites, expect_callsites)
 def setUp(self):
   symbols = [sa.Symbol(0x1000, 'F', 0x15C, 'hook_task'),
              sa.Symbol(0x2000, 'F', 0x51C, 'console_task'),
              sa.Symbol(0x3200, 'O', 0x124, '__just_data'),
              sa.Symbol(0x4000, 'F', 0x11C, 'touchpad_calc'),
              sa.Symbol(0x5000, 'F', 0x12C, 'touchpad_calc.constprop.42'),
              sa.Symbol(0x12000, 'F', 0x13C, 'trackpad_range'),
              sa.Symbol(0x13000, 'F', 0x200, 'inlined_mul'),
              sa.Symbol(0x13100, 'F', 0x200, 'inlined_mul'),
              sa.Symbol(0x13100, 'F', 0x200, 'inlined_mul_alias')]
   tasklist = [sa.Task('HOOKS', 'hook_task', 2048, 0x1000),
               sa.Task('CONSOLE', 'console_task', 460, 0x2000)]
   options = mock.MagicMock(elf_path='./ec.RW.elf',
                            export_taskinfo='fake',
                            section='RW',
                            objdump='objdump',
                            addr2line='addr2line',
                            annotation=None)
   self.analyzer = sa.StackAnalyzer(options, symbols, tasklist, {})
 def testSymbol(self):
     symbol_a = sa.Symbol(0x1234, 'F', 32, 'a')
     symbol_b = sa.Symbol(0x234, 'O', 42, 'b')
     self.assertEqual(symbol_a, symbol_a)
     self.assertNotEqual(symbol_a, symbol_b)
     self.assertNotEqual(symbol_a, None)
 def setUp(self):
     symbols = [
         sa.Symbol(0x1000, 'F', 0x15C, 'hook_task'),
         sa.Symbol(0x2000, 'F', 0x51C, 'console_task'),
         sa.Symbol(0x3200, 'O', 0x124, '__just_data'),
         sa.Symbol(0x4000, 'F', 0x11C, 'touchpad_calc'),
         sa.Symbol(0x5000, 'F', 0x12C, 'touchpad_calc.constprop.42'),
         sa.Symbol(0x12000, 'F', 0x13C, 'trackpad_range'),
         sa.Symbol(0x13000, 'F', 0x200, 'inlined_mul'),
         sa.Symbol(0x13100, 'F', 0x200, 'inlined_mul'),
         sa.Symbol(0x13100, 'F', 0x200, 'inlined_mul_alias'),
         sa.Symbol(0x20000, 'O', 0x0, '__array'),
         sa.Symbol(0x20010, 'O', 0x0, '__array_end'),
     ]
     tasklist = [
         sa.Task('HOOKS', 'hook_task', 2048, 0x1000),
         sa.Task('CONSOLE', 'console_task', 460, 0x2000)
     ]
     # Array at 0x20000 that contains pointers to hook_task and console_task,
     # with stride=8, offset=4
     rodata = (0x20000, [0xDEAD1000, 0x00001000, 0xDEAD2000, 0x00002000])
     options = mock.MagicMock(elf_path='./ec.RW.elf',
                              export_taskinfo='fake',
                              section='RW',
                              objdump='objdump',
                              addr2line='addr2line',
                              annotation=None)
     self.analyzer = sa.StackAnalyzer(options, symbols, rodata, tasklist,
                                      {})