Added null check for Decompiler action context

This commit is contained in:
dragonmacher
2026-02-20 12:51:16 -05:00
parent aeea8dc50d
commit 198f8fb558
4 changed files with 18 additions and 49 deletions

View File

@@ -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;

View File

@@ -45,6 +45,10 @@ public class RemoveEquateAction extends AbstractDecompilerAction {
@Override
protected 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/switch
PcodeOp switchOp = ((ClangCaseToken) tokenAtCursor).getSwitchOp();

View File

@@ -63,6 +63,9 @@ public class RetypeReturnAction extends AbstractDecompilerAction {
}
ClangToken tokenAtCursor = context.getTokenAtCursor();
if (tokenAtCursor == null) {
return false;
}
return (tokenAtCursor.Parent() instanceof ClangReturnType);
}

View File

@@ -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);