def __init__(self, arch=ARCH_ARM_LINUX, memory=1024, debug_host=False, debug_target=False, qemu_bin=None, img_dir=".", img_fs="linux-rootfs.img", img_kernel="linux-kernel"):
        SockPuppet.Controller.__init__(self, debug=debug_host)
        self.debug_target = debug_target
        if qemu_bin is not None:
            self.QEMU_BIN = qemu_bin
        elif platform.system() in ["Windows", "Linux"]:
            self.QEMU_BIN = distutils.spawn.find_executable("qemu-system-arm")
        else:
            raise RuntimeError("Unsupported platform: %s" % platform.system())
        assert self.QEMU_BIN is not None and os.path.isfile(self.QEMU_BIN), "Missing QEMU executable at %r" % self.QEMU_BIN
        if arch == self.ARCH_ARM_LINUX:
            img_fs = os.path.join(img_dir, "linux-rootfs.img")
            img_kernel = os.path.join(img_dir, "linux-kernel")
            assert os.path.isfile(img_fs), "Missing %s" % img_fs
            assert os.path.isfile(img_kernel), "Missing %s" % img_kernel
            cmd = [self.QEMU_BIN, "-M", "vexpress-a9", "-snapshot", "-m", str(memory),
                   "-kernel", img_kernel, "-sd", img_fs, "-append", "root=b300 console=ttyAMA0",
                   "-net", "nic", "-net", "user,hostfwd=tcp::2222-:22", "-serial", "stdio",
                   "-display", "none"]
        else:
            raise RuntimeError("Unsupported Architecture")
        if debug_target:
            self.target_out = sys.stdout
        else:
            self.target_out = open(os.devnull, "w")
        try:
            self.qemu_proc = subprocess.Popen(cmd, shell=False, stdout=self.target_out,
                                              stderr=self.target_out)
            self.connect()
            if debug_target:
                self.debug_client()
            self.send_file(SockPuppet.__file__, "/root/SockPuppet.py")
            self.send_quit()
            self.disconnect()
            self.connect()
            if debug_target:
                self.debug_client()
            # Send required gdb wrapper
            alf_debug_dir = os.path.join(ALF_BASE, "alf", "debug")
            # Send required gdb wrapper
            self.send_file(os.path.join(alf_debug_dir, "_common.py"))
            self.send_file(os.path.join(alf_debug_dir, "_gdb.py"))
            self.send_file(os.path.join(alf_debug_dir, "cmds.gdb"))
            # Send CERT exploitable to target
            exploitable_dir = os.path.join(ALF_BASE, "lib", "exploitable")
            self.send_file(os.path.join(exploitable_dir, "exploitable.py"))
            exploitable_dir = os.path.join(exploitable_dir, "lib")
            self.send_file(os.path.join(exploitable_dir, "__init__.py"))
            self.send_file(os.path.join(exploitable_dir, "analyzers.py"))
            self.send_file(os.path.join(exploitable_dir, "classifier.py"))
            self.send_file(os.path.join(exploitable_dir, "elf.py"))
            self.send_file(os.path.join(exploitable_dir, "gdb_wrapper.py"))
            self.send_file(os.path.join(exploitable_dir, "rules.py"))
            self.send_file(os.path.join(exploitable_dir, "tools.py"))
            self.send_file(os.path.join(exploitable_dir, "versions.py"))
            self.run_code(_remote_init, self.REMOTE_WORKING_DIR)
        except __HOLE__:
            self._kill_qemu()
            raise
        finally:
            if not debug_target:
                self.target_out.close()
dataset/ETHPy150Open blackberry/ALF/alf/debug/_qemu.py/QEmuTarget.__init__