mirror of https://github.com/geohot/qira
superficial stuff, porting to python3
This commit is contained in:
parent
7cd21feb98
commit
119245a0e2
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python2.7
|
||||
from __future__ import print_function
|
||||
import os
|
||||
import sys
|
||||
basedir = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -51,7 +52,7 @@ if __name__ == '__main__':
|
|||
|
||||
# handle arguments
|
||||
if sys.platform == "darwin":
|
||||
print "*** running on darwin, defaulting to --pin"
|
||||
print("*** running on darwin, defaulting to --pin")
|
||||
qira_config.USE_PIN = True
|
||||
else:
|
||||
qira_config.USE_PIN = args.pin
|
||||
|
@ -66,11 +67,11 @@ if __name__ == '__main__':
|
|||
qira_config.TRACE_LIBRARIES = True
|
||||
|
||||
if args.static:
|
||||
print "*** using static"
|
||||
print("*** using static")
|
||||
qira_config.WITH_STATIC = True
|
||||
qira_config.STATIC_ENGINE = args.engine
|
||||
if args.flush_cache:
|
||||
print "*** flushing caches"
|
||||
print("*** flushing caches")
|
||||
os.system("rm -rfv /tmp/qira*")
|
||||
|
||||
# qemu args from command line
|
||||
|
@ -89,14 +90,14 @@ if __name__ == '__main__':
|
|||
raise Exception("can't run as server if QIRA is already running")
|
||||
except:
|
||||
is_qira_running = 0
|
||||
print "no qira server found, starting it"
|
||||
print("no qira server found, starting it")
|
||||
program.clear()
|
||||
|
||||
# start the binary runner
|
||||
if args.server:
|
||||
qira_socat.start_bindserver(program, qira_config.SOCAT_PORT, -1, 1, True)
|
||||
else:
|
||||
print "**** running "+program.program
|
||||
print("**** running",program.program)
|
||||
program.execqira(shouldfork=not is_qira_running)
|
||||
|
||||
if not is_qira_running:
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python2.7
|
||||
from __future__ import print_function
|
||||
import qira_config
|
||||
import qira_program
|
||||
import arch
|
||||
|
@ -6,6 +7,14 @@ import time
|
|||
import math
|
||||
import sys
|
||||
import struct
|
||||
|
||||
from PIL import Image
|
||||
import base64
|
||||
try:
|
||||
import StringIO
|
||||
except ImportError:
|
||||
from io import BytesIO as StringIO
|
||||
|
||||
sys.path.append(qira_config.BASEDIR+"/static2")
|
||||
import static2
|
||||
|
||||
|
@ -17,7 +26,7 @@ def ghex(a):
|
|||
def draw_multigraph(blocks):
|
||||
import pydot
|
||||
|
||||
print "generating traces"
|
||||
print("generating traces")
|
||||
|
||||
arr = []
|
||||
trace = []
|
||||
|
@ -36,7 +45,7 @@ def draw_multigraph(blocks):
|
|||
|
||||
graph = pydot.Dot(graph_type='digraph')
|
||||
|
||||
print "adding nodes"
|
||||
print("adding nodes")
|
||||
nodes = []
|
||||
for a in arr:
|
||||
n = pydot.Node(a, shape="box")
|
||||
|
@ -46,8 +55,8 @@ def draw_multigraph(blocks):
|
|||
edges = []
|
||||
cnts = []
|
||||
|
||||
print "trace size",len(trace)
|
||||
print "realblock count",len(arr)
|
||||
print("trace size",len(trace))
|
||||
print("realblock count",len(arr))
|
||||
|
||||
# coalesce loops
|
||||
"""
|
||||
|
@ -75,12 +84,12 @@ def draw_multigraph(blocks):
|
|||
graph.add_edge(e)
|
||||
"""
|
||||
|
||||
print "adding edges"
|
||||
print("adding edges")
|
||||
for i in range(0, len(trace)-1):
|
||||
e = pydot.Edge(nodes[trace[i]], nodes[trace[i+1]], label=str(cls[i+1]), headport="n", tailport="s")
|
||||
graph.add_edge(e)
|
||||
|
||||
print "drawing png @ /tmp/graph.png"
|
||||
print("drawing png @ /tmp/graph.png")
|
||||
graph.write_png('/tmp/graph.png')
|
||||
|
||||
|
||||
|
@ -235,7 +244,7 @@ def do_loop_analysis(blocks):
|
|||
# remove the loop from the blocks
|
||||
bb = bb[0:i] + bb[i:i+j] + bb[i+j*loopcnt:]
|
||||
ab = ab[0:i] + ab[i:i+j] + ab[i+j*loopcnt:]
|
||||
print loop
|
||||
print(loop)
|
||||
loops.append(loop)
|
||||
did_update = True
|
||||
break
|
||||
|
@ -465,9 +474,6 @@ def get_vtimeline_picture(trace, minclnum, maxclnum):
|
|||
r = maxclnum-minclnum
|
||||
sampling = int(math.ceil(r/50000.0))
|
||||
|
||||
from PIL import Image # sudo pip install pillow
|
||||
import base64
|
||||
import StringIO
|
||||
im_y = int(maxclnum/sampling)
|
||||
im = Image.new( 'RGB', (1, im_y), "black")
|
||||
px = im.load()
|
||||
|
@ -560,7 +566,7 @@ if __name__ == "__main__":
|
|||
trace = program.add_trace("/tmp/qira_logs/0", 0)
|
||||
while not trace.db.did_update():
|
||||
time.sleep(0.1)
|
||||
print "loaded"
|
||||
print("loaded")
|
||||
program.qira_asm_file = open("/tmp/qira_asm", "r")
|
||||
qira_program.Program.read_asm_file(program)
|
||||
|
||||
|
@ -569,7 +575,7 @@ if __name__ == "__main__":
|
|||
flow = get_instruction_flow(trace, program, trace.db.get_minclnum(), trace.db.get_maxclnum())
|
||||
blocks = get_blocks(flow, True)
|
||||
|
||||
print slice(trace, 124)
|
||||
print(slice(trace, 124))
|
||||
|
||||
#print analyze(t, program)
|
||||
#print blocks
|
||||
|
|
|
@ -61,5 +61,5 @@ if __name__ == "__main__":
|
|||
import sys
|
||||
# standalone this can dump a log
|
||||
for (address, data, clnum, flags) in read_log(open(sys.argv[1])):
|
||||
print "%4d: %X -> %X %X" % (clnum, address, data, flags)
|
||||
print("%4d: %X -> %X %X" % (clnum, address, data, flags))
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
from qira_base import *
|
||||
import qira_config
|
||||
import qira_analysis
|
||||
|
@ -50,7 +51,7 @@ class Program:
|
|||
self.program = which(prog)
|
||||
self.args = args
|
||||
self.proghash = sha1(open(self.program, "rb").read()).hexdigest()
|
||||
print "*** program is",self.program,"with hash",self.proghash
|
||||
print("*** program is",self.program,"with hash",self.proghash)
|
||||
|
||||
# this is always initted, as it's the tag repo
|
||||
self.static = static2.Static(self.program)
|
||||
|
@ -90,21 +91,21 @@ class Program:
|
|||
# pmaps is global, but updated by the traces
|
||||
progdat = open(self.program, "rb").read(0x800)
|
||||
|
||||
CPU_TYPE_ARM = "\x0C"
|
||||
CPU_TYPE_ARM64 = "\x01\x00\x00\x0C"
|
||||
CPU_TYPE_ARM = b"\x0C"
|
||||
CPU_TYPE_ARM64 = b"\x01\x00\x00\x0C"
|
||||
|
||||
CPU_SUBTYPE_ARM_ALL = "\x00"
|
||||
CPU_SUBTYPE_ARM_V4T = "\x05"
|
||||
CPU_SUBTYPE_ARM_V6 = "\x06"
|
||||
CPU_SUBTYPE_ARM_V5TEJ = "\x07"
|
||||
CPU_SUBTYPE_ARM_XSCALE = "\x08"
|
||||
CPU_SUBTYPE_ARM_V7 = "\x09"
|
||||
CPU_SUBTYPE_ARM_V7F = "\x0A"
|
||||
CPU_SUBTYPE_ARM_V7S = "\x0B"
|
||||
CPU_SUBTYPE_ARM_V7K = "\x0C"
|
||||
CPU_SUBTYPE_ARM_V6M = "\x0E"
|
||||
CPU_SUBTYPE_ARM_V7M = "\x0F"
|
||||
CPU_SUBTYPE_ARM_V7EM = "\x10"
|
||||
CPU_SUBTYPE_ARM_ALL = b"\x00"
|
||||
CPU_SUBTYPE_ARM_V4T = b"\x05"
|
||||
CPU_SUBTYPE_ARM_V6 = b"\x06"
|
||||
CPU_SUBTYPE_ARM_V5TEJ = b"\x07"
|
||||
CPU_SUBTYPE_ARM_XSCALE = b"\x08"
|
||||
CPU_SUBTYPE_ARM_V7 = b"\x09"
|
||||
CPU_SUBTYPE_ARM_V7F = b"\x0A"
|
||||
CPU_SUBTYPE_ARM_V7S = b"\x0B"
|
||||
CPU_SUBTYPE_ARM_V7K = b"\x0C"
|
||||
CPU_SUBTYPE_ARM_V6M = b"\x0E"
|
||||
CPU_SUBTYPE_ARM_V7M = b"\x0F"
|
||||
CPU_SUBTYPE_ARM_V7EM = b"\x10"
|
||||
|
||||
CPU_SUBTYPE_ARM = [
|
||||
CPU_SUBTYPE_ARM_V4T,
|
||||
|
@ -124,17 +125,17 @@ class Program:
|
|||
CPU_SUBTYPE_ARM_V7S
|
||||
]
|
||||
|
||||
MACHO_MAGIC = "\xFE\xED\xFA\xCE"
|
||||
MACHO_CIGAM = "\xCE\xFA\xED\xFE"
|
||||
MACHO_MAGIC_64 = "\xFE\xED\xFA\xCF"
|
||||
MACHO_CIGAM_64 = "\xCF\xFA\xED\xFE"
|
||||
MACHO_FAT_MAGIC = "\xCA\xFE\xBA\xBE"
|
||||
MACHO_FAT_CIGAM = "\xBE\xBA\xFE\xCA"
|
||||
MACHO_P200_FAT_MAGIC = "\xCA\xFE\xD0\x0D"
|
||||
MACHO_P200_FAT_CIGAM = "\x0D\xD0\xFE\xCA"
|
||||
MACHO_MAGIC = b"\xFE\xED\xFA\xCE"
|
||||
MACHO_CIGAM = b"\xCE\xFA\xED\xFE"
|
||||
MACHO_MAGIC_64 = b"\xFE\xED\xFA\xCF"
|
||||
MACHO_CIGAM_64 = b"\xCF\xFA\xED\xFE"
|
||||
MACHO_FAT_MAGIC = b"\xCA\xFE\xBA\xBE"
|
||||
MACHO_FAT_CIGAM = b"\xBE\xBA\xFE\xCA"
|
||||
MACHO_P200_FAT_MAGIC = b"\xCA\xFE\xD0\x0D"
|
||||
MACHO_P200_FAT_CIGAM = b"\x0D\xD0\xFE\xCA"
|
||||
|
||||
# Linux binaries
|
||||
if progdat[0:4] == "\x7FELF":
|
||||
if progdat[0:4] == b"\x7FELF":
|
||||
# get file type
|
||||
self.fb = struct.unpack("H", progdat[0x12:0x14])[0] # e_machine
|
||||
|
||||
|
@ -142,7 +143,7 @@ class Program:
|
|||
maybe_path = lib_dir+arch+"/"
|
||||
if 'QEMU_LD_PREFIX' not in os.environ and os.path.exists(maybe_path):
|
||||
os.environ['QEMU_LD_PREFIX'] = os.path.realpath(maybe_path)
|
||||
print "**** set QEMU_LD_PREFIX to",os.environ['QEMU_LD_PREFIX']
|
||||
print("**** set QEMU_LD_PREFIX to",os.environ['QEMU_LD_PREFIX'])
|
||||
|
||||
if self.fb == 0x28:
|
||||
if '/lib/ld-linux.so.3' in progdat:
|
||||
|
@ -182,21 +183,21 @@ class Program:
|
|||
raise Exception("binary type "+hex(self.fb)+" not supported")
|
||||
|
||||
self.qirabinary = os.path.realpath(self.qirabinary)
|
||||
print "**** using",self.qirabinary,"for",hex(self.fb)
|
||||
print("**** using",self.qirabinary,"for",hex(self.fb))
|
||||
|
||||
self.runnable = True
|
||||
|
||||
# Windows binaries
|
||||
elif progdat[0:2] == "MZ":
|
||||
print "**** windows binary detected, only running the server"
|
||||
elif progdat[0:2] == b"MZ":
|
||||
print("**** windows binary detected, only running the server")
|
||||
pe = struct.unpack("I", progdat[0x3c:0x40])[0]
|
||||
wh = struct.unpack("H", progdat[pe+4:pe+6])[0]
|
||||
if wh == 0x14c:
|
||||
print "*** 32-bit windows"
|
||||
print("*** 32-bit windows")
|
||||
self.tregs = arch.X86REGS
|
||||
self.fb = 0x03
|
||||
elif wh == 0x8664:
|
||||
print "*** 64-bit windows"
|
||||
print("*** 64-bit windows")
|
||||
self.tregs = arch.X64REGS
|
||||
self.fb = 0x3e
|
||||
else:
|
||||
|
@ -204,17 +205,17 @@ class Program:
|
|||
|
||||
# MACHO FAT binaries
|
||||
elif progdat[0x0:0x04] in (MACHO_FAT_MAGIC, MACHO_FAT_CIGAM, MACHO_P200_FAT_MAGIC, MACHO_P200_FAT_CIGAM):
|
||||
print "**** Mach-O FAT (Universal) binary detected"
|
||||
print("**** Mach-O FAT (Universal) binary detected")
|
||||
|
||||
if progdat[0x04:0x05] == CPU_TYPE_ARM and progdat[0x08:0x09] in CPU_SUBTYPE_ARM:
|
||||
print "**** Mach-O ARM architecture detected"
|
||||
print("**** Mach-O ARM architecture detected")
|
||||
self.macharch = "arm"
|
||||
elif (progdat[0x08:0x0c] == CPU_TYPE_ARM64) or (progdat[0x1c:0x20] == CPU_TYPE_ARM64) or (progdat[0x30:0x34] == CPU_TYPE_ARM64):
|
||||
print "**** Mach-O Aarch64 architecture detected"
|
||||
print("**** Mach-O Aarch64 architecture detected")
|
||||
self.macharch = "aarch64"
|
||||
else:
|
||||
self.macharch = ""
|
||||
print "**** Mach-O X86/64 architecture detected"
|
||||
print("**** Mach-O X86/64 architecture detected")
|
||||
|
||||
if progdat[0x0:0x04] in (MACHO_P200_FAT_MAGIC, MACHO_P200_FAT_CIGAM):
|
||||
raise NotImplementedError("Pack200 compressed files are not supported yet")
|
||||
|
@ -236,24 +237,24 @@ class Program:
|
|||
if self.macharch == "arm" or self.macharch == "aarch64":
|
||||
raise NotImplementedError("ARM/Aarch64 Support is not implemented")
|
||||
if not os.path.isfile(self.pintool):
|
||||
print "Running a Mach-O FAT (Universal) binary requires PIN support. See tracers/pin_build.sh"
|
||||
print("Running a Mach-O FAT (Universal) binary requires PIN support. See tracers/pin_build.sh")
|
||||
exit()
|
||||
raise NotImplementedError("Mach-O FAT (Universal) binary not supported")
|
||||
self.runnable = True
|
||||
|
||||
# MACHO binaries
|
||||
elif progdat[0x0:0x04] in (MACHO_MAGIC_64, MACHO_CIGAM_64, MACHO_MAGIC, MACHO_CIGAM):
|
||||
print "**** Mach-O binary detected"
|
||||
print("**** Mach-O binary detected")
|
||||
|
||||
if progdat[0x04:0x05] == CPU_TYPE_ARM and progdat[0x08:0x09] in CPU_SUBTYPE_ARM:
|
||||
print "**** Mach-O ARM architecture detected"
|
||||
print("**** Mach-O ARM architecture detected")
|
||||
self.macharch = "arm"
|
||||
elif progdat[0x04:0x05] == CPU_TYPE_ARM and progdat[0x08:0x09] in CPU_SUBTYPE_ARM64:
|
||||
print "**** Mach-O Aarch64 architecture detected"
|
||||
print("**** Mach-O Aarch64 architecture detected")
|
||||
self.macharch = "aarch64"
|
||||
else:
|
||||
self.macharch = ""
|
||||
print "**** Mach-O X86/64 architecture detected"
|
||||
print("**** Mach-O X86/64 architecture detected")
|
||||
|
||||
if progdat[0x0:0x04] in (MACHO_MAGIC_64, MACHO_CIGAM_64):
|
||||
if progdat[0x0:0x04] == MACHO_CIGAM_64:
|
||||
|
@ -278,7 +279,7 @@ class Program:
|
|||
if self.macharch == "arm" or self.macharch == "aarch64":
|
||||
raise NotImplementedError("ARM/Aarch64 Support is not implemented")
|
||||
if not os.path.isfile(self.pintool):
|
||||
print "Running a Mach-O binary requires PIN support. See tracers/pin_build.sh"
|
||||
print("Running a Mach-O binary requires PIN support. See tracers/pin_build.sh")
|
||||
exit()
|
||||
self.runnable = True
|
||||
else:
|
||||
|
@ -286,7 +287,7 @@ class Program:
|
|||
|
||||
def clear(self):
|
||||
# probably always good to do except in development of middleware
|
||||
print "*** deleting old runs"
|
||||
print("*** deleting old runs")
|
||||
self.delete_old_runs()
|
||||
|
||||
# getting asm from qemu
|
||||
|
@ -481,13 +482,12 @@ class Trace:
|
|||
# is it safe to assume 4096 byte pages?
|
||||
|
||||
st = "*** mapping %s %s sz:0x%x off:0x%x @ 0x%X" % (sha1(alldat).hexdigest(), files[fil], sz, off, return_code)
|
||||
print st,
|
||||
print(st,)
|
||||
dat = alldat[off:off+sz]
|
||||
|
||||
self.program.static.add_memory_chunk(return_code, dat)
|
||||
print "done"
|
||||
except Exception, e:
|
||||
print e
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
except:
|
||||
pass
|
||||
|
@ -532,10 +532,10 @@ class Trace:
|
|||
|
||||
try:
|
||||
forkbase = get_forkbase_from_log(self.forknum)
|
||||
print "*** using base %d for %d" % (forkbase, self.forknum)
|
||||
print("*** using base %d for %d" % (forkbase, self.forknum))
|
||||
f = open(qira_config.TRACE_FILE_BASE+str(forkbase)+"_base")
|
||||
except Exception, e:
|
||||
print "*** base file issue",e
|
||||
except Exception as e:
|
||||
print("*** base file issue",e)
|
||||
# done
|
||||
return
|
||||
|
||||
|
@ -564,8 +564,8 @@ class Trace:
|
|||
for offset in os.listdir(images_dir+"/"+image):
|
||||
off_map[int(offset, 16)] = images_dir+"/"+image+"/"+offset
|
||||
img_map[unquote(image)] = off_map
|
||||
except Exception, e:
|
||||
print "Exception while dealing with _images/:", e
|
||||
except Exception as e:
|
||||
print("Exception while dealing with _images/:", e)
|
||||
|
||||
for ln in f.read().split("\n"):
|
||||
ln = ln.split(" ")
|
||||
|
@ -587,7 +587,7 @@ class Trace:
|
|||
with open(fn) as f:
|
||||
f.seek(offset)
|
||||
dat = f.read(se-ss)
|
||||
except Exception, e:
|
||||
print "Failed to get", fn, "offset", offset, ":", e
|
||||
except Exception as e:
|
||||
print("Failed to get", fn, "offset", offset, ":", e)
|
||||
continue
|
||||
self.program.static.add_memory_chunk(ss, dat)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
import os
|
||||
import socket
|
||||
import signal
|
||||
|
@ -27,7 +28,7 @@ def start_bindserver(program, port, parent_id, start_cl, loop = False):
|
|||
return
|
||||
# bindserver runs in a fork
|
||||
while 1:
|
||||
print "**** listening on",myss
|
||||
print("**** listening on",myss)
|
||||
(cs, address) = myss.accept()
|
||||
|
||||
# fork off the child if we are looping
|
||||
|
@ -36,7 +37,7 @@ def start_bindserver(program, port, parent_id, start_cl, loop = False):
|
|||
cs.close()
|
||||
continue
|
||||
run_id = get_next_run_id()
|
||||
print "**** ID",run_id,"CLIENT",cs, address, cs.fileno()
|
||||
print("**** ID",run_id,"CLIENT",cs, address, cs.fileno())
|
||||
|
||||
fd = cs.fileno()
|
||||
# python nonblocking is a lie...
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
from qira_base import *
|
||||
import qira_config
|
||||
import os
|
||||
|
@ -14,7 +15,7 @@ def socket_method(func):
|
|||
# before things are initted in the js, we get this
|
||||
for i in args:
|
||||
if i == None:
|
||||
#print "BAD ARGS TO %-20s" % (func.func_name), "with",args
|
||||
#print "BAD ARGS TO %-20s" % (func.__name__), "with",args
|
||||
return
|
||||
try:
|
||||
start = time.time()
|
||||
|
@ -23,10 +24,10 @@ def socket_method(func):
|
|||
|
||||
# print slow calls, slower than 50ms
|
||||
if tm > 50 or qira_config.WEBSOCKET_DEBUG:
|
||||
print "SOCKET %6.2f ms in %-20s with" % (tm, func.func_name), args
|
||||
print("SOCKET %6.2f ms in %-20s with" % (tm, func.__name__), args)
|
||||
return ret
|
||||
except Exception, e:
|
||||
print "ERROR",e,"in",func.func_name,"with",args
|
||||
except Exception as e:
|
||||
print("ERROR",e,"in",func.__name__,"with",args)
|
||||
return func_wrapper
|
||||
|
||||
import qira_socat
|
||||
|
@ -113,7 +114,7 @@ def mwpoller():
|
|||
@socket_method
|
||||
def forkat(forknum, clnum, pending):
|
||||
global program
|
||||
print "forkat",forknum,clnum,pending
|
||||
print("forkat",forknum,clnum,pending)
|
||||
|
||||
REGSIZE = program.tregs[1]
|
||||
dat = []
|
||||
|
@ -147,7 +148,7 @@ def forkat(forknum, clnum, pending):
|
|||
@socket_method
|
||||
def deletefork(forknum):
|
||||
global program
|
||||
print "deletefork", forknum
|
||||
print("deletefork", forknum)
|
||||
os.unlink(qira_config.TRACE_FILE_BASE+str(int(forknum)))
|
||||
del program.traces[forknum]
|
||||
push_updates()
|
||||
|
@ -157,7 +158,7 @@ def deletefork(forknum):
|
|||
def slice(forknum, clnum):
|
||||
trace = program.traces[forknum]
|
||||
data = qira_analysis.slice(trace, clnum)
|
||||
print "slice",forknum,clnum, data
|
||||
print("slice",forknum,clnum, data)
|
||||
emit('slice', forknum, data);
|
||||
|
||||
@socketio.on('doanalysis', namespace='/qira')
|
||||
|
@ -173,7 +174,7 @@ def analysis(forknum):
|
|||
@socket_method
|
||||
def connect():
|
||||
global program
|
||||
print "client connected", program.get_maxclnum()
|
||||
print("client connected", program.get_maxclnum())
|
||||
push_updates()
|
||||
|
||||
@socketio.on('getclnum', namespace='/qira')
|
||||
|
@ -429,11 +430,11 @@ def run_server(largs, lprogram):
|
|||
import qira_webstatic
|
||||
qira_webstatic.init(lprogram)
|
||||
|
||||
print "****** starting WEB SERVER on %s:%d" % (qira_config.HOST, qira_config.WEB_PORT)
|
||||
print("****** starting WEB SERVER on %s:%d" % (qira_config.HOST, qira_config.WEB_PORT))
|
||||
threading.Thread(target=mwpoller).start()
|
||||
try:
|
||||
socketio.run(app, host=qira_config.HOST, port=qira_config.WEB_PORT, log_output=False)
|
||||
except KeyboardInterrupt:
|
||||
print "*** User raised KeyboardInterrupt"
|
||||
print("*** User raised KeyboardInterrupt")
|
||||
exit()
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# eventually, this can live in a different process
|
||||
# or we can break the boundary at static2
|
||||
# these calls don't have to be included for qira to work
|
||||
from __future__ import print_function
|
||||
|
||||
import qira_config
|
||||
|
||||
|
@ -150,7 +151,7 @@ if qira_config.WITH_STATIC:
|
|||
for i in sorted(b.addresses):
|
||||
bbb = {'address': ghex(i)}
|
||||
copy_fields(bbb, program.static[i])
|
||||
bbb['dests'] = map(lambda (x,y): (ghex(x), y), program.static[i]['instruction'].dests())
|
||||
bbb['dests'] = map(lambda x: (ghex(x[0]), x[1]), program.static[i]['instruction'].dests())
|
||||
bb.append(bbb)
|
||||
blocks.append(bb)
|
||||
|
||||
|
@ -160,7 +161,7 @@ if qira_config.WITH_STATIC:
|
|||
@socket_method
|
||||
def make(typ, iaddr):
|
||||
iaddr = fhex(iaddr)
|
||||
print "*** make",typ,"at",ghex(iaddr)
|
||||
print("*** make",typ,"at",ghex(iaddr))
|
||||
if typ == 'function':
|
||||
program.static.analyzer.make_function_at(program.static, iaddr)
|
||||
elif typ == 'code':
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
import Queue
|
||||
try:
|
||||
import Queue
|
||||
except ImportError:
|
||||
import queue as Queue
|
||||
from model import Function, Block, DESTTYPE
|
||||
import byteweight
|
||||
import time
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
from elftools.elf.elffile import ELFFile
|
||||
from elftools.elf.sections import SymbolTableSection
|
||||
from elftools.elf.relocation import RelocationSection
|
||||
|
@ -23,13 +24,13 @@ def get_arch(fb):
|
|||
|
||||
def load_binary(static):
|
||||
try:
|
||||
elf = ELFFile(open(static.path))
|
||||
elf = ELFFile(open(static.path, "rb"))
|
||||
except ELFError:
|
||||
print "*** loader error: non-ELF detected"
|
||||
print("*** loader error: non-ELF detected")
|
||||
return
|
||||
|
||||
# TODO: replace with elf['e_machine']
|
||||
progdat = open(static.path).read(0x20)
|
||||
progdat = open(static.path, "rb").read(0x20)
|
||||
fb = struct.unpack("H", progdat[0x12:0x14])[0] # e_machine
|
||||
static['arch'] = get_arch(fb)
|
||||
static['entry'] = elf['e_entry']
|
||||
|
@ -39,11 +40,11 @@ def load_binary(static):
|
|||
addr = segment['p_vaddr']
|
||||
if segment['p_type'] == 'PT_LOAD':
|
||||
memsize = segment['p_memsz']
|
||||
static.add_memory_chunk(addr, segment.data().ljust(memsize, "\x00"))
|
||||
static.add_memory_chunk(addr, segment.data().ljust(memsize, b"\x00"))
|
||||
|
||||
for section in elf.iter_sections():
|
||||
if static.debug >= 1:
|
||||
print "** found section", section.name, type(section)
|
||||
print("** found section", section.name, type(section))
|
||||
|
||||
if isinstance(section, RelocationSection):
|
||||
symtable = elf.get_section(section['sh_link'])
|
||||
|
@ -53,7 +54,7 @@ def load_binary(static):
|
|||
for rel in section.iter_relocations():
|
||||
symbol = symtable.get_symbol(rel['r_info_sym'])
|
||||
if static.debug >= 1: #suppress output for testing
|
||||
print "Relocation",rel, symbol.name
|
||||
print("Relocation",rel, symbol.name)
|
||||
if rel['r_offset'] != 0 and symbol.name != "":
|
||||
static[rel['r_offset']]['name'] = "__"+symbol.name
|
||||
ncount += 1
|
||||
|
@ -85,12 +86,12 @@ def load_binary(static):
|
|||
#print symbol['st_info'], symbol.name, hex(symbol['st_value'])
|
||||
if symbol['st_value'] != 0 and symbol.name != "" and symbol['st_info']['type'] == "STT_FUNC":
|
||||
if static.debug >= 1:
|
||||
print "Symbol",hex(symbol['st_value']), symbol.name
|
||||
print("Symbol",hex(symbol['st_value']), symbol.name)
|
||||
static[symbol['st_value']]['name'] = symbol.name
|
||||
ncount += 1
|
||||
|
||||
# parse the DynamicSection to get the libraries
|
||||
#if isinstance(section, DynamicSection):
|
||||
if static.debug >= 1:
|
||||
print "** found %d names" % ncount
|
||||
print("** found %d names" % ncount)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
from capstone import *
|
||||
import capstone # for some unexported (yet) symbols in Capstone 3.0
|
||||
import qira_config
|
||||
|
@ -25,7 +26,7 @@ class Instruction(object):
|
|||
try:
|
||||
return BapInsn(*args, **kwargs)
|
||||
except Exception as exn:
|
||||
print "bap failed", type(exn).__name__, exn
|
||||
print("bap failed", type(exn).__name__, exn)
|
||||
return CsInsn(*args, **kwargs)
|
||||
else:
|
||||
return CsInsn(*args, **kwargs)
|
||||
|
@ -208,7 +209,7 @@ if qira_config.WITH_BAP:
|
|||
else:
|
||||
if offset != offset & 0xFFFFFFFF:
|
||||
if debug_level >= 1:
|
||||
print "[!] Warning: supplied offset 0x{:x} is not 32 bits.".format(offset)
|
||||
print("[!] Warning: supplied offset 0x{:x} is not 32 bits.".format(offset))
|
||||
offset = offset & 0xFFFFFFFF
|
||||
if (offset >> 31) & 1 == 1:
|
||||
offset_fixed = -(0xFFFFFFFF-offset+1)
|
||||
|
@ -227,7 +228,7 @@ if qira_config.WITH_BAP:
|
|||
v_prime = calc_offset(*k)
|
||||
if v_prime != v:
|
||||
k_fmt = (k[0],hex(k[1]),k[2])
|
||||
print "{0} -> {1:x} expected, got {0} -> {2:x}".format(k_fmt,v,v_prime)
|
||||
print("{0} -> {1:x} expected, got {0} -> {2:x}".format(k_fmt,v,v_prime))
|
||||
|
||||
class UnknownRegister(Exception):
|
||||
def __init__(self, reg):
|
||||
|
@ -504,10 +505,10 @@ class CsInsn(object):
|
|||
try:
|
||||
fmt, ref = self._get_ref_square_bracket()
|
||||
except AssertionError:
|
||||
print "*** Warning: assumption in _get_ref_square_bracket violated"
|
||||
print("*** Warning: assumption in _get_ref_square_bracket violated")
|
||||
return self.i.op_str
|
||||
except Exception as e:
|
||||
print "unknown exception in _get_operand_s"
|
||||
print("unknown exception in _get_operand_s")
|
||||
return self.i.op_str
|
||||
|
||||
try:
|
||||
|
@ -516,9 +517,9 @@ class CsInsn(object):
|
|||
except IgnoredRegister as e:
|
||||
pass
|
||||
except UnknownRegister as e:
|
||||
print "_get_operand_s: unknown register {} at clnum {}".format(e.reg, clnum)
|
||||
print("_get_operand_s: unknown register {} at clnum {}".format(e.reg, clnum))
|
||||
except Exception as e:
|
||||
print "unknown exception in _get_operand_s", e
|
||||
print("unknown exception in _get_operand_s", e)
|
||||
|
||||
return self.i.op_str
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python2.7
|
||||
from __future__ import print_function
|
||||
|
||||
# NO MORE RADARE
|
||||
# tags should be dynamically generated
|
||||
|
@ -98,7 +99,7 @@ class Static:
|
|||
@staticmethod
|
||||
def analyze_functions(x):
|
||||
dat = ida.fetch_tags()
|
||||
print dat
|
||||
print(dat)
|
||||
else:
|
||||
# run the elf loader
|
||||
sys.path.append(os.path.join(qira_config.BASEDIR, "static2", "builtin"))
|
||||
|
@ -108,7 +109,7 @@ class Static:
|
|||
loader.load_binary(self)
|
||||
|
||||
if self.debug >= 1:
|
||||
print "*** elf loaded"
|
||||
print("*** elf loaded")
|
||||
|
||||
"""
|
||||
# check the cache
|
||||
|
@ -252,7 +253,7 @@ class Static:
|
|||
for (laddress, llength) in self.base_memory:
|
||||
if address == laddress:
|
||||
if self.base_memory[(laddress, llength)] != dat:
|
||||
print "*** WARNING, changing segment",hex(laddress),llength
|
||||
print("*** WARNING, changing segment",hex(laddress),llength)
|
||||
return
|
||||
|
||||
# segments should have an idea of segment permission
|
||||
|
@ -262,14 +263,14 @@ class Static:
|
|||
def process(self):
|
||||
self.analyzer.analyze_functions(self)
|
||||
if self.debug >= 1:
|
||||
print "*** found %d functions" % len(self['functions'])
|
||||
print("*** found %d functions" % len(self['functions']))
|
||||
|
||||
|
||||
# *** STATIC TEST STUFF ***
|
||||
|
||||
if __name__ == "__main__":
|
||||
static = Static(sys.argv[1],debug=1)
|
||||
print "arch:",static['arch']
|
||||
print("arch:",static['arch'])
|
||||
|
||||
# find main
|
||||
static.process()
|
||||
|
@ -285,18 +286,18 @@ if __name__ == "__main__":
|
|||
|
||||
# function printer
|
||||
for f in sorted(static['functions']):
|
||||
print static[f.start]['name'] or hex(f.start), f
|
||||
print(static[f.start]['name'] or hex(f.start), f)
|
||||
for b in sorted(f.blocks):
|
||||
print " ",b
|
||||
print(" ",b)
|
||||
for a in sorted(b.addresses):
|
||||
print " ",hex(a),static._insert_names(static[a]['instruction'])
|
||||
print(" ",hex(a),static._insert_names(static[a]['instruction']))
|
||||
|
||||
|
||||
# print symbols
|
||||
print "symbols"
|
||||
print("symbols")
|
||||
names = static.get_tags(['name'])
|
||||
for addr in names:
|
||||
print "%8x: %s" % (addr, names[addr]['name'])
|
||||
print("%8x: %s" % (addr, names[addr]['name']))
|
||||
|
||||
#print static['functions']
|
||||
|
||||
|
|
Loading…
Reference in New Issue