-
Notifications
You must be signed in to change notification settings - Fork 1
/
exportSymbolPJ64.java
96 lines (86 loc) · 2.13 KB
/
exportSymbolPJ64.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//creates symbol table for Project64
//@author Blackgamma7
//@category symbol
//@keybinding
//@menupath
//@toolbar
import java.io.File;
import java.io.FileWriter;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.symbol.*;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.FunctionIterator;
public class exportSymbolPJ64 extends GhidraScript {
@Override
public void run() throws Exception {
SymbolTable st = currentProgram.getSymbolTable();
SymbolIterator it = st.getDefinedSymbols();
File f = askFile("Where do you want symbols?", "here");
FileWriter W = new FileWriter(f);
while (it.hasNext() && !monitor.isCancelled()) {
String datName="data";
Symbol s = it.next();
Address addr = s.getAddress();
String name = s.getName();
if (name.startsWith("FUN_") || !addr.isMemoryAddress()||s.getParentSymbol().getName().startsWith("switchD")||s.getParentSymbol().getName().startsWith("ConstFloats")) {continue;}
if(Character.isDigit(name.charAt(0))){name="_"+name;}
if(s.getSymbolType()!=SymbolType.FUNCTION){
try{datName=getDataAt(addr).getBaseDataType().getName().toLowerCase();}
catch(Exception e){datName="error";}}
else{datName="code";}
switch(datName){
default:
datName="data";
break;
case "undefined4":
case "uint":
datName="u32";
break;
case "undefined2":
case "ushort":
datName="u16";
break;
case "float":
case "double":
case "u32":
case "s16":
case "code":
break;
case "float[2]":
datName="v2";
break;
case "float[3]":
datName="v3";
break;
case "float[4]":
datName="v4";
break;
case "undefined1":
case "byte":
case "bool":
datName="u8";
break;
case "char":
case "s8":
datName="s8";
break;
case "short":
datName="s16";
break;
case "int":
datName="s32";
break;
case "undefined8":
case "ulonglong":
datName="u64";
break;
case "longlong":
datName="s64";
break;
}
W.write(addr+","+datName+","+name+"\n");
}
W.close();
}
}