Commit 6313165c by Melvin Klimke Committed by Enkelmann

Indirect call flows (#96)

parent 514be103
......@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript {
Term<Program> program = null;
FunctionManager funcMan;
HashMap<String, Integer> functionEntryPoints;
ghidra.program.model.listing.Program ghidraProgram;
VarnodeContext context;
String cpuArch;
......@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript {
cpuArch = getCpuArchitecture();
program = createProgramTerm();
functionEntryPoints = new HashMap<String, Integer>();
setFunctionEntryPoints();
Project project = createProject();
program = iterateFunctions(simpleBM, listing);
......@@ -91,6 +94,24 @@ public class PcodeExtractor extends GhidraScript {
/**
* Adds all entry points of internal and external function to a global hash map
* This will later speed up the cast of indirect Calls.
*/
protected void setFunctionEntryPoints() {
// Add external symbols and internal function addresses to hash map
int funcCounter = 0;
for(ExternSymbol sym : program.getTerm().getExternSymbols()){
functionEntryPoints.put(sym.getAddress(), funcCounter);
funcCounter++;
}
for(Function func : funcMan.getFunctionsNoStubs(true)) {
functionEntryPoints.put(func.getEntryPoint().toString(), funcCounter);
funcCounter++;
}
}
/**
*
* @return: CPU architecture as string.
*
......@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript {
* Resolves the target id for an indirect jump
*/
protected Tid getTargetTid(Varnode target) {
if (!target.isRegister() && !target.isUnique()) {
Reference[] referenced = ghidraProgram.getReferenceManager().getReferencesFrom(target.getAddress());
if(referenced.length != 0) {
for (ExternSymbol symbol : program.getTerm().getExternSymbols()) {
if (symbol.getAddress().equals(referenced[0].getToAddress().toString())) {
return symbol.getTid();
}
Address[] flowDestinations = PcodeBlockData.instruction.getFlows();
if(flowDestinations.length == 1) {
for(Address flow : flowDestinations) {
if(functionEntryPoints.containsKey(flow.toString())){
return new Tid(String.format("sub_%s", flow.toString()), flow.toString());
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment