-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasm_exporter.py
39 lines (33 loc) · 869 Bytes
/
asm_exporter.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
from ghidra.program.model.listing import Listing
from ghidraType import Inst, Program
args = getScriptArgs()
def bytesToHex(byte):
hexs = list()
for b in byte:
b = (bin(((1 << 8) - 1) & b)[2:]).zfill(8)
h = hex(int(b, 2))[2:]
if len(h) == 1:
h = "0" + h
hexs.append(h)
return hexs
cuIterator = Listing.getCodeUnits(currentProgram.getListing(), True)
insts = list()
code = Program(name="test")
for line in cuIterator:
insts.append(line)
for line in insts:
label = None
if line.getLabel():
label = str(line.getLabel())
byte = None
inst = str(line)
if inst != "?? ??":
byte = bytesToHex(line.getBytes())
code.addInst(Inst(
label,
str(line.getAddress()),
inst,
str(line.getMaxAddress()),
byte
))
code.save_to_file(args[0])