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
评论列表
文章目录