-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRemoveExternalReferences.java
48 lines (43 loc) · 1.88 KB
/
RemoveExternalReferences.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
//Remove old external references
//@author saruman9
//@category References.External
//@keybinding ctrl 1
//@menupath
//@toolbar
import ghidra.app.script.GhidraScript;
import ghidra.program.model.symbol.ExternalLocation;
import ghidra.program.model.symbol.ExternalLocationIterator;
import ghidra.program.model.symbol.ExternalManager;
import ghidra.program.model.symbol.Reference;
import ghidra.program.model.symbol.ReferenceManager;
import ghidra.program.model.symbol.SourceType;
import ghidra.util.Msg;
public class RemoveExternalReferences extends GhidraScript {
@Override
protected void run() throws Exception {
if (currentProgram == null) {
Msg.showError(this,
null,
"Error",
"This script should be run from a tool with open program.");
return;
}
ExternalManager externalManager = currentProgram.getExternalManager();
ReferenceManager referenceManager = currentProgram.getReferenceManager();
for (String libraryNames : externalManager.getExternalLibraryNames()) {
ExternalLocationIterator externalLocationIterator =
externalManager.getExternalLocations(libraryNames);
while (externalLocationIterator.hasNext()) {
ExternalLocation externalLocation = externalLocationIterator.next();
for (Reference referenceExternal : referenceManager
.getReferencesTo(externalLocation.getExternalSpaceAddress())) {
referenceManager.addMemoryReference(referenceExternal.getFromAddress(),
externalLocation.getAddress(),
referenceExternal.getReferenceType(),
SourceType.ANALYSIS,
referenceExternal.getOperandIndex());
}
}
}
}
}