Esempio n. 1
0
 def __init__(self, binary):
     self.__binary = binary
     self.__arch_mode = self.__binary.architecture_mode
     self.__arch = X86ArchitectureInformation(self.__arch_mode)
     self.__disassembler = X86Disassembler(self.__arch_mode)
     self.__translator = X86Translator(self.__arch_mode)
     self.__bb_builder = CFGRecoverer(
         RecursiveDescent(self.__disassembler, self.__binary.text_section,
                          self.__translator, self.__arch))
Esempio n. 2
0
    def test_sample_2(self):
        binary = BinaryFile(get_full_path("/data/bin/x86_sample_2"))
        strategy = RecursiveDescent(self._disassembler, binary.text_section,
                                    self._translator, self._arch_info)
        recoverer = CFGRecoverer(strategy)

        # Recover "main" function.
        bbs, call_targets = recoverer.build(0x0804846d, 0x080484a3)

        self.assertEqual(len(bbs), 4)

        cfg = ControlFlowGraph(bbs, name="main")

        self.assertEqual(cfg.start_address, 0x0804846d)
        self.assertEqual(cfg.end_address, 0x080484a3)
        self.assertEqual(len(cfg.basic_blocks), 4)

        bb_entry = cfg.find_basic_block(0x0804846d)
        self.assertEqual(len(bb_entry.branches), 2)
        self.assertEqual(bb_entry.taken_branch, 0x08048491)
        self.assertEqual(bb_entry.not_taken_branch, 0x0804848a)

        bb_taken = cfg.find_basic_block(0x08048491)
        self.assertEqual(len(bb_taken.branches), 1)
        self.assertEqual(bb_taken.taken_branch, None)
        self.assertEqual(bb_taken.not_taken_branch, None)
        self.assertEqual(bb_taken.direct_branch, 0x08048496)

        bb_not_taken = cfg.find_basic_block(0x0804848a)
        self.assertEqual(len(bb_not_taken.branches), 1)
        self.assertEqual(bb_not_taken.taken_branch, None)
        self.assertEqual(bb_not_taken.not_taken_branch, None)
        self.assertEqual(bb_not_taken.direct_branch, 0x08048496)

        # Recover "func_1" function.
        bbs, call_targets = recoverer.build(0x0804843b, 0x8048453)

        self.assertEqual(len(bbs), 1)

        cfg = ControlFlowGraph(bbs, name="main")

        self.assertEqual(cfg.start_address, 0x0804843b)
        self.assertEqual(cfg.end_address, 0x8048453)
        self.assertEqual(len(cfg.basic_blocks), 1)

        # Recover "func_2" function.
        bbs, call_targets = recoverer.build(0x08048454, 0x0804846c)

        self.assertEqual(len(bbs), 1)

        cfg = ControlFlowGraph(bbs, name="main")

        self.assertEqual(cfg.start_address, 0x08048454)
        self.assertEqual(cfg.end_address, 0x0804846c)
        self.assertEqual(len(cfg.basic_blocks), 1)
Esempio n. 3
0
    def test_sample_1(self):
        binary = BinaryFile(get_full_path("/data/bin/x86_sample_1"))
        strategy = RecursiveDescent(self._disassembler, binary.text_section,
                                    self._translator, self._arch_info)
        recoverer = CFGRecoverer(strategy)

        bbs, call_targets = recoverer.build(0x0804840b, 0x08048438)

        self.assertEqual(len(bbs), 1)

        cfg = ControlFlowGraph(bbs, name="main")

        self.assertEqual(cfg.start_address, 0x0804840b)
        self.assertEqual(cfg.end_address, 0x08048438)
        self.assertEqual(len(cfg.basic_blocks), 1)
Esempio n. 4
0
    def __init__(self, binary, symbols):
        self.__binary = binary
        self.__arch_mode = self.__binary.architecture_mode
        self.__arch = X86ArchitectureInformation(self.__arch_mode)
        self.__disassembler = X86Disassembler(self.__arch_mode)
        self.__translator = X86Translator(self.__arch_mode)
        self.__bb_builder = CFGRecoverer(
            RecursiveDescent(self.__disassembler, self.__binary.text_section,
                             self.__translator, self.__arch))

        self.__container = {}
        self.__symbols = symbols

        self.__symbols_by_addr = {}

        for name, start, end in symbols:
            self.__symbols_by_addr[start] = (name, end)