def main(): logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S") ctx = Ctx() # New directory try_rmtree(ctx.outdir) indir, dll = os.path.split(ctx.srcdir) try: shutil.copytree(indir, ctx.outdir) except FileExistsError: print("Warning make_testdata: file", ctx.outdir, "exists", "Cannot copy from", ctx.srcdir) if ctx.no_pdb: pdb = re.sub("\.dll", ".pdb", dll) os.remove(os.path.join(ctx.outdir, pdb)) sys.path.append(ctx.yadir) import exec_ida cmd = exec_ida.Exec(get_binary_name(ctx.idaq), os.path.join(ctx.outdir, dll), '-A') cmd.set_idle(True) cmd.with_script(os.path.join(ctx.yadir, 'export_all.py'), ctx.bindir) logging.debug(' '.join(cmd.get_args())) check_fail(cmd.run()) yadb = os.path.join(ctx.outdir, "database", "database.yadb") if not os.path.isfile(yadb): check_fail("missing %s" % yadb)
def run_script(self, script, target): import exec_ida args = ["-Oyaco:disable_plugin", "-A"] cmd = exec_ida.Exec(os.path.join(self.ctx.ida_dir, "ida64"), os.path.join(self.path, target), *args) cmd.set_idle(True) fd, fname = tempfile.mkstemp(dir=self.path, prefix="exec_", suffix=".py") os.write(fd, ida_start + script + ida_end) os.close(fd) cmd.with_script(fname, self.ctx.bin_dir, self.ctx.yaco_dir) err = cmd.run() self.ctx.assertEqual(err, None, "%s" % err)
def run_test_suite(work_dir, bin_dir, idaq, target, module, prefix, script): print '* running', prefix, 'tests on', target import exec_ida args = ["-Oyaco:disable_plugin", "-A"] cmd = exec_ida.Exec(os.path.join(ida_dir, idaq), os.path.join(work_dir, target), *args) cmd.set_idle(True) cmd.with_script(script, bin_dir, module, prefix) print str(cmd) err = cmd.run() if not err: return 0 print(err) return -1
def run_ida(ctx, ida_database, script, interactive=False, *args): ida = ctx.ida if ida_database.endswith(".i64"): ida = ctx.ida64 ida_args = ["-Oyaco:disable_plugin"] if not interactive: ida_args += ['-A'] sys.path.append(os.path.join(ctx.yatools_dir, "YaCo")) import exec_ida cmd = exec_ida.Exec(ida, ida_database, *ida_args) cmd.set_idle(True) cmd.with_script(script, *args) logging.info("running %s" % str(cmd)) err = cmd.run() if err: fail(ctx, "unable to run ida\n%s" % err)
def run_script(self, script, target): # Load ida.exe import exec_ida args = ["-Oyaco:disable_plugin", "-A"] cmd = exec_ida.Exec(os.path.join(self.ctx.ida_dir, "ida64"), os.path.join(self.path, target), *args) cmd.set_idle(True) # Write temporary test script fd, fname = tempfile.mkstemp(dir=self.path, prefix="exec_", suffix=".py") b_generated = (ida_start + script + ida_end).encode() os.write(fd, b_generated) os.close(fd) # Run generated script cmd.with_script(fname, self.ctx.bin_dir, self.ctx.yaco_dir) err = cmd.run() self.ctx.assertEqual(err, None, "%s" % err)
def main(): logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S") ctx = Ctx() indir, dll = os.path.split(ctx.src) logging.info( '%s (%s)' % (os.path.join('testdata', os.path.basename(indir), dll), ctx.idaq)) dst = os.path.join(ctx.outdir, os.path.basename(indir)) try_rmtree(dst) shutil.copytree(indir, dst) sys.path.append(ctx.yadir) import exec_ida cmd = exec_ida.Exec(get_binary_name(ctx.idaq), os.path.join(dst, dll), '-A') cmd.set_idle(True) cmd.with_script(os.path.join(ctx.yadir, 'export_all.py'), ctx.bindir) logging.debug(' '.join(cmd.get_args())) check_fail(cmd.run()) yadb = os.path.join(dst, "database", "database.yadb") if not os.path.isfile(yadb): check_fail("missing %s" % yadb)
def launch_worker(self, create_idb=True, recycle_idb_from_id=None): worker_id = self.next_worker_id self.next_worker_id += 1 idb_filename_for_export = get_local_idb_name( idc.GetIdbPath(), "_cache_export_%08i" % worker_id, self.export_dir) if create_idb: self.create_idb_for_worker(worker_id, recycle_idb_from_id) logger.debug("Running job %i." % worker_id) idaq = sys.executable if sys.platform == "linux2": idaq = "idaq" if idc.GetIdbPath().endswith(idaapi.IDB_EXT64): idaq = "idaq64" idaq_path = os.path.abspath( os.path.join(os.path.dirname(inspect.getsourcefile(idaapi)), '..')) idaq = os.path.join(idaq_path, idaq) ida_args = [] if self.disable_plugin: ida_args += ["-Oyaco:disable_plugin"] if not debug: ida_args += ["-A"] cmd = exec_ida.Exec(idaq, os.path.abspath(idb_filename_for_export), *ida_args) cmd.set_idle(True) script = os.path.abspath(os.path.join(__file__, "..", "export_all.py")) cmd.with_script(script, "--slave", self.bin_dir) logger.info(str(cmd)) cmd.start() process_conn = self.listener.accept() self.connection_fds[worker_id] = process_conn.fileno() self.connections[process_conn.fileno()] = (worker_id, process_conn, cmd)