-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemangleRTTIString.java
More file actions
41 lines (37 loc) · 1.37 KB
/
DemangleRTTIString.java
File metadata and controls
41 lines (37 loc) · 1.37 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
//@category RTTI
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.symbol.SourceType;
import ghidra.program.model.symbol.Symbol;
import static util.Demangler.DemangleAndNameNamespace;
public class DemangleRTTIString extends GhidraScript {
@Override
protected void run() throws Exception {
AddressSetView selection = currentSelection;
if (selection != null) {
for (AddressRange ar : selection) {
for (Address addr : ar) {
if (getDataAt(addr) == null) continue;
demangleAt(addr);
}
}
} else {
demangleAt(currentAddress);
}
}
private void demangleAt(Address addr) throws Exception {
if (getDataAt(addr).getValue() instanceof String name) {
Symbol symbol = getSymbolAt(addr);
if (symbol == null) {
symbol = createLabel(addr, name, true);
}
String mangled = String.format("_ZTS%s",name);
symbol.setName(mangled, SourceType.DEFAULT);
DemangleAndNameNamespace(currentProgram, addr, monitor);
} else {
printf("The data at %s is not a String!\n", addr);
}
}
}