GhidraScripts/SetCallConvBulk.java

51 lines
1.7 KiB
Java
Raw Normal View History

2024-01-22 05:51:31 +01:00
//TODO write a description for this script
//@author DrFrugal
//@category Functions
2024-01-22 05:51:31 +01:00
//@keybinding
//@menupath
//@toolbar bomb
import java.util.List;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;
public class SetCallConvBulk extends GhidraScript {
2024-01-22 05:51:31 +01:00
public void run() throws Exception {
String callingConvention = BulkUtils.askForCallingConvention(this);
List<Function> matchingFunctions = BulkUtils.getFunctions(this);
2024-01-22 05:51:31 +01:00
int skipped = BulkUtils.removeFunctionsByCallingConvention(matchingFunctions, callingConvention);
int numOfMatches = matchingFunctions.size();
// only abort if there are no matches AND no matches have been skipped, so the users understands why there are no matches
if(numOfMatches == 0 && skipped == 0){
println("Abort: no matches found");
return;
}
String title = "Set calling convention of " + matchingFunctions.size() + " function(s) to " + callingConvention;
boolean confirmed = BulkUtils.showFunctionConfirmationDialog(matchingFunctions, title, skipped, "Number of matches skipped (calling convention already matches): %d");
if (!confirmed) {
println("Abort: negative confirmation");
return;
}
int success = 0;
int fail = 0;
for (Function func : matchingFunctions) {
try {
func.setCallingConvention(callingConvention);
success++;
} catch (Exception e) {
println("Failed to update function " + func.getName() + " at " + func.getEntryPoint() + " - " + e.getMessage());
fail++;
}
}
BulkUtils.printDoneMessage(this, success, fail);
}
}