(self, block: BlockNode)
Parse instructions for a given block node
Parse instructions for a given block node
Parse instructions for a given block node
def parse_block(self, block: BlockNode) -> None:
        """
        Parse instructions for a given block node
        """
        func = self.func_lookup(block)
        if func and func.addr == block.addr:
            self.raw_result.append(FuncComment(block.function))
            self.raw_result.append(func)
        bs = BlockStart(block, func, self.project)
        self.raw_result.append(bs)

        if block.is_hook:
            hook = Hook(block)
            self.raw_result.append(hook)
            self.raw_result_map['hooks'][block.addr] = hook
        elif self.project.arch.capstone_support:
            # Prefer Capstone first, where we are able to extract a bit more
            # about the operands
            if block.thumb:
                aligned_block_addr = (block.addr >> 1) << 1
                cs = self.project.arch.capstone_thumb
            else:
                aligned_block_addr = block.addr
                cs = self.project.arch.capstone
            if block.bytestr is None:
                bytestr = self.project.loader.memory.load(aligned_block_addr, block.size)
            else:
                bytestr = block.bytestr
            self.block_to_insn_addrs[block.addr] = []
            for cs_insn in cs.disasm(bytestr, block.addr):
                self._add_instruction_to_results(block, CapstoneInsn(cs_insn), bs)
        elif pcode is not None and isinstance(self.project.factory.default_engine, pcode.HeavyPcodeMixin):
            # When using the P-code engine, we can fall back on its disassembly
            # in the event that Capstone does not support it
            self.block_to_insn_addrs[block.addr] = []
            b = self.project.factory.block(block.addr, size=block.size)
            for insn in b.disassembly.insns:
                self._add_instruction_to_results(block, insn, bs)
        elif type(block) is SootBlockNode:
            for raw_stmt in block.stmts:
                stmt = SootStatement(block.addr, raw_stmt)
                self.raw_result.append(stmt)
                self.raw_result_map['instructions'][stmt.addr] = stmt
                self.block_to_insn_addrs[block.addr].append(stmt.addr)
        else:
            raise TypeError("")

        if self._include_ir:
            b = self.project.factory.block(block.addr, size=block.size)
            self._add_block_ir_to_results(block, b.vex)
def parse_block ( self , block : BlockNode ) -> None : func = self . func_lookup ( block ) if func and func . addr == block . addr : self . raw_result . append ( FuncComment ( block . function ) ) self . raw_result . append ( func ) bs = BlockStart ( block , func , self . project ) self . raw_result . append ( bs ) if block . is_hook : hook = Hook ( block ) self . raw_result . append ( hook ) self . raw_result_map [ 'hooks' ] [ block . addr ] = hook elif self . project . arch . capstone_support : # Prefer Capstone first, where we are able to extract a bit more # about the operands if block . thumb : aligned_block_addr = ( block . addr >> 1 ) << 1 cs = self . project . arch . capstone_thumb else : aligned_block_addr = block . addr cs = self . project . arch . capstone if block . bytestr is None : bytestr = self . project . loader . memory . load ( aligned_block_addr , block . size ) else : bytestr = block . bytestr self . block_to_insn_addrs [ block . addr ] = [ ] for cs_insn in cs . disasm ( bytestr , block . addr ) : self . _add_instruction_to_results ( block , CapstoneInsn ( cs_insn ) , bs ) elif pcode is not None and isinstance ( self . project . factory . default_engine , pcode . HeavyPcodeMixin ) : # When using the P-code engine, we can fall back on its disassembly # in the event that Capstone does not support it self . block_to_insn_addrs [ block . addr ] = [ ] b = self . project . factory . block ( block . addr , size = block . size ) for insn in b . disassembly . insns : self . _add_instruction_to_results ( block , insn , bs ) elif type ( block ) is SootBlockNode : for raw_stmt in block . stmts : stmt = SootStatement ( block . addr , raw_stmt ) self . raw_result . append ( stmt ) self . raw_result_map [ 'instructions' ] [ stmt . addr ] = stmt self . block_to_insn_addrs [ block . addr ] . append ( stmt . addr ) else : raise TypeError ( "" ) if self . _include_ir : b = self . project . factory . block ( block . addr , size = block . size ) self . _add_block_ir_to_results ( block , b . vex )