test_mos65xx.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Capstone Python bindings, by Sebastian Macke <Sebastian Macke>
4 from __future__ import print_function
5 from capstone import *
6 from capstone.mos65xx import *
7 from xprint import to_hex, to_x
8 
9 MOS65XX_CODE = b"\x0d\x34\x12\x00\x81\x65\x6c\x01\x00\x85\xFF\x10\x00\x19\x42\x42\x00\x49\x42"
10 
11 address_modes=[
12  'No address mode',
13  'implied addressing (no addressing mode)',
14  'accumulator addressing',
15  'absolute addressing',
16  'zeropage addressing',
17  '8 Bit immediate value',
18  'indexed absolute addressing by the X index register',
19  'indexed absolute addressing by the Y index register',
20  'indexed indirect addressing by the X index register',
21  'indirect indexed addressing by the Y index register',
22  'indexed zeropage addressing by the X index register',
23  'indexed zeropage addressing by the Y index register',
24  'relative addressing used by branches',
25  'absolute indirect addressing'
26 ];
27 
28 
30  # print address, mnemonic and operands
31  print("0x%x:\t%s\t%s" % (insn.address, insn.mnemonic, insn.op_str))
32 
33  # "data" instruction generated by SKIPDATA option has no detail
34  if insn.id == 0:
35  return
36  print("\taddress mode: %s" % (address_modes[insn.am]))
37  print("\tmodifies flags: %s" % ('true' if insn.modifies_flags != 0 else 'false'))
38  if len(insn.operands) > 0:
39  print("\top_count: %u" % len(insn.operands))
40  c = -1
41  for i in insn.operands:
42  c += 1
43  if i.type == MOS65XX_OP_REG:
44  print("\t\toperands[%u].type: REG = %s" % (c, insn.reg_name(i.reg)))
45  if i.type == MOS65XX_OP_IMM:
46  print("\t\toperands[%u].type: IMM = 0x%s" % (c, to_x(i.imm)))
47  if i.type == MOS65XX_OP_MEM:
48  print("\t\toperands[%u].type: MEM = 0x%s" % (c, to_x(i.mem)))
49 
50 
51 # ## Test class Cs
52 def test_class():
53  print("*" * 16)
54  print("Platform: %s" % "MOS65XX")
55  print("Code: %s" % to_hex(MOS65XX_CODE))
56  print("Disasm:")
57 
58  try:
59  md = Cs(CS_ARCH_MOS65XX, 0)
60  md.detail = True
61  for insn in md.disasm(MOS65XX_CODE, 0x1000):
62  print_insn_detail(insn)
63  print()
64 
65  print("0x%x:\n" % (insn.address + insn.size))
66  except CsError as e:
67  print("ERROR: %s" % e)
68 
69 
70 if __name__ == '__main__':
71  test_class()
capstone.Cs
Definition: third_party/bloaty/third_party/capstone/bindings/python/capstone/__init__.py:800
xprint.to_x
def to_x(s)
Definition: xprint.py:29
test_mos65xx.print_insn_detail
def print_insn_detail(insn)
Definition: test_mos65xx.py:29
capstone.mos65xx
Definition: mos65xx.py:1
test_mos65xx.test_class
def test_class()
Definition: test_mos65xx.py:52
xprint.to_hex
def to_hex(s, prefix_0x=True)
Definition: xprint.py:9
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:28