Esempio n. 1
0
 def __init__(self, filename, *cmdline_args, **flags):
     config = generate_config(filename, *cmdline_args, **flags)
     self._setup(config)
Esempio n. 2
0
    def __init__(self, config=None, api=None):
        self.api = api
        self.api.internal_engine = self
        if config is None:
            config = _generate_without_binary()
        if isinstance(config, str):
            config = generate_config(config)
        self.config = config

        # OS plugins place OS-specific, system-wide, functionality
        # in engine.zos

        class ZOS(object):
            def __init__(self):
                pass

        self.zos = ZOS()

        binary = config.filename

        # Set provided arguments
        self.original_binary = binary
        self.cmdline_args = ([] if config.cmdline_args is None else
                             config.cmdline_args)

        self.random_file_name = getattr(config, "random_file_name", False)

        self.log_level = getattr(logging, config.log.upper(), None)
        if not isinstance(self.log_level, int):
            raise ValueError("Invalid log level: %s" % config.log)

        # To get different logs based on the level, read this:
        # https://stackoverflow.com/questions/14844970
        #   /modifying-logging-message-format-based-on-message-
        #   logging-level-in-python3
        self._init_logging(self.log_level)

        # If verbose is true, print lots of info, including every
        # instruction
        self.original_file_name = ""
        self.main_module_name = ""
        self.main_module = None

        self.date = "2019-02-02"

        self.timer = util.Timer()

        self.hook_manager = HookManager(self, self.api)
        self.breakpoints = BreakpointManager(self.hook_manager)
        self.interrupt_handler = InterruptHooks(self.hook_manager, self)
        self.exception_handler = ExceptionHooks(self)
        self.files = FileSystem(self, self.hook_manager)
        self.processes = Processes(
            self.hook_manager,
            self.interrupt_handler,
            self.files,
            self.original_binary,
            self.STACK_SIZE,
            disableNX=self.config.disableNX,
        )

        self.os_plugins = OSPlugins(self)

        if binary is not None and binary != "":
            self.load_executable(binary, entrypoint_override=config.startat)
        else:
            self._initialize_zelos()  # For testing purposes.
            # If no binary is passed, default to UNIX-style paths.
            self.files.setup("/")

        head, tail = ntpath.split(config.filename)
        original_filename = tail or ntpath.basename(head)
        self.original_file_name = original_filename
        self.date = config.date

        if config.dns > 0:
            self.flags_dns = True

        if config.writetrace != "":
            target_addr = int(config.writetrace, 16)
            self.set_writetrace(target_addr)
        if config.memlimit > 0:
            self.set_mem_limit(config.memlimit)
        for m in config.mount:
            try:
                arch, dest, src = m.split(",")
                # TODO: Use arch to determine when to mount
                if os.path.isdir(src):
                    self.files.mount_folder(src, emulated_path=dest)
                else:
                    self.files.add_file(src, emulated_path=dest)
            except ValueError:
                self.logger.error(
                    f"Incorrectly formatted input to '--mount': {m}")
                continue
        if config.strace is not None:
            self.zos.syscall_manager.set_strace_file(config.strace)