-
Notifications
You must be signed in to change notification settings - Fork 3
/
SetEntryPointsInSelection.java
45 lines (40 loc) · 1.42 KB
/
SetEntryPointsInSelection.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
//Set functions in selection as entry points.
//@author saruman9
//@category Selection
//@keybinding
//@menupath
//@toolbar
import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressRange;
import ghidra.program.model.address.AddressRangeIterator;
import ghidra.program.model.listing.FunctionManager;
import ghidra.util.Msg;
public class SetEntryPointsInSelection 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) {
Msg.showError(this,
null,
"Error",
"You should select needed functions.");
return;
}
FunctionManager functionManager = currentProgram.getFunctionManager();
AddressRangeIterator addressIterator = currentSelection.getAddressRanges();
while (addressIterator.hasNext()) {
AddressRange addressRange = addressIterator.next();
Address entryPoint = addressRange.getMinAddress();
if (functionManager.getFunctionAt(entryPoint) != null) {
addEntryPoint(entryPoint);
}
}
}
}