Exemplo n.º 1
0
 def testSuccessUnwind(self):
     self.assertEqual(
         [
             FunctionUnwind(address=0x100,
                            size=1024,
                            address_unwinds=(
                                AddressUnwind(
                                    address_offset=0x0,
                                    unwind_type=UnwindType.RETURN_TO_LR,
                                    sp_offset=0,
                                    registers=(),
                                ),
                                AddressUnwind(
                                    address_offset=0x200,
                                    unwind_type=UnwindType.RETURN_TO_LR,
                                    sp_offset=0,
                                    registers=(),
                                ),
                            ))
         ],
         list(
             GenerateUnwinds([
                 FunctionCfi(size=1024,
                             address_cfi=(
                                 AddressCfi(address=0x100,
                                            unwind_instructions='RETURN'),
                                 AddressCfi(address=0x300,
                                            unwind_instructions='RETURN'),
                             ))
             ],
                             parsers=[MockReturnParser()])))
Exemplo n.º 2
0
 def testInvalidInitialUnwindInstructionAsserts(self):
     self.assertRaises(
         AssertionError, lambda: list(
             GenerateUnwinds([
                 FunctionCfi(size=1024,
                             address_cfi=(
                                 AddressCfi(address=0x100,
                                            unwind_instructions='UNKNOWN'),
                                 AddressCfi(address=0x200,
                                            unwind_instructions='RETURN'),
                             ))
             ],
                             parsers=[MockReturnParser()])))
Exemplo n.º 3
0
 def testEpilogueUnwind(self):
     self.assertEqual(
         (None, True, -100),
         ParseAddressCfi(AddressCfi(address=0x800,
                                    unwind_instructions='EPILOGUE_UNWIND'),
                         function_start_address=0x500,
                         parsers=(MockEpilogueUnwindParser(), ),
                         prev_cfa_sp_offset=100))
Exemplo n.º 4
0
 def testUnhandledAddress(self):
     self.assertEqual(
         (None, False, 100),
         ParseAddressCfi(AddressCfi(address=0x800,
                                    unwind_instructions='UNKNOWN'),
                         function_start_address=0x500,
                         parsers=(MockReturnParser(), ),
                         prev_cfa_sp_offset=100))
Exemplo n.º 5
0
    def testReadFunctionCfiSingleFunction(self):
        input_lines = [
            'STACK CFI INIT 15b6490 4 .cfa: sp 0 + .ra: lr',
            'STACK CFI 2 .cfa: sp 24 + .ra: .cfa - 4 + ^ r4: .cfa - 16 + ^ '
            'r5: .cfa - 12 + ^ r7: .cfa - 8 + ^',
        ]

        f = io.StringIO(''.join(line + '\n' for line in input_lines))

        self.assertEqual([
            FunctionCfi(4, (
                AddressCfi(0x15b6490, '.cfa: sp 0 + .ra: lr'),
                AddressCfi(
                    0x2, '.cfa: sp 24 + .ra: .cfa - 4 + ^ r4: .cfa - 16 + ^ '
                    'r5: .cfa - 12 + ^ r7: .cfa - 8 + ^'),
            ))
        ], list(ReadFunctionCfi(f)))
Exemplo n.º 6
0
    def testParsePrecedence(self):
        address_unwind = AddressUnwind(
            address_offset=0x300,
            unwind_type=UnwindType.RETURN_TO_LR,
            sp_offset=0,
            registers=(),
        )

        self.assertEqual(
            (address_unwind, False, 0),
            ParseAddressCfi(AddressCfi(address=0x800,
                                       unwind_instructions='RETURN'),
                            function_start_address=0x500,
                            parsers=(MockReturnParser(), MockWildcardParser()),
                            prev_cfa_sp_offset=0))