GhidraScripts/ImportCallConvBulk.java

48 lines
1.3 KiB
Java

//TODO write a description for this script
//@author DrFrugal
//@category Functions
//@keybinding
//@menupath
//@toolbar bomb
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import ghidra.app.script.GhidraScript;
import ghidra.program.model.listing.Function;
public class ImportCallConvBulk extends GhidraScript {
public void run() throws Exception {
String ln;
String[] shards;
Function func;
File f = askFile("Import Calling Conventions", "OK");
BufferedReader br = new BufferedReader(new FileReader(f));
while((ln = br.readLine()) != null) {
ln = ln.trim();
if(ln == "") continue; // skip empty line
shards = ln.split(" "); // first shard is address, second shard is calling convention
if(shards.length != 2) continue; // malformed line
func = getFunctionAt(toAddr(shards[0]));
if(func == null) continue; // unable to find a function at this offset
switch(shards[1]) {
case "__cdecl":
case "__fastcall":
case "__stdcall":
case "__thiscall":
func.setCallingConvention(shards[1]);
break;
default:
func.setCallingConvention("unknown");
func.addTag(shards[1]);
break;
}
}
br.close();
}
}