def main(): # Don't support the legacy api. sys.modules["__main__"].IDAPYTHON_COMPAT_695_API = False import idc kordesii.setup_logging() try: Pyro4.config.SERVERTYPE = "multiplex" Pyro4.config.FLAME_ENABLED = "True" Pyro4.config.SERIALIZERS_ACCEPTED = {"dill"} logger.debug("Starting daemon...") daemon = Pyro4.Daemon(host="localhost") warnings.simplefilter("ignore") uri = _register(daemon) logger.info("Listening on {}".format(uri)) # Send port back to the client. _send_result(uri.port) # Start listener idc.auto_wait() daemon.requestLoop(loopCondition=lambda: not daemon_stop.is_set()) if _close_ida: idc.qexit(0) except Exception as e: # Send exception back to the client, so they can raise it outside of IDA. _send_result(e)
def main(debug, verbose, decoder_dir, decoder_source): # Setup logging kordesii.setup_logging() if debug: logging.root.setLevel(logging.DEBUG) elif verbose: logging.root.setLevel(logging.INFO) # else let log_config.yaml set log level. # Register parsers kordesii.register_entry_points() if decoder_dir: kordesii.register_decoder_directory(decoder_dir) if decoder_source: kordesii.set_default_source(decoder_source)
def main(): """ Run tool. """ print('') # Get command line arguments argparser = get_arg_parser() args = argparser.parse_args() # Setup logging kordesii.setup_logging() if args.debug: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel( logging.ERROR ) # By default, ignore all warning, info, and debug messages. # Register decoders kordesii.register_entry_points() if args.decoderdir: kordesii.register_decoder_directory(args.decoderdir) if args.decodersource: kordesii.set_default_source(args.decodersource) # Configure reporter based on args reporter = Reporter() # Configure test object if args.all_tests or not args.decoder_name: decoders = [None] else: decoders = [args.decoder_name] tester = Tester(reporter, results_dir=args.test_case_dir, decoder_names=decoders, nprocs=args.nprocs, field_names=filter(None, args.field_names.split(",")), ignore_field_names=filter( None, args.exclude_field_names.split(","))) # Gather all our input files input_files = [] if args.input_file: input_files = read_input_list(args.input_file) # Add/Delete if args.delete or args.update: if not args.decoder_name: sys.exit( 'Decoder must be provided when adding or deleting a file from a test case.' ) for input_file in input_files: if args.delete: tester.remove_test(input_file) else: tester.add_test(input_file) # Update elif args.update: if not args.decoder_name: sys.exit('Decoder must be provided when updating a test case.') tester.update_tests() # Default is to run test cases else: _run_tests(tester, silent=args.silent, show_passed=not args.only_failed_tests)
def start(self): """ Starts IDA proxy server and sets up import hooks. :raises RuntimeError: If we fail to start or connect to IDA. """ global _instance_running global _open_proxies global _port if _instance_running: raise ValueError("IDA instance already started!") if not os.path.exists(self.input_path): raise ValueError("Unable to find: {}".format(self.input_path)) if self._open_in_ida(): raise ValueError( "Another process has {} open in IDA. " "Please close the other process and/or cleanup the internal runtime files.".format(self.input_path) ) # Start log listener (if not already started) if not logutil.listen_port: kordesii.setup_logging() assert logutil.listen_port # Start up IDA server. ida_exe = kordesii.find_ida(kordesii.is_64_bit(self.input_path)) script_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "ida_server.py") port_path = self._make_port_file() command = [ ida_exe, "-A", '-S""{}" {} {} {}"'.format(script_path, logging.root.getEffectiveLevel(), logutil.listen_port, port_path), # '-L"{}.log"'.format(self.input_path), # Uncomment if debugging ida_server.py '"{}"'.format(self.input_path), ] command = " ".join(command) logger.debug("Running command: {}".format(command)) env = dict(os.environ) env["PYTHONPATH"] = "" process = subprocess.Popen(command, env=env, shell=sys.platform != "win32") thread = threading.Thread(target=communicate, args=(process,)) thread.daemon = True thread.start() try: # Wait for port to arrive then retrieve it. logger.debug("Retrieving port...") _port = self._get_port(port_path) if os.path.exists(port_path): os.unlink(port_path) logger.debug("IDA Server setup on port {}".format(_port)) # Pull main proxy. main_proxy = Pyro4.Proxy("PYRO:main@localhost:{}".format(_port)) assert main_proxy.ping() # Safety check except Exception: process.kill() thread.join() self._cleanup_files() raise _open_proxies["main"] = main_proxy self._process = process self._thread = thread self._orig_path = list(sys.path) self._orig_modules = dict(sys.modules) self._orig_meta_path = list(sys.meta_path) # Hook import paths to use proxy for internal ida module. sys.path.append(os.path.join(os.path.dirname(ida_exe), "python")) sys.modules["__main__"].IDAPYTHON_COMPAT_695_API = False sys.meta_path.insert(0, IDAFinder()) _instance_running = True self._started = True
def main(): """ Takes args from the command line, runs IDA, and returns with IDA's returncode on success or a message on failure. """ opt_parse = make_opt_parser() options, args = opt_parse.parse_args() # Setup logging kordesii.setup_logging() if options.hidedebug: logging.root.setLevel(logging.ERROR) elif options.debug: logging.root.setLevel(logging.DEBUG) else: logging.root.setLevel(logging.INFO) # Register decoders kordesii.register_entry_points() if options.decoderdir: kordesii.register_decoder_directory(options.decoderdir) if options.decodersource: kordesii.set_default_source(options.decodersource) # List out decoder names and exit if options.list: _print_decoders(json_output=options.jsonoutput) sys.exit(0) # Currently only allow one file to be passed in if not args or len(args) != 1: opt_parse.print_help() return # If we can not create reporter object there is very little we can do. Just die immediately. try: reporter = Reporter( tempdir=options.tempdir, disabletempcleanup=options.disabletempcleanup, disabledebug=options.hidedebug, ) except Exception as e: error_message = "Error loading DC3-Kordesii reporter object, please check installation: %s" % ( traceback.format_exc()) if options.jsonoutput: print('{"errors": ["%s"]}' % error_message) else: print(error_message) sys.exit(1) # Run decoder if options.decoder: # Grab file from arguments input_file = os.path.abspath(args[0]) # Run the decoder reporter.run_decoder( options.decoder, input_file, timeout=options.timeout, autonomous=options.autonomous, log=options.enableidalog, cleanup_txt_files=not options.disabletxtcleanup, cleanup_output_files=options.enableoutputfilecleanup, cleanup_idb_files=options.enableidbcleanup) # Output results if options.jsonoutput: output = reporter.metadata if reporter.errors: output["errors"] = reporter.errors if reporter.ida_log: output["ida_log"] = reporter.ida_log print(json.dumps(output, indent=4)) else: reporter.print_report()