Skip to content

Commit

Permalink
compatible with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
DennyDai committed Jul 19, 2023
1 parent f8b969c commit afe17cb
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions headless_ida/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@
def HeadlessIdaServer(idat_path):
class _HeadlessIdaServer(rpyc.Service):
def exposed_init(self, binary):
with tempfile.NamedTemporaryFile() as binary_file:
binary_file.write(binary)
binary_file.flush()
binary_path = binary_file.name
binary_file = tempfile.NamedTemporaryFile(delete=False)
binary_file.write(binary)
binary_file.flush()
binary_file.close()
binary_path = binary_file.name

server_path = os.path.join(os.path.realpath(
os.path.dirname(__file__)), "ida_script.py")
port = 8000
with socket.socket() as s:
s.bind(('', 0))
port = s.getsockname()[1]
tempidb = tempfile.NamedTemporaryFile(suffix=".idb")
p = subprocess.Popen(
f'{idat_path} -o"{tempidb.name}" -A -S"{escape_path(server_path)} {port}" -P+ {binary_path}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
if p.poll() is not None:
raise Exception(
f"IDA failed to start: return code {p.poll()}\n"
f"=============== STDOUT ===============\n{p.stdout.read().decode()}"
f"=============== STDERR ===============\n{p.stderr.read().decode()}"
)
try:
self.conn = rpyc.connect("localhost", port)
except:
continue
break
server_path = os.path.join(os.path.realpath(
os.path.dirname(__file__)), "ida_script.py")
port = 8000
with socket.socket() as s:
s.bind(('', 0))
port = s.getsockname()[1]
tempidb = tempfile.NamedTemporaryFile(suffix=".idb")
p = subprocess.Popen(
f'{idat_path} -o"{tempidb.name}" -A -S"{escape_path(server_path)} {port}" -P+ {binary_path}', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
if p.poll() is not None:
raise Exception(
f"IDA failed to start: return code {p.poll()}\n"
f"=============== STDOUT ===============\n{p.stdout.read().decode()}"
f"=============== STDERR ===============\n{p.stderr.read().decode()}"
)
try:
self.conn = rpyc.connect("localhost", port)
except:
continue
break

def exposed_import_module(self, mod):
return self.conn.root.import_module(mod)
Expand Down

0 comments on commit afe17cb

Please sign in to comment.