-
Notifications
You must be signed in to change notification settings - Fork 3
/
RemoveAllReferencesToAddress.java
42 lines (38 loc) · 1.26 KB
/
RemoveAllReferencesToAddress.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
//Remove all references to data.
//@author saruman9
//@category References
//@keybinding ctrl 1
//@menupath
//@toolbar
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressIterator;
import ghidra.program.model.symbol.Reference;
import ghidra.util.Msg;
public class RemoveAllReferencesToAddress 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;
}
if (currentSelection != null) {
AddressIterator addresses = currentSelection.getAddresses(true);
while (addresses.hasNext()) {
Address address = addresses.next();
removeReferencesToAddress(address);
}
} else {
removeReferencesToAddress(currentAddress);
}
}
private void removeReferencesToAddress(Address addressTo) {
Reference[] references = getReferencesTo(addressTo);
for (Reference reference : references) {
removeReference(reference);
}
}
}