Ghidra is a software reverse engineering (SRE) framework
GP-3412 make convert action work with operands that have subpieces
dev747368a080cc563c81
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/ConvertCommand.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/ConvertCommand.javaindex 27f9af7b06..617fab6588 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/ConvertCommand.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/ConvertCommand.java@@ -81,7 +81,8 @@ public class ConvertCommand extends BackgroundCommand {Instruction instruction = (Instruction) context.getCodeUnit();int opIndex = action.plugin.getOperandIndex(context);- msg = applyEquate(instruction, opIndex);+ int subOpIndex = action.plugin.getSubOperandIndex(context);+ msg = applyEquate(instruction, opIndex, subOpIndex);}catch (Exception e) {msg = "Exception applying the Convert: " + e.getMessage();@@ -142,7 +143,7 @@ public class ConvertCommand extends BackgroundCommand {String errorMessage = null;for (Instruction instruction : it) {for (int i = 0; i < instruction.getNumOperands(); i++) {- String m = applyEquate(instruction, i);+ String m = applyEquate(instruction, i, 0);if (errorMessage == null && m != null) {errorMessage = m;}@@ -155,12 +156,12 @@ public class ConvertCommand extends BackgroundCommand {* Create a new equate. If already created with a different value, then we can't do anything.* If equate name is null, i.e. selection is not letter or digit, then do nothing*/- private String applyEquate(Instruction instruction, int opIndex) {+ private String applyEquate(Instruction instruction, int opIndex, int subOpIndex) {if (instruction == null || opIndex == -1) {return null;}- Scalar scalar = grabMatchingScalar(instruction, opIndex);+ Scalar scalar = grabMatchingScalar(instruction, opIndex, subOpIndex);if (scalar == null) {return null;}@@ -210,12 +211,13 @@ public class ConvertCommand extends BackgroundCommand {* Gets a scalar that matches the value of the scalar at the cursor location.* @param instruction The instruction to search* @param opIndex The operand index to look at+ * @param subOpIndex the sub operand index* @return A scalar that matches the value of the scalar at the cursor location, or null if no* such scalar can be found.*/- private Scalar grabMatchingScalar(Instruction instruction, int opIndex) {+ private Scalar grabMatchingScalar(Instruction instruction, int opIndex, int subOpIndex) {Scalar scalarAtCursor = action.plugin.getScalar(context);- Scalar scalar = instruction.getScalar(opIndex);+ Scalar scalar = action.plugin.getScalar(instruction, opIndex, subOpIndex);if (scalarAtCursor.equals(scalar)) {return scalar;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.javaindex 41646bbe62..22451a8552 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/equate/EquatePlugin.java@@ -554,7 +554,7 @@ public class EquatePlugin extends Plugin {* @param subOpIndex sub-operand index* @return scalar value or null*/- private Scalar getScalar(CodeUnit cu, int opIndex, int subOpIndex) {+ Scalar getScalar(CodeUnit cu, int opIndex, int subOpIndex) {if (cu == null) {return null;}