MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / decode_instruction

Method decode_instruction

python/examples/nes.py:461–483  ·  view source on GitHub ↗
(data:bytes, addr:int)

Source from the content-addressed store, hash-verified

459
460 @staticmethod
461 def decode_instruction(data:bytes, addr:int) -> Optional[Tuple[Mnemonic, Operand, int, int]]:
462 if len(data) < 1:
463 return None
464 opcode = ord(data[0:1])
465 instr = M6502.InstructionNames[opcode]
466 if instr is None:
467 return None
468 operand = M6502.InstructionOperandTypes[opcode]
469 assert operand is not None
470 length = 1 + M6502.OperandLengths[operand]
471 if len(data) < length:
472 return None
473
474 if M6502.OperandLengths[operand] == 0:
475 value = 0
476 elif operand == REL:
477 value = (addr + 2 + struct.unpack("b", data[1:2])[0]) & 0xffff
478 elif M6502.OperandLengths[operand] == 1:
479 value = ord(data[1:2])
480 else:
481 value = struct.unpack("<H", data[1:3])[0]
482
483 return instr, operand, length, value
484
485 def get_instruction_info(self, data:bytes, addr:int) -> Optional[InstructionInfo]:
486 result = M6502.decode_instruction(data, addr)

Callers 3

get_instruction_infoMethod · 0.80
get_instruction_textMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected