mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
Corrected EquatePluginTest1 failure and ConvertCommand
This commit is contained in:
@@ -95,7 +95,8 @@ public class ConvertCommand extends BackgroundCommand {
|
|||||||
DataType dt = data.getBaseDataType();
|
DataType dt = data.getBaseDataType();
|
||||||
Settings settings = data;
|
Settings settings = data;
|
||||||
Settings defaultSettings = dt.getDefaultSettings();
|
Settings defaultSettings = dt.getDefaultSettings();
|
||||||
if (Scalar.class.equals(data.getValueClass()) || !(dt instanceof AbstractIntegerDataType)) {
|
if (!(Scalar.class.equals(data.getValueClass())) ||
|
||||||
|
!(dt instanceof AbstractIntegerDataType)) {
|
||||||
msg = "Unsupported data type for convert: " + data.getDataType().getDisplayName();
|
msg = "Unsupported data type for convert: " + data.getDataType().getDisplayName();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -433,22 +433,20 @@ public abstract class AbstractEquatePluginTest extends AbstractProgramBasedTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void createSignedData(Address addr) throws Exception {
|
protected void createSignedData(Address addr) throws Exception {
|
||||||
int id = program.startTransaction("Test - Create Signed Data");
|
createData(addr, SignedWordDataType.dataType);
|
||||||
|
|
||||||
SignedWordDataType dt = new SignedWordDataType(program.getDataTypeManager());
|
|
||||||
int length = dt.getLength();
|
|
||||||
listing.clearCodeUnits(addr, addr.add(length), true);
|
|
||||||
listing.createData(addr, dt);
|
|
||||||
|
|
||||||
program.endTransaction(id, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createUnsignedData(Address addr) throws Exception {
|
protected void createUnsignedData(Address addr) throws Exception {
|
||||||
int id = program.startTransaction("Test - Create Unsigned Data");
|
createData(addr, WordDataType.dataType);
|
||||||
|
}
|
||||||
|
|
||||||
WordDataType dt = new WordDataType(program.getDataTypeManager());
|
protected void createData(Address addr, DataType dt) throws Exception {
|
||||||
|
int id = program.startTransaction("Test - Create Data");
|
||||||
|
|
||||||
|
dt = dt.clone(program.getDataTypeManager());
|
||||||
int length = dt.getLength();
|
int length = dt.getLength();
|
||||||
listing.clearCodeUnits(addr, addr.add(length), true);
|
assertTrue("", length > 0);
|
||||||
|
listing.clearCodeUnits(addr, addr.add(length - 1), true);
|
||||||
program.getListing().createData(addr, dt);
|
program.getListing().createData(addr, dt);
|
||||||
|
|
||||||
program.endTransaction(id, true);
|
program.endTransaction(id, true);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ import ghidra.app.util.viewer.field.ListingTextField;
|
|||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.address.AddressSet;
|
import ghidra.program.model.address.AddressSet;
|
||||||
import ghidra.program.model.data.*;
|
import ghidra.program.model.data.*;
|
||||||
|
import ghidra.program.model.data.Enum;
|
||||||
import ghidra.program.model.listing.Data;
|
import ghidra.program.model.listing.Data;
|
||||||
import ghidra.program.model.listing.Instruction;
|
import ghidra.program.model.listing.Instruction;
|
||||||
import ghidra.program.model.scalar.Scalar;
|
import ghidra.program.model.scalar.Scalar;
|
||||||
@@ -821,6 +822,35 @@ public class EquatePlugin1Test extends AbstractEquatePluginTest {
|
|||||||
assertTrue(data.getDataType() instanceof SignedWordDataType);
|
assertTrue(data.getDataType() instanceof SignedWordDataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoConvertOnData() throws Exception {
|
||||||
|
Address addr = addr(0x01003384);
|
||||||
|
|
||||||
|
// action should not apply to BooleanDataType which produces Scalar value
|
||||||
|
createData(addr, BooleanDataType.dataType);
|
||||||
|
Data data = program.getListing().getDataAt(addr);
|
||||||
|
assertTrue(data.getDataType() instanceof BooleanDataType);
|
||||||
|
|
||||||
|
goTo(addr);
|
||||||
|
DockingActionIf action = getAction(equatePlugin, "Convert To Signed Decimal");
|
||||||
|
|
||||||
|
assertFalse(action.isAddToPopup(getListingContext()));
|
||||||
|
assertFalse(action.isEnabledForContext(getListingContext()));
|
||||||
|
|
||||||
|
// action should not apply to Enum which produces Scalar value
|
||||||
|
EnumDataType myEnum = new EnumDataType("Joe", 2);
|
||||||
|
myEnum.add("ValFFFF", -1);
|
||||||
|
|
||||||
|
createData(addr, myEnum);
|
||||||
|
data = program.getListing().getDataAt(addr);
|
||||||
|
assertTrue(data.getDataType() instanceof Enum);
|
||||||
|
|
||||||
|
goTo(addr);
|
||||||
|
|
||||||
|
assertFalse(action.isAddToPopup(getListingContext()));
|
||||||
|
assertFalse(action.isEnabledForContext(getListingContext()));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConvertPickSameDatatype() throws Exception {
|
public void testConvertPickSameDatatype() throws Exception {
|
||||||
Address addr = addr(0x01003384);
|
Address addr = addr(0x01003384);
|
||||||
|
|||||||
Reference in New Issue
Block a user