Commit 6313165c by Melvin Klimke Committed by Enkelmann

Indirect call flows (#96)

parent 514be103
...@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript { ...@@ -56,6 +56,7 @@ public class PcodeExtractor extends GhidraScript {
Term<Program> program = null; Term<Program> program = null;
FunctionManager funcMan; FunctionManager funcMan;
HashMap<String, Integer> functionEntryPoints;
ghidra.program.model.listing.Program ghidraProgram; ghidra.program.model.listing.Program ghidraProgram;
VarnodeContext context; VarnodeContext context;
String cpuArch; String cpuArch;
...@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript { ...@@ -79,6 +80,8 @@ public class PcodeExtractor extends GhidraScript {
cpuArch = getCpuArchitecture(); cpuArch = getCpuArchitecture();
program = createProgramTerm(); program = createProgramTerm();
functionEntryPoints = new HashMap<String, Integer>();
setFunctionEntryPoints();
Project project = createProject(); Project project = createProject();
program = iterateFunctions(simpleBM, listing); program = iterateFunctions(simpleBM, listing);
...@@ -91,6 +94,24 @@ public class PcodeExtractor extends GhidraScript { ...@@ -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. * @return: CPU architecture as string.
* *
...@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript { ...@@ -998,13 +1019,11 @@ public class PcodeExtractor extends GhidraScript {
* Resolves the target id for an indirect jump * Resolves the target id for an indirect jump
*/ */
protected Tid getTargetTid(Varnode target) { protected Tid getTargetTid(Varnode target) {
if (!target.isRegister() && !target.isUnique()) { Address[] flowDestinations = PcodeBlockData.instruction.getFlows();
Reference[] referenced = ghidraProgram.getReferenceManager().getReferencesFrom(target.getAddress()); if(flowDestinations.length == 1) {
if(referenced.length != 0) { for(Address flow : flowDestinations) {
for (ExternSymbol symbol : program.getTerm().getExternSymbols()) { if(functionEntryPoints.containsKey(flow.toString())){
if (symbol.getAddress().equals(referenced[0].getToAddress().toString())) { return new Tid(String.format("sub_%s", flow.toString()), flow.toString());
return symbol.getTid();
}
} }
} }
} }
......
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