-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportAssembly.java
More file actions
52 lines (50 loc) · 2.03 KB
/
ExportAssembly.java
File metadata and controls
52 lines (50 loc) · 2.03 KB
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
49
50
51
52
//@category 3DS
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressSetView;
import ghidra.program.model.lang.OperandType;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Instruction;
import ghidra.program.model.symbol.Symbol;
import java.util.ArrayList;
import java.util.List;
public class ExportAssembly extends GhidraScript {
@Override
protected void run() throws Exception {
Function f = getFunctionContaining(currentAddress);
AddressSetView body = f.getBody();
List<Instruction> instructions = new ArrayList<>();
for (AddressRange ar : body) {
ar.forEach(a -> {
Instruction i = getInstructionAt(a);
if (i == null) return;
instructions.add(i);
});
}
instructions.forEach(i -> {
String asm = i.toString();
Address addr = i.getAddress();
for (int j=0; j < i.getNumOperands(); j++) {
int o = i.getOperandType(j);
switch (o) {
case OperandType.ADDRESS | OperandType.SCALAR -> {
// [DAT_XYZ]
String addr_str = i.getDefaultOperandRepresentation(j);
String addr_str_cut = addr_str.substring(1, addr_str.length() - 1);
asm = asm.replace(addr_str, getSymbolAt(parseAddress(addr_str_cut)).getName());
}
case OperandType.ADDRESS | OperandType.CODE -> {
String addr_str = i.getDefaultOperandRepresentation(j);
asm = asm.replace(addr_str, getSymbolAt(parseAddress(addr_str)).getName());
}
}
}
Symbol sym = getSymbolAt(addr);
if (sym != null) {
println(sym.getName() + ":");
}
println(" " + asm);
});
}
}