Ghidra is a software reverse engineering (SRE) framework
GP-1687_emteere fix for CSEL AARCH64 instruction causing switches not to recover
emteere961a9e7b75be
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 a00a77a08b..0bdef3a230 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@@ -1053,7 +1053,7 @@ public class SymbolicPropogator {// if internal flow joins back together, just skip over effect// Warning this is arbitrary choice of one branch over the other....!!!// look at pcode up to destination, if all non flow or internal, just skip- int sequenceOffset = (int) in[0].getOffset();+ int sequenceOffset = pcodeIndex + (int) in[0].getOffset();int i = pcodeIndex + 1;for (; i < sequenceOffset; i++) {if (isBranch(ops[i])) {@@ -1061,12 +1061,6 @@ public class SymbolicPropogator {}}if (i == sequenceOffset) {- if (fallThru != null) {- // we don't know what will happen from here on, but anything before should in theory propagate- vContext.propogateResults(true);- vContext.mergeToFutureFlowState(minInstrAddress,- instruction.getFallThrough());- }// everything that is in the cache from here on should be clearedmustClearAllUntil_PcodeIndex = sequenceOffset;break;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/VarnodeContext.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/VarnodeContext.javaindex ba2b39af4f..f918feadc9 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/VarnodeContext.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/VarnodeContext.java@@ -716,6 +716,9 @@ public class VarnodeContext implements ProcessorContext {result = null;}if (out.isUnique()) {+ if (mustClear) {+ result = null;+ }tempUniqueVals.put(out, result);}else {diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.javaindex 8f7e393369..6ba434894a 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/analysis/DecompilerSwitchAnalyzer.java@@ -23,13 +23,13 @@ import generic.concurrent.*;import ghidra.app.cmd.function.CreateFunctionCmd;import ghidra.app.cmd.function.DecompilerSwitchAnalysisCmd;import ghidra.app.decompiler.DecompileResults;-import ghidra.app.decompiler.parallel.*;+import ghidra.app.decompiler.parallel.DecompilerCallback;+import ghidra.app.decompiler.parallel.ParallelDecompiler;import ghidra.app.services.*;import ghidra.app.util.importer.MessageLog;import ghidra.framework.options.Options;import ghidra.program.model.address.*;-import ghidra.program.model.block.BasicBlockModel;-import ghidra.program.model.block.CodeBlock;+import ghidra.program.model.block.*;import ghidra.program.model.lang.Register;import ghidra.program.model.listing.*;import ghidra.program.model.symbol.*;@@ -135,8 +135,8 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer {for (Function function : functions) {funcSet.add(function.getBody());}- AutoAnalysisManager.getAnalysisManager(program).scheduleOneTimeAnalysis(- new DecompilerSwitchAnalyzer(), funcSet);+ AutoAnalysisManager.getAnalysisManager(program)+ .scheduleOneTimeAnalysis(new DecompilerSwitchAnalyzer(), funcSet);Msg.info(this, "hit non-returning function, restarting decompiler switch analyzer later");}@@ -320,9 +320,9 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer {*/private boolean handleSimpleBlock(Address location, TaskMonitor monitor)throws CancelledException {- BasicBlockModel basicBlockModel = new BasicBlockModel(program);+ SimpleBlockModel blockModel = new SimpleBlockModel(program);- return resolveComputableFlow(location, monitor, basicBlockModel);+ return resolveComputableFlow(location, monitor, blockModel);}/**@@ -332,14 +332,13 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer {* @return true if the flow could be easily resolved.*/private boolean resolveComputableFlow(Address location, TaskMonitor monitor,- BasicBlockModel basicBlockModel) throws CancelledException {+ CodeBlockModel blockModel) throws CancelledException {// get the basic block//// NOTE: Assumption, the decompiler won't get the switch if there is no guard- final CodeBlock jumpBlockAt =- basicBlockModel.getFirstCodeBlockContaining(location, monitor);+ final CodeBlock jumpBlockAt = blockModel.getFirstCodeBlockContaining(location, monitor);// If the jump target can has a computable target with only the instructions in the basic block it is found in// then it isn't a switch statment//@@ -371,8 +370,8 @@ public class DecompilerSwitchAnalyzer extends AbstractAnalyzer {BigInteger value = context.getValue(isaModeSwitchRegister, false);if (value != null && program.getListing().getInstructionAt(addr) == null) {try {- program.getProgramContext().setValue(isaModeRegister, addr, addr,- value);+ program.getProgramContext()+ .setValue(isaModeRegister, addr, addr, value);}catch (ContextChangeException e) {// ignore