Example #1
0
 def assert_not_contain_this_type(self, code, not_expect_type):
     address = 0x40000
     gadget_classifier = classifier.GadgetClassifier(
         archinfo.ArchX86(), code, address, log_level=logging.DEBUG)
     gadgets = gadget_classifier.create_gadgets_from_instructions(address)
     types = []
     for g in gadgets:
         if g.address != address:  #The gadget should be starting at the *address*
             continue
         types.append(type(g))
     self.assertFalse(not_expect_type in types)
    def run_test(self, arch, tests):
        gadget_classifier = classifier.GadgetClassifier(
            arch, log_level=logging.DEBUG)
        for (expected_types, code) in tests:
            gadgets = gadget_classifier.create_gadgets_from_instructions(
                code, 0x40000)

            # For each returned gadget, count the number of each gadget types
            types = {}
            for g in gadgets:
                if type(g) not in types: types[type(g)] = 0
                types[type(g)] += 1
            self.assertEqual(types, expected_types)
Example #3
0
    def run_test(self, arch, tests):
        for (expected_types, code) in tests:
            address = 0x40000
            gadget_classifier = classifier.GadgetClassifier(
                arch, code, address, log_level=logging.DEBUG)
            classic_gadgets = []
            if len(code) >= arch.instruction_alignment:
                classic_gadgets += gadget_classifier.create_gadgets_from_instructions(
                    address)
            jcc_gadgets = gadget_classifier.harvest_jcc_gadgets(
                classic_gadgets)

            # For each returned gadget, count the number of each gadget types
            types = {}
            for g in classic_gadgets + jcc_gadgets:
                if g.address != address:  #Matching the starting address of current gadget againt #address#
                    continue
                n = types.get(type(g), 0)
                types[type(g)] = n + 1

            #self.assertEqual(types, expected_types)
            self.assertEqual(expected_types, types)
Example #4
0
    def run_jcc_test(self, arch, tests):
        for (expected_types, code) in tests:
            address = 0x40000
            gadget_classifier = classifier.GadgetClassifier(
                arch, code, address, log_level=logging.DEBUG)
            classic_gadgets = []
            for i in range(0, len(code), arch.instruction_alignment):  #{
                address = 0x40000 + i
                classic_gadgets += gadget_classifier.create_gadgets_from_instructions(
                    address)
            #}end for

            jcc_gadgets = gadget_classifier.harvest_jcc_gadgets(
                classic_gadgets)

            # For each returned gadget, count the number of each gadget types
            types = {}
            for g in classic_gadgets + jcc_gadgets:
                n = types.get(type(g), 0)
                types[type(g)] = n + 1

            #self.assertEqual(types, expected_types)
            self.assertEqual(expected_types, types)