assembler.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:bytecode_simplifier 作者: extremecoders-re 项目源码 文件源码
def calculate_ins_operands(self):
        """
        Instructions like JUMP_FORWARD & SETUP_LOOP uses the operand to refer to other instructions.
        This reference is an integer denoting the offset/absolute address of the target. This function
        calculates the values of these operand
        """
        logger.debug('Calculating instruction operands.')
        for block in self.bb_ordered:
            addr = block.address
            for ins in block.instruction_iter():
                addr += ins.size
                if ins.opcode in dis.hasjabs:
                    # ins.argval is a BasicBlock
                    ins.arg = ins.argval.address
                    # TODO
                    # We do not generate EXTENDED_ARG opcode at the moment,
                    # hence size of opcode argument can only be 2 bytes
                    assert ins.arg <= 0xFFFF
                elif ins.opcode in dis.hasjrel:
                    ins.arg = ins.argval.address - addr
                    # relative jump can USUALLY go forward
                    assert ins.arg >= 0
                    assert ins.arg <= 0xFFFF
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号