def html(self): out = '<h1>Procedure {0}</h1>\n'.format(tag.nameForAddress(self.start_addr)); out += '<pre class="disasm">'; import disasm for addr in sorted(self.visited): if addr in self.labels: out += html.label(addr) out += disasm.decodeCache(addr)[0].html(0) out += '</pre>\n' return out
def addBlock(self, pos, start_addr, end_addr): instructions = [] addr = start_addr while addr < end_addr: instr, addr = disasm.decodeCache(addr) instructions.append(instr) if not instr.hasContinue(): break assert instructions childs = [] last = instructions[-1] if last.hasContinue(): childs.append(end_addr) remove_last = False if last.name == 'JP': childs += last.allJumps() if last.cond.alwaysTrue() and last.allJumps(): remove_last = True elif last.name == 'switch': childs += last.jumpsForSize(self.jumptable_sizes[addr]) # TODO: XXX: addr is not nice here elif last.name == 'RET': childs.append(None) if not last.hasContinue(): remove_last = True if remove_last: instructions = instructions[:-1] from flowcontrol import Block block = Block(instructions) self.blocks[pos] = block for ch in childs: if ch not in self.block_starts: if ch is not None: self.addFakeBlock(ch) self._childs[self.block_id_at_addr[start_addr]] = [self.block_id_at_addr[ch] for ch in childs]