Exemplo n.º 1
0
    def run_test(self,
                 filename,
                 patches,
                 set_oep=None,
                 inputvalue=None,
                 expected_output=None,
                 expected_returnCode=None,
                 try_without_cfg=True):
        filepath = os.path.join(self.bin_location, filename)
        pipe = subprocess.PIPE

        with patcherex.utils.tempdir() as td:
            tmp_file = os.path.join(td, "patched")
            backend = DetourBackend(filepath, try_without_cfg=try_without_cfg)
            backend.apply_patches(patches)
            if set_oep:
                backend.set_oep(backend.name_map[set_oep])
            backend.save(tmp_file)
            p = subprocess.Popen([
                self.qemu_location, "-L", "/usr/mips64-linux-gnuabi64",
                tmp_file
            ],
                                 stdin=pipe,
                                 stdout=pipe,
                                 stderr=pipe)
            res = p.communicate(inputvalue)
            if expected_output:
                self.assertEqual(res[0], expected_output)
            if expected_returnCode:
                self.assertEqual(p.returncode, expected_returnCode)
            return backend
Exemplo n.º 2
0
    def run_test(self,
                 file,
                 patches,
                 set_oep=None,
                 inputs=None,
                 expected_output=None,
                 expected_returnCode=None):
        filepath = os.path.join(self.bin_location, file)
        pipe = subprocess.PIPE

        with patcherex.utils.tempdir() as td:
            tmp_file = os.path.join(td, "patched")
            backend = DetourBackend(filepath)
            backend.apply_patches(patches)
            if set_oep:
                backend.set_oep(backend.name_map[set_oep])
            backend.save(tmp_file)
            p = subprocess.Popen([tmp_file],
                                 stdin=pipe,
                                 stdout=pipe,
                                 stderr=pipe)
            res = p.communicate(inputs)
            if expected_output:
                self.assertEqual(res[0], expected_output)
            if expected_returnCode:
                self.assertEqual(p.returncode, expected_returnCode)
            return backend