2014-07-23 04:37:06 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import os
|
|
|
|
import argparse
|
|
|
|
import socket
|
|
|
|
import threading
|
|
|
|
import time
|
|
|
|
|
|
|
|
import qira_socat
|
|
|
|
import qira_program
|
|
|
|
import qira_webserver
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = argparse.ArgumentParser(description = 'Analyze binary.')
|
|
|
|
parser.add_argument('-s', "--server", help="bind on port 4000. like socat", action="store_true")
|
2014-07-25 07:38:01 +04:00
|
|
|
parser.add_argument('-t', "--tracelibraries", help="trace into all libraries", action="store_true")
|
2014-07-23 04:37:06 +04:00
|
|
|
parser.add_argument('binary', help="path to the binary")
|
|
|
|
parser.add_argument('args', nargs='*', help="arguments to the binary")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# creates the file symlink, program is constant through server run
|
|
|
|
program = qira_program.Program(args.binary, args.args)
|
|
|
|
|
2014-07-25 07:38:01 +04:00
|
|
|
if args.tracelibraries:
|
|
|
|
program.defaultargs.append("-tracelibraries")
|
|
|
|
|
2014-07-23 04:37:06 +04:00
|
|
|
is_qira_running = 1
|
|
|
|
try:
|
2014-07-23 21:09:08 +04:00
|
|
|
socket.create_connection(('127.0.0.1', qira_webserver.QIRA_PORT))
|
2014-07-23 04:37:06 +04:00
|
|
|
if args.server:
|
|
|
|
raise Exception("can't run as server if QIRA is already running")
|
|
|
|
except:
|
|
|
|
is_qira_running = 0
|
|
|
|
print "no qira server found, starting it"
|
|
|
|
program.clear()
|
|
|
|
|
|
|
|
# start the binary runner
|
|
|
|
if args.server:
|
2014-07-25 08:26:15 +04:00
|
|
|
qira_socat.start_bindserver(program, 4000, -1, 1, True)
|
2014-07-23 04:37:06 +04:00
|
|
|
else:
|
|
|
|
print "**** running "+program.program
|
|
|
|
if is_qira_running or os.fork() == 0: # cute?
|
2014-07-25 07:38:01 +04:00
|
|
|
program.execqira()
|
2014-07-23 04:37:06 +04:00
|
|
|
|
|
|
|
if not is_qira_running:
|
|
|
|
# start the http server
|
2014-07-23 07:12:55 +04:00
|
|
|
qira_webserver.run_server(program)
|
2014-07-23 04:37:06 +04:00
|
|
|
|