mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-01-10 06:27:59 -05:00
GP-3412 make convert action work with operands that have subpieces
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user