text
stringlengths
1
93.6k
if not instr.isValid():
break
if instr.isBlockEnding():
if instr.isConditionalBranch():
self.true_path = instr.target
self.false_path = addr + instr.length()
self.exits += [self.true_path, self.false_path]
elif instr.target != None:
self.exits += [instr.target]
break
addr += instr.length()
if addr in known_instrs:
self.exits += [addr]
break
def update(self):
changed = False
for instr in self.instrs:
if instr.format_text(self, self.analysis.options):
changed = True
return changed
class Function:
def __init__(self, analysis, exe, entry, name = None):
self.analysis = analysis
self.exe = exe
self.entry = entry
if name:
self.name = name
else:
self.name = "sub_%.8x" % entry
self.blocks = {}
self.plt = False
self.ready = False
self.update_id = None
def findBasicBlocks(self):
# Reset block information in case we are reanalyzing an updated function
self.blocks = {}
self.plt = False
self.ready = False
self.update_id = self.analysis.get_next_update_id()
# Create initial basic block and add it to the queue
block = BasicBlock(self.analysis, self.exe, self.entry)
block.header_text.lines += [[[self.name + ":", QColor(192, 0, 0)]]]
block.header_text.tokens += [[[0, len(self.name), "ptr", self.entry, self.name]]]
queue = [block]
known_instrs = {}
# Process until all blocks are found
while len(queue) > 0:
block = queue.pop()
# Find instructions for this block
block.populate(known_instrs)
self.blocks[block.entry] = block
# Follow block exits
for edge in block.exits:
already_found = edge in self.blocks
for i in queue:
if i.entry == edge:
already_found = True
if not already_found:
if edge in known_instrs:
# Address is within another basic block, split the block so that
# the new edge can point to a basic block as well
block = known_instrs[edge]
for i in range(0, len(block.instrs)):
if block.instrs[i].addr == edge:
break
new_block = BasicBlock(self.analysis, self.exe, edge)
new_block.exits = block.exits
new_block.true_path = block.true_path
new_block.false_path = block.false_path
new_block.instrs = block.instrs[i:]
for instr in new_block.instrs:
known_instrs[instr.addr] = new_block
self.blocks[edge] = new_block
block.exits = [edge]
block.true_path = None
block.false_path = None
block.instrs = block.instrs[0:i]
else:
# New basic block
block = BasicBlock(self.analysis, self.exe, edge)
self.blocks[edge] = block
known_instrs[edge] = block
queue += [block]
# Set previous block list for each block
for block in self.blocks.values():
block.prev = []
for block in self.blocks.values():
for exit in block.exits: