-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_disassemble.py
executable file
·48 lines (36 loc) · 1.17 KB
/
simple_disassemble.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
"""
Very simple example disassembly for RISC OS code.
"""
import os
import struct
import sys
import riscos_disassemble
if len(sys.argv) < 2:
print("Syntax: {} <filename>".format(sys.argv[0]))
exit(1)
filename = sys.argv[1]
dis_cls = riscos_disassemble.get_disassembler('arm')
if dis_cls:
dis = dis_cls()
else:
exit("Could not find disassembler for ARM")
with open(filename, 'rb') as fh:
addr = 0
while True:
data = fh.read(4)
if len(data) < 4:
break
word = struct.unpack('<L', data)[0]
(consumed, arm) = dis.disassemble(addr, data)
def char(x):
if x < 0x20 or x>=0x7f:
return '.'
return chr(x)
print("{:08x} : {:08x} : {}{}{}{} : {}".format(addr, word,
char(word & 255),
char((word>>8) & 255),
char((word>>16) & 255),
char((word>>24) & 255),
arm))
addr += 4