Ghidra is a software reverse engineering (SRE) framework
Added null check for Decompiler action context
dragonmacher198f8fb5585f
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.javaindex c2efa89104..8769392fc8 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/ConvertConstantAction.java@@ -75,8 +75,9 @@ public abstract class ConvertConstantAction extends AbstractDecompilerAction {public boolean isMatch(long value) {value = value & mask;for (long match : values) {- if (match == value)+ if (match == value) {return true;+ }}return false;}@@ -130,7 +131,13 @@ public abstract class ConvertConstantAction extends AbstractDecompilerAction {if (convDisplay == null) {return false;}- if (convDisplay.equals(context.getTokenAtCursor().getText())) {++ ClangToken token = context.getTokenAtCursor();+ if (token == null) {+ return false;+ }++ if (convDisplay.equals(token.getText())) {return false;}String menuString = getStandardLengthString(getMenuPrefix()) + convDisplay;diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveEquateAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveEquateAction.javaindex 8191c0e875..1d225cbeb3 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveEquateAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RemoveEquateAction.java@@ -45,6 +45,10 @@ public class RemoveEquateAction extends AbstractDecompilerAction {@Overrideprotected boolean isEnabledForDecompilerContext(DecompilerActionContext context) {ClangToken tokenAtCursor = context.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return false;+ }+if (tokenAtCursor instanceof ClangCaseToken) {// Check for a conversion applied to case labels on a specific jumptable/switchPcodeOp switchOp = ((ClangCaseToken) tokenAtCursor).getSwitchOp();diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeReturnAction.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeReturnAction.javaindex 21d45104be..1572355d32 100644--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeReturnAction.java+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/plugin/core/decompile/actions/RetypeReturnAction.java@@ -63,6 +63,9 @@ public class RetypeReturnAction extends AbstractDecompilerAction {}ClangToken tokenAtCursor = context.getTokenAtCursor();+ if (tokenAtCursor == null) {+ return false;+ }return (tokenAtCursor.Parent() instanceof ClangReturnType);}diff --git a/Ghidra/Features/DecompilerDependent/src/main/java/ghidra/app/plugin/core/decompiler/taint/actions/TaintAbstractDecompilerAction.java b/Ghidra/Features/DecompilerDependent/src/main/java/ghidra/app/plugin/core/decompiler/taint/actions/TaintAbstractDecompilerAction.javaindex 0ecbc85d26..05f385a981 100644--- a/Ghidra/Features/DecompilerDependent/src/main/java/ghidra/app/plugin/core/decompiler/taint/actions/TaintAbstractDecompilerAction.java+++ b/Ghidra/Features/DecompilerDependent/src/main/java/ghidra/app/plugin/core/decompiler/taint/actions/TaintAbstractDecompilerAction.java@@ -18,18 +18,15 @@ package ghidra.app.plugin.core.decompiler.taint.actions;import docking.ActionContext;import docking.action.DockingAction;import docking.action.KeyBindingType;-import ghidra.app.decompiler.*;-import ghidra.app.decompiler.component.DecompilerUtils;+import ghidra.app.decompiler.ClangFieldToken;+import ghidra.app.decompiler.ClangToken;import ghidra.app.plugin.core.decompile.DecompilePlugin;import ghidra.app.plugin.core.decompile.DecompilerActionContext;import ghidra.app.util.datatype.DataTypeSelectionDialog;import ghidra.framework.plugintool.PluginTool;-import ghidra.program.model.address.Address;import ghidra.program.model.data.*;import ghidra.program.model.listing.*;import ghidra.program.model.pcode.*;-import ghidra.program.model.symbol.*;-import ghidra.util.UndefinedFunction;import ghidra.util.data.DataTypeParser.AllowedDataTypes;/**@@ -139,48 +136,6 @@ public abstract class TaintAbstractDecompilerAction extends DockingAction {decompilerActionPerformed(decompilerContext);}- protected Symbol getSymbol(DecompilerActionContext context) {-- // prefer the decompiler's function reference over the program location's address- Function function = getFunction(context);- if (function != null && !(function instanceof UndefinedFunction)) {- return function.getSymbol();- }-- Program program = context.getProgram();- SymbolTable symbolTable = program.getSymbolTable();- Address address = context.getAddress();- if (address == null) {- return null;- }- return symbolTable.getPrimarySymbol(address);- }-- /**- * Get the function corresponding to the specified decompiler context.- *- * @param context decompiler action context- * @return the function associated with the current context token or null if none identified.- */- protected Function getFunction(DecompilerActionContext context) {- ClangToken token = context.getTokenAtCursor();-- Function f = null;- if (token instanceof ClangFuncNameToken) {- f = DecompilerUtils.getFunction(context.getProgram(), (ClangFuncNameToken) token);- }- else {- HighSymbol highSymbol = token.getHighSymbol(context.getHighFunction());- if (highSymbol instanceof HighFunctionShellSymbol) {- f = (Function) highSymbol.getSymbol().getObject();- }- }- while (f != null && f.isThunk() && f.getSymbol().getSource() == SourceType.DEFAULT) {- f = f.getThunkedFunction(false);- }- return f;- }-protected abstract boolean isEnabledForDecompilerContext(DecompilerActionContext context);protected abstract void decompilerActionPerformed(DecompilerActionContext context);