-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSetDefaultCallingConvInSelection.java
47 lines (42 loc) · 1.57 KB
/
SetDefaultCallingConvInSelection.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
//Set default calling convention for functions in a selection.
//@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.Function;
import ghidra.program.model.listing.FunctionManager;
import ghidra.util.Msg;
public class SetDefaultCallingConvInSelection 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();
Function function = functionManager.getFunctionAt(entryPoint);
if (function != null) {
function.setCallingConvention(Function.DEFAULT_CALLING_CONVENTION_STRING);
}
}
}
}