Ghidra is a software reverse engineering (SRE) framework
GP-1418_emteere fixed issues with memory usage for very long functions. Sped up constant analysis by not storing fallthru state to future flows
emteere03af0b6f56d1
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/SymbolicPropogator.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/SymbolicPropogator.javaindex efc1fa24f2..f38e35bea2 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/SymbolicPropogator.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/SymbolicPropogator.java@@ -40,7 +40,7 @@ import ghidra.util.exception.*;import ghidra.util.task.TaskMonitor;public class SymbolicPropogator {- private static int LRU_SIZE = 1024;+ private static int LRU_SIZE = 4096;// QUESTIONS// 1. How are "register-relative" varnodes distinguished based upon target space ? Not sure how we handle wrapping/truncation concerns.// 1) The offset is the only thing that could be used as a reference.@@ -63,7 +63,6 @@ public class SymbolicPropogator {protected boolean canceled = false;protected boolean readExecutableAddress;protected VarnodeContext context;- protected boolean conflict;protected boolean hitCodeFlow = false; // no branching so far@@ -490,12 +489,13 @@ public class SymbolicPropogator {break;}+ Address minInstrAddress = instr.getMinAddress();maxAddr = instr.getMaxAddress();// if this instruction has a delay slot, adjust maxAddr accordingly//if (instr.getPrototype().hasDelaySlots()) {- maxAddr = instr.getMinAddress().add(instr.getDefaultFallThroughOffset() - 1);+ maxAddr = minInstrAddress.add(instr.getDefaultFallThroughOffset() - 1);}vContext.setCurrentInstruction(instr);@@ -512,11 +512,10 @@ public class SymbolicPropogator {//// apply the pcode effects//- conflict = false;Address retAddr = applyPcode(vContext, instr, monitor);// add this instruction to processed body set- body.addRange(instr.getMinAddress(), maxAddr);+ body.addRange(minInstrAddress, maxAddr);/* Allow evaluateContext routine to change override the flowtype of an instruction.* Jumps Changed to calls will now continue processing.@@ -558,8 +557,8 @@ public class SymbolicPropogator {}if (!instrFlow.isCall()) {for (Address flow : flows) {- contextStack.push(new SavedFlowState(vContext,- instr.getMinAddress(), flow, continueAfterHittingFlow));+ contextStack.push(new SavedFlowState(vContext, minInstrAddress,+ flow, continueAfterHittingFlow));}}else if (flows.length > 1) {@@ -568,9 +567,8 @@ public class SymbolicPropogator {for (Reference flowRef : flowRefs) {RefType referenceType = flowRef.getReferenceType();if (referenceType.isComputed() && referenceType.isJump()) {- contextStack.push(- new SavedFlowState(vContext, instr.getMinAddress(),- flowRef.getToAddress(), continueAfterHittingFlow));+ contextStack.push(new SavedFlowState(vContext, minInstrAddress,+ flowRef.getToAddress(), continueAfterHittingFlow));}}}@@ -590,13 +588,13 @@ public class SymbolicPropogator {vContext.mergeToFutureFlowState(maxAddr, inlineCall);vContext.flowEnd(maxAddr);flowConstants(maxAddr, inlineCall, func.getBody(), eval, vContext, monitor);- vContext.mergeToFutureFlowState(instr.getMinAddress(), maxAddr);+ vContext.mergeToFutureFlowState(minInstrAddress, maxAddr);//// TODO: WARNING, might not start the flow correctly if there is no future flow here.// FLOW end will probably work correctly, but....//- vContext.flowStart(instr.getMinAddress(), maxAddr);+ vContext.flowStart(minInstrAddress, maxAddr);}}@@ -605,24 +603,29 @@ public class SymbolicPropogator {Address fallThru = instr.getFallThrough();nextAddr = null;if (retAddr != null) {- contextStack.push(new SavedFlowState(vContext, instr.getMinAddress(), retAddr,+ contextStack.push(new SavedFlowState(vContext, minInstrAddress, retAddr,continueAfterHittingFlow));fallThru = null;}if (fallThru != null) {if (doFallThruLast) {+ vContext.mergeToFutureFlowState(minInstrAddress, fallThru);+// put it lowest on the stack to do later!- contextStack.push(new SavedFlowState(vContext, instr.getMinAddress(),- fallThru, !callCouldCauseBadStackDepth));+ contextStack.push(new SavedFlowState(vContext, minInstrAddress, fallThru,+ !callCouldCauseBadStackDepth));}else if (fallThru.compareTo(maxAddr) < 0) {// this isn't a normal fallthru, must break it up// don't continue flowing if something else is hit, this is an odd case+ vContext.mergeToFutureFlowState(minInstrAddress, fallThru);+contextStack.push(- new SavedFlowState(vContext, instr.getMinAddress(), fallThru, false));+ new SavedFlowState(vContext, minInstrAddress, fallThru, false));}else {+ // no need to store future flow state, will continue on the fall-thru flownextAddr = fallThru;fallThru = null;}@@ -857,8 +860,8 @@ public class SymbolicPropogator {for (Reference flowRef : flowRefs) {RefType referenceType = flowRef.getReferenceType();if (referenceType.isComputed() && referenceType.isJump()) {- conflict |= vContext.mergeToFutureFlowState(- flowRef.getFromAddress(), flowRef.getToAddress());+ vContext.mergeToFutureFlowState(flowRef.getFromAddress(),+ flowRef.getToAddress());}}@@ -923,8 +926,7 @@ public class SymbolicPropogator {if (target != null) {if (target.isMemoryAddress()) {vContext.propogateResults(false);- conflict |=- vContext.mergeToFutureFlowState(minInstrAddress, target);+ vContext.mergeToFutureFlowState(minInstrAddress, target);}func = prog.getFunctionManager().getFunctionAt(target);if (func == null && ptype == PcodeOp.CALLIND) {@@ -996,8 +998,7 @@ public class SymbolicPropogator {instruction.getAddress());}vContext.propogateResults(false);- conflict |=- vContext.mergeToFutureFlowState(minInstrAddress, in[0].getAddress());+ vContext.mergeToFutureFlowState(minInstrAddress, in[0].getAddress());pcodeIndex = ops.length; // break out of the processingbreak;@@ -1008,15 +1009,14 @@ public class SymbolicPropogator {int sequenceOffset = (int) in[0].getOffset();if ((pcodeIndex + sequenceOffset) >= ops.length) {vContext.propogateResults(false);- conflict |= vContext.mergeToFutureFlowState(minInstrAddress,+ vContext.mergeToFutureFlowState(minInstrAddress,instruction.getFallThrough());}}else if (in[0].isAddress()) {vt = in[0];vContext.propogateResults(false);- conflict |= vContext.mergeToFutureFlowState(minInstrAddress,- in[0].getAddress());+ vContext.mergeToFutureFlowState(minInstrAddress, in[0].getAddress());}Varnode condition = null;@@ -1056,7 +1056,7 @@ public class SymbolicPropogator {if (fallThru != null) {// we don't know what will happen from here on, but anything before should in theory propagatevContext.propogateResults(true);- conflict |= vContext.mergeToFutureFlowState(minInstrAddress,+ vContext.mergeToFutureFlowState(minInstrAddress,instruction.getFallThrough());}// everything that is in the cache from here on should be cleared@@ -1432,11 +1432,6 @@ public class SymbolicPropogator {// assume the future flow will have flowed the correct info.nextAddr = fallthru;}- else {- if (fallthru != null) {- conflict |= vContext.mergeToFutureFlowState(minInstrAddress, fallthru);- }- }return nextAddr;}