text
stringlengths
1
93.6k
self.blocks[exit].prev.append(block)
if (len(self.blocks) == 1) and (len(block.instrs) == 1) and (block.instrs[0].plt != None):
# Function is a trampoline to a PLT entry
self.rename(block.instrs[0].plt)
self.plt = True
self.exe.create_symbol(self.entry, self.name)
def findCalls(self):
calls = []
for block in self.blocks.values():
for instr in block.instrs:
if instr.isCall() and (instr.target != None):
if (instr.target >= self.exe.start()) and (instr.target < self.exe.end()):
calls += [instr.target]
return calls
def update(self):
changed = False
for block in self.blocks.values():
if block.update():
changed = True
if changed:
self.update_id = self.analysis.get_next_update_id()
def rename(self, name):
self.name = name
self.blocks[self.entry].header_text.lines[0] = [[name + ":", QColor(192, 0, 0)]]
self.blocks[self.entry].header_text.tokens[0] = [[0, len(self.name), "ptr", self.entry, self.name]]
class Analysis:
def __init__(self, exe):
self.exe = exe
self.start = None
self.functions = {}
self.run = True
self.lock = threading.Lock()
self.queue = []
self.status = ""
self.update_id = 0
self.update_request = False
self.options = set()
self.exe.add_callback(self)
def get_next_update_id(self):
self.update_id += 1
return self.update_id
def analyze(self):
self.lock.acquire()
if hasattr(self.exe, "entry"):
self.status = "Disassembling function at 0x%.8x..." % self.exe.entry()
self.start = Function(self, self.exe, self.exe.entry(), '_start')
self.functions[self.exe.entry()] = self.start
self.start.findBasicBlocks()
self.queue += self.start.findCalls()
self.start.ready = True
self.lock.release()
while self.run:
while (len(self.queue) > 0) and self.run:
self.lock.acquire()
entry = self.queue.pop()
self.status = "Disassembling function at 0x%.8x..." % entry
if entry not in self.functions:
if entry in self.exe.symbols_by_addr:
func = Function(self, self.exe, entry, self.exe.symbols_by_addr[entry])
else:
func = Function(self, self.exe, entry)
self.functions[entry] = func
else:
func = self.functions[entry]
func.findBasicBlocks()
calls = func.findCalls()
for call in calls:
already_found = self.functions.has_key(call)
for i in self.queue:
if i == call:
already_found = True
if not already_found:
self.queue += [call]
func.ready = True
self.lock.release()
# Give GUI thread a chance to do stuff
time.sleep(0.001)
# Update disassembly so that function names are correct
self.update_request = False
for func in self.functions.values():
if not self.run:
break
self.lock.acquire()
self.status = "Updating function at 0x%.8x..." % func.entry
func.update()