From 0b8d60704045b54a3a50c4f5795d2e04d8909b73 Mon Sep 17 00:00:00 2001 From: sakiodre <136492105+sakiodre@users.noreply.github.com> Date: Sat, 24 Jun 2023 13:32:55 +0700 Subject: [PATCH] Add no high variable error handling while unwinding stack in SymPcodeExecutor --- .../plugin/core/debug/stack/StackUnwindWarning.java | 12 ++++++++++++ .../plugin/core/debug/stack/SymPcodeExecutor.java | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/StackUnwindWarning.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/StackUnwindWarning.java index d598483917..a0c2eba094 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/StackUnwindWarning.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/StackUnwindWarning.java @@ -25,6 +25,7 @@ import ghidra.program.model.data.DataType; import ghidra.program.model.listing.Function; import ghidra.program.model.pcode.PcodeOp; import ghidra.program.model.pcode.PcodeOpAST; +import ghidra.program.model.pcode.VarnodeAST; /** * A warning issued while unwinding a stack @@ -186,6 +187,17 @@ public interface StackUnwindWarning { } } + /** + * While analyzing an indirect call, couldn't get the function signature because its input doesn't have a high variable. + */ + public record NoHighVariableFromTargetPointerTypeUnwindWarning(VarnodeAST vn) + implements StackUnwindWarning { + @Override + public String getMessage() { + return "Input of indirect call target has no high variable: " + vn; + } + } + /** * While analyzing an indirect call, the signature could not be derived from call-site context. */ diff --git a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/SymPcodeExecutor.java b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/SymPcodeExecutor.java index 9b3f916907..79e7e3d910 100644 --- a/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/SymPcodeExecutor.java +++ b/Ghidra/Debug/Debugger/src/main/java/ghidra/app/plugin/core/debug/stack/SymPcodeExecutor.java @@ -216,7 +216,14 @@ class SymPcodeExecutor extends PcodeExecutor { */ protected FunctionSignature getSignatureFromTargetPointerType(PcodeOpAST op) { VarnodeAST target = (VarnodeAST) op.getInput(0); - DataType dataType = target.getHigh().getDataType(); + HighVariable high = target.getHigh(); + + if (high == null) { + warnings.add(new NoHighVariableFromTargetPointerTypeUnwindWarning(target)); + return null; + } + + DataType dataType = high.getDataType(); if (!(dataType instanceof Pointer ptrType)) { warnings.add(new UnexpectedTargetTypeStackUnwindWarning(dataType)); return null;