mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-3227 - Removed transactions from the equate manager
This commit is contained in:
parent
0ec5313bac
commit
665a83d6c0
4 changed files with 115 additions and 291 deletions
|
@ -37,8 +37,7 @@ public class CreateEnumEquateCommand extends BackgroundCommand {
|
||||||
* @param program The program to use
|
* @param program The program to use
|
||||||
* @param addresses The addresses to apply an enum to
|
* @param addresses The addresses to apply an enum to
|
||||||
* @param enoom The enum to apply equates with
|
* @param enoom The enum to apply equates with
|
||||||
* @param shouldIncludeTypes True if the equate name should include the enum name.
|
* @param shouldDoOnSubOps true if the enum should also be applied to the sub-operands.
|
||||||
* @param shouldDoOnSubOps True if the enum should also be applied to the sub-operands.
|
|
||||||
*/
|
*/
|
||||||
public CreateEnumEquateCommand(Program program, AddressSetView addresses, Enum enoom,
|
public CreateEnumEquateCommand(Program program, AddressSetView addresses, Enum enoom,
|
||||||
boolean shouldDoOnSubOps) {
|
boolean shouldDoOnSubOps) {
|
||||||
|
@ -65,5 +64,4 @@ public class CreateEnumEquateCommand extends BackgroundCommand {
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Create Enum Equate Command";
|
return "Create Enum Equate Command";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import ghidra.app.plugin.PluginCategoryNames;
|
||||||
import ghidra.app.util.bean.SetEquateDialog;
|
import ghidra.app.util.bean.SetEquateDialog;
|
||||||
import ghidra.app.util.bean.SetEquateDialog.SelectionType;
|
import ghidra.app.util.bean.SetEquateDialog.SelectionType;
|
||||||
import ghidra.app.util.datatype.ApplyEnumDialog;
|
import ghidra.app.util.datatype.ApplyEnumDialog;
|
||||||
import ghidra.app.util.datatype.DataTypeSelectionDialog;
|
|
||||||
import ghidra.framework.cmd.BackgroundCommand;
|
import ghidra.framework.cmd.BackgroundCommand;
|
||||||
import ghidra.framework.cmd.CompoundBackgroundCommand;
|
import ghidra.framework.cmd.CompoundBackgroundCommand;
|
||||||
import ghidra.framework.plugintool.*;
|
import ghidra.framework.plugintool.*;
|
||||||
|
@ -74,23 +73,14 @@ public class EquatePlugin extends Plugin {
|
||||||
private SetEquateDialog setEquateDialog;
|
private SetEquateDialog setEquateDialog;
|
||||||
private ApplyEnumDialog applyEnumDialog;
|
private ApplyEnumDialog applyEnumDialog;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*
|
|
||||||
* @param tool
|
|
||||||
*/
|
|
||||||
public EquatePlugin(PluginTool tool) {
|
public EquatePlugin(PluginTool tool) {
|
||||||
super(tool);
|
super(tool);
|
||||||
createActions();
|
createActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Returns the GUI for the {@link SetEquateDialog}. Note that this function will close
|
* Returns the GUI for the {@link SetEquateDialog}. Note that this function will close
|
||||||
* any instance of the dialog that is currently open and construct a new one.
|
* any instance of the dialog that is currently open and construct a new one.
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @param scalar
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private SetEquateDialog createEquateDialog(ListingActionContext context, Scalar scalar) {
|
private SetEquateDialog createEquateDialog(ListingActionContext context, Scalar scalar) {
|
||||||
if (setEquateDialog != null) {
|
if (setEquateDialog != null) {
|
||||||
|
@ -105,11 +95,9 @@ public class EquatePlugin extends Plugin {
|
||||||
return setEquateDialog;
|
return setEquateDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Returns the GUI for the {@link DataTypeSelectionDialog}. Note that this function will
|
* Returns the GUI for the {@link DataTypeSelectionDialog}. Note that this function will
|
||||||
* close any instance of the dialog that is currently open and construct a new one.
|
* close any instance of the dialog that is currently open and construct a new one.
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private ApplyEnumDialog applyEnumDialog(ListingActionContext context) {
|
private ApplyEnumDialog applyEnumDialog(ListingActionContext context) {
|
||||||
DataTypeManager dtm = context.getProgram().getDataTypeManager();
|
DataTypeManager dtm = context.getProgram().getDataTypeManager();
|
||||||
|
@ -122,11 +110,6 @@ public class EquatePlugin extends Plugin {
|
||||||
return applyEnumDialog;
|
return applyEnumDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Destroys the {@link SetEquateDialog}.
|
|
||||||
*
|
|
||||||
* @param dialog
|
|
||||||
*/
|
|
||||||
private void dispose(SetEquateDialog dialog) {
|
private void dispose(SetEquateDialog dialog) {
|
||||||
if (setEquateDialog == dialog) {
|
if (setEquateDialog == dialog) {
|
||||||
setEquateDialog.dispose();
|
setEquateDialog.dispose();
|
||||||
|
@ -146,7 +129,7 @@ public class EquatePlugin extends Plugin {
|
||||||
* array or composite (CreateEquateCmd does not currently support such data cases)</li>
|
* array or composite (CreateEquateCmd does not currently support such data cases)</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* Currently markup of equates is not supported within composite or array data
|
* Currently markup of equates is not supported within composite or array data
|
||||||
* @param context
|
* @param context the action context
|
||||||
* @return true if current location satisfies the above constraints
|
* @return true if current location satisfies the above constraints
|
||||||
*/
|
*/
|
||||||
protected boolean isEquatePermitted(ListingActionContext context) {
|
protected boolean isEquatePermitted(ListingActionContext context) {
|
||||||
|
@ -182,7 +165,7 @@ public class EquatePlugin extends Plugin {
|
||||||
* ultimately create the background tasks that will create the proper equate(s) for
|
* ultimately create the background tasks that will create the proper equate(s) for
|
||||||
* the selected addresses.
|
* the selected addresses.
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context the action context
|
||||||
*/
|
*/
|
||||||
private void setEquate(ListingActionContext context) {
|
private void setEquate(ListingActionContext context) {
|
||||||
|
|
||||||
|
@ -252,7 +235,7 @@ public class EquatePlugin extends Plugin {
|
||||||
/**
|
/**
|
||||||
* Called in response to the user selecting the Apply Enum action from the popup menu. This
|
* Called in response to the user selecting the Apply Enum action from the popup menu. This
|
||||||
* action will apply enum values to scalars in a selection.
|
* action will apply enum values to scalars in a selection.
|
||||||
* @param context
|
* @param context the action context
|
||||||
*/
|
*/
|
||||||
private void applyEnum(ListingActionContext context) {
|
private void applyEnum(ListingActionContext context) {
|
||||||
applyEnumDialog = applyEnumDialog(context);
|
applyEnumDialog = applyEnumDialog(context);
|
||||||
|
@ -281,7 +264,7 @@ public class EquatePlugin extends Plugin {
|
||||||
/**
|
/**
|
||||||
* Called in response to the user activating rename action from the context menu.
|
* Called in response to the user activating rename action from the context menu.
|
||||||
*
|
*
|
||||||
* @param context
|
* @param context the action context
|
||||||
*/
|
*/
|
||||||
private void renameEquate(ListingActionContext context) {
|
private void renameEquate(ListingActionContext context) {
|
||||||
|
|
||||||
|
@ -348,12 +331,6 @@ public class EquatePlugin extends Plugin {
|
||||||
dispose(setEquateDialog);
|
dispose(setEquateDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the equate for the given context listing.
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private Equate getEquate(ListingActionContext context) {
|
private Equate getEquate(ListingActionContext context) {
|
||||||
EquateTable equateTable = context.getProgram().getEquateTable();
|
EquateTable equateTable = context.getProgram().getEquateTable();
|
||||||
Scalar s = getScalar(context);
|
Scalar s = getScalar(context);
|
||||||
|
@ -363,15 +340,6 @@ public class EquatePlugin extends Plugin {
|
||||||
return equateTable.getEquate(context.getAddress(), getOperandIndex(context), s.getValue());
|
return equateTable.getEquate(context.getAddress(), getOperandIndex(context), s.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Renames all equates matching the given old equate name, within the address space identified
|
|
||||||
* by the iterator.
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @param oldEquate
|
|
||||||
* @param newEquateName
|
|
||||||
* @param iter
|
|
||||||
*/
|
|
||||||
private void renameEquate(ListingActionContext context, Equate oldEquate, String newEquateName,
|
private void renameEquate(ListingActionContext context, Equate oldEquate, String newEquateName,
|
||||||
CodeUnitIterator iter) {
|
CodeUnitIterator iter) {
|
||||||
|
|
||||||
|
@ -476,14 +444,6 @@ public class EquatePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the list of operands for the given {@link Instruction} that match the given
|
|
||||||
* {@link Equate}.
|
|
||||||
*
|
|
||||||
* @param instruction
|
|
||||||
* @param equate
|
|
||||||
* @return an array of matches, in the format: [operand][operand-obj]
|
|
||||||
*/
|
|
||||||
private List<Integer> getInstructionMatches(Program program, Instruction instruction,
|
private List<Integer> getInstructionMatches(Program program, Instruction instruction,
|
||||||
Equate equate) {
|
Equate equate) {
|
||||||
|
|
||||||
|
@ -521,15 +481,6 @@ public class EquatePlugin extends Plugin {
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the given {@link Data} object is a scalar value that has an equate
|
|
||||||
* that matches the one passed-in.
|
|
||||||
*
|
|
||||||
* @param data
|
|
||||||
* @param context
|
|
||||||
* @param equate
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private boolean isDataMatch(Data data, ListingActionContext context, Equate equate) {
|
private boolean isDataMatch(Data data, ListingActionContext context, Equate equate) {
|
||||||
|
|
||||||
if (!data.isDefined()) {
|
if (!data.isDefined()) {
|
||||||
|
@ -560,12 +511,10 @@ public class EquatePlugin extends Plugin {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* Removes equates within the selected region, or a single equate if there's
|
* Removes equates within the selected region, or a single equate if there's
|
||||||
* no selection. The user will be prompted for confirmation before
|
* no selection. The user will be prompted for confirmation before
|
||||||
* removing multiple equates in a selection.
|
* removing multiple equates in a selection.
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
*/
|
*/
|
||||||
private void removeSelectedEquates(ListingActionContext context) {
|
private void removeSelectedEquates(ListingActionContext context) {
|
||||||
|
|
||||||
|
@ -606,7 +555,8 @@ public class EquatePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the instruction at the location provided by the ProgramLocationProvider
|
* Get the instruction at the location provided by the context
|
||||||
|
* @param context the action context
|
||||||
* @return code unit containing current location if found (component data unsupported)
|
* @return code unit containing current location if found (component data unsupported)
|
||||||
*/
|
*/
|
||||||
CodeUnit getCodeUnit(ListingActionContext context) {
|
CodeUnit getCodeUnit(ListingActionContext context) {
|
||||||
|
@ -619,7 +569,7 @@ public class EquatePlugin extends Plugin {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the operand index at the location
|
* Get the operand index at the location
|
||||||
*
|
* @param context the action context
|
||||||
* @return 0-3 for a good operand location, -1 otherwise
|
* @return 0-3 for a good operand location, -1 otherwise
|
||||||
*/
|
*/
|
||||||
int getOperandIndex(ListingActionContext context) {
|
int getOperandIndex(ListingActionContext context) {
|
||||||
|
@ -630,11 +580,6 @@ public class EquatePlugin extends Plugin {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param context
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
int getSubOperandIndex(ListingActionContext context) {
|
int getSubOperandIndex(ListingActionContext context) {
|
||||||
ProgramLocation location = context.getLocation();
|
ProgramLocation location = context.getLocation();
|
||||||
if (location instanceof OperandFieldLocation) {
|
if (location instanceof OperandFieldLocation) {
|
||||||
|
@ -649,10 +594,6 @@ public class EquatePlugin extends Plugin {
|
||||||
return scalar;
|
return scalar;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// *** private methods ***
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
private Scalar getScalar(CodeUnit cu, ListingActionContext context) {
|
private Scalar getScalar(CodeUnit cu, ListingActionContext context) {
|
||||||
int opIndex = getOperandIndex(context);
|
int opIndex = getOperandIndex(context);
|
||||||
int subOpIndex = getSubOperandIndex(context);
|
int subOpIndex = getSubOperandIndex(context);
|
||||||
|
@ -664,7 +605,7 @@ public class EquatePlugin extends Plugin {
|
||||||
* Get scalar value associated with the specified code unit,
|
* Get scalar value associated with the specified code unit,
|
||||||
* opIndex and subOpindex. NOTE: this method does not support
|
* opIndex and subOpindex. NOTE: this method does not support
|
||||||
* composite or array data (null will always be returned).
|
* composite or array data (null will always be returned).
|
||||||
* @param cu cpde unit
|
* @param cu code unit
|
||||||
* @param opIndex operand index
|
* @param opIndex operand index
|
||||||
* @param subOpIndex sub-operand index
|
* @param subOpIndex sub-operand index
|
||||||
* @return scalar value or null
|
* @return scalar value or null
|
||||||
|
|
|
@ -30,51 +30,34 @@ import ghidra.program.model.symbol.*;
|
||||||
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
|
||||||
import ghidra.util.exception.DuplicateNameException;
|
import ghidra.util.exception.DuplicateNameException;
|
||||||
import ghidra.util.exception.InvalidInputException;
|
import ghidra.util.exception.InvalidInputException;
|
||||||
import ghidra.util.task.TaskMonitorAdapter;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
/**
|
|
||||||
* Test the equate manager for the database implementation.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
private ProgramDB program;
|
private ProgramDB program;
|
||||||
private AddressSpace space;
|
private AddressSpace space;
|
||||||
private EquateTable equateTable;
|
private EquateTable equateTable;
|
||||||
private int transactionID;
|
private int transactionID;
|
||||||
|
|
||||||
/**
|
@Before
|
||||||
* Constructor for EquateManagerTest.
|
public void setUp() throws Exception {
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
public EquateManagerTest() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @see TestCase#setUp()
|
|
||||||
*/
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
program = createDefaultProgram("Test", ProgramBuilder._TOY, this);
|
program = createDefaultProgram("Test", ProgramBuilder._TOY, this);
|
||||||
space = program.getAddressFactory().getDefaultAddressSpace();
|
space = program.getAddressFactory().getDefaultAddressSpace();
|
||||||
Memory memory = program.getMemory();
|
Memory memory = program.getMemory();
|
||||||
transactionID = program.startTransaction("Test");
|
transactionID = program.startTransaction("Test");
|
||||||
memory.createInitializedBlock("test", addr(0), 5000, (byte) 0,
|
memory.createInitializedBlock("test", addr(0), 5000, (byte) 0, TaskMonitor.DUMMY, false);
|
||||||
TaskMonitorAdapter.DUMMY_MONITOR, false);
|
|
||||||
|
|
||||||
equateTable = program.getEquateTable();
|
equateTable = program.getEquateTable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
program.endTransaction(transactionID, true);
|
program.endTransaction(transactionID, true);
|
||||||
program.release(this);
|
program.release(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEquate() throws Exception {
|
public void testCreateEquate() throws Exception {
|
||||||
Equate equate = equateTable.createEquate("Test", 100);
|
Equate equate = equateTable.createEquate("Test", 100);
|
||||||
assertNotNull(equate);
|
assertNotNull(equate);
|
||||||
|
|
||||||
|
@ -82,8 +65,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertNotNull(equate);
|
assertNotNull(equate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateEquateDuplicate() throws Exception {
|
public void testCreateEquateDuplicate() throws Exception {
|
||||||
equateTable.createEquate("Test", 100);
|
equateTable.createEquate("Test", 100);
|
||||||
equateTable.createEquate("Test-2", 1000);
|
equateTable.createEquate("Test-2", 1000);
|
||||||
try {
|
try {
|
||||||
|
@ -91,35 +74,38 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
Assert.fail("Should have gotten duplicate name exception");
|
Assert.fail("Should have gotten duplicate name exception");
|
||||||
}
|
}
|
||||||
catch (DuplicateNameException e) {
|
catch (DuplicateNameException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBadNameForCreate() throws Exception {
|
public void testBadNameForCreate() throws Exception {
|
||||||
try {
|
try {
|
||||||
equateTable.createEquate("", 100);
|
equateTable.createEquate("", 100);
|
||||||
Assert.fail("Should have gotten invalid input exception");
|
Assert.fail("Should have gotten invalid input exception");
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
equateTable.createEquate(null, 100);
|
equateTable.createEquate(null, 100);
|
||||||
Assert.fail("Should have gotten invalid input exception");
|
Assert.fail("Should have gotten invalid input exception");
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBasicEquate() throws Exception {
|
public void testBasicEquate() throws Exception {
|
||||||
Equate equate = equateTable.createEquate("Test", 100);
|
Equate equate = equateTable.createEquate("Test", 100);
|
||||||
assertEquals("Test", equate.getName());
|
assertEquals("Test", equate.getName());
|
||||||
|
|
||||||
assertEquals(100, equate.getValue());
|
assertEquals(100, equate.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddReferenceOnEquate() throws Exception {
|
public void testAddReferenceOnEquate() throws Exception {
|
||||||
Equate eqTest = equateTable.createEquate("Test", 100);
|
Equate eqTest = equateTable.createEquate("Test", 100);
|
||||||
eqTest.addReference(addr(100), 0);
|
eqTest.addReference(addr(100), 0);
|
||||||
EquateReference[] refs = eqTest.getReferences();
|
EquateReference[] refs = eqTest.getReferences();
|
||||||
|
@ -150,8 +136,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// assertEquals(1, eqTest3.getReferenceCount());
|
// assertEquals(1, eqTest3.getReferenceCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveReference() throws Exception {
|
public void testRemoveReference() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test", 1);
|
Equate eq = equateTable.createEquate("Test", 1);
|
||||||
|
|
||||||
eq.addReference(addr(10), 0);
|
eq.addReference(addr(10), 0);
|
||||||
|
@ -185,8 +171,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(7, refs.length);
|
assertEquals(7, refs.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquateIterator() throws Exception {
|
public void testEquateIterator() throws Exception {
|
||||||
|
|
||||||
for (int i = 10; i < 20; i++) {
|
for (int i = 10; i < 20; i++) {
|
||||||
equateTable.createEquate("Test_" + i, i);
|
equateTable.createEquate("Test_" + i, i);
|
||||||
|
@ -203,8 +189,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquateAddressIterator() throws Exception {
|
public void testEquateAddressIterator() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test", 1);
|
Equate eq = equateTable.createEquate("Test", 1);
|
||||||
|
|
||||||
eq.addReference(addr(100), 3);
|
eq.addReference(addr(100), 3);
|
||||||
|
@ -228,8 +214,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(7, count);// should filter out duplicate ref addrs
|
assertEquals(7, count);// should filter out duplicate ref addrs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquateAddressIteratorStart() throws Exception {
|
public void testEquateAddressIteratorStart() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test", 1);
|
Equate eq = equateTable.createEquate("Test", 1);
|
||||||
|
|
||||||
eq.addReference(addr(100), 3);
|
eq.addReference(addr(100), 3);
|
||||||
|
@ -247,8 +233,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(2, count);// should filter out duplicate ref addrs
|
assertEquals(2, count);// should filter out duplicate ref addrs
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEquateAddressIteratorSet() throws Exception {
|
public void testEquateAddressIteratorSet() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test", 1);
|
Equate eq = equateTable.createEquate("Test", 1);
|
||||||
|
|
||||||
eq.addReference(addr(100), 3);
|
eq.addReference(addr(100), 3);
|
||||||
|
@ -287,8 +273,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetEquatesByValue() throws Exception {
|
public void testGetEquatesByValue() throws Exception {
|
||||||
// now create equates with the same value
|
// now create equates with the same value
|
||||||
for (int i = 0; i < 10; i++) {
|
for (int i = 0; i < 10; i++) {
|
||||||
equateTable.createEquate("EQ_0" + i, 500);
|
equateTable.createEquate("EQ_0" + i, 500);
|
||||||
|
@ -299,8 +285,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(12, equates.size());
|
assertEquals(12, equates.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetEquateByName() throws Exception {
|
public void testGetEquateByName() throws Exception {
|
||||||
equateTable.createEquate("Test", 500);
|
equateTable.createEquate("Test", 500);
|
||||||
equateTable.createEquate("Test2", 1500);
|
equateTable.createEquate("Test2", 1500);
|
||||||
|
|
||||||
|
@ -315,8 +301,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertNull(equateTable.getEquate("foo"));
|
assertNull(equateTable.getEquate("foo"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveEquate() throws Exception {
|
public void testRemoveEquate() throws Exception {
|
||||||
equateTable.createEquate("Test", 500);
|
equateTable.createEquate("Test", 500);
|
||||||
equateTable.createEquate("Test2", 1500);
|
equateTable.createEquate("Test2", 1500);
|
||||||
|
|
||||||
|
@ -325,8 +311,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertNotNull(equateTable.getEquate("Test2"));
|
assertNotNull(equateTable.getEquate("Test2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveEquateWithRefs() throws Exception {
|
public void testRemoveEquateWithRefs() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test", 1);
|
Equate eq = equateTable.createEquate("Test", 1);
|
||||||
|
|
||||||
eq.addReference(addr(100), 3);
|
eq.addReference(addr(100), 3);
|
||||||
|
@ -344,8 +330,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertNotNull(equateTable.getEquate("Test2"));
|
assertNotNull(equateTable.getEquate("Test2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRemoveEquatesInRange() throws Exception {
|
public void testRemoveEquatesInRange() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test1", 100);
|
Equate eq = equateTable.createEquate("Test1", 100);
|
||||||
equateTable.createEquate("Test2", 200);
|
equateTable.createEquate("Test2", 200);
|
||||||
equateTable.createEquate("Test3", 200);
|
equateTable.createEquate("Test3", 200);
|
||||||
|
@ -370,7 +356,7 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
}
|
}
|
||||||
assertEquals(6, count);
|
assertEquals(6, count);
|
||||||
|
|
||||||
equateTable.deleteAddressRange(addr(50), addr(500), TaskMonitorAdapter.DUMMY_MONITOR);
|
equateTable.deleteAddressRange(addr(50), addr(500), TaskMonitor.DUMMY);
|
||||||
assertNull(equateTable.getEquate("Test1"));
|
assertNull(equateTable.getEquate("Test1"));
|
||||||
assertNotNull(equateTable.getEquate("Test4"));
|
assertNotNull(equateTable.getEquate("Test4"));
|
||||||
assertEquals(0, equateTable.getEquates(addr(100), 0).size());
|
assertEquals(0, equateTable.getEquates(addr(100), 0).size());
|
||||||
|
@ -386,8 +372,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(5, count);
|
assertEquals(5, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenameEquate() throws Exception {
|
public void testRenameEquate() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test1", 100);
|
Equate eq = equateTable.createEquate("Test1", 100);
|
||||||
equateTable.createEquate("Test2", 200);
|
equateTable.createEquate("Test2", 200);
|
||||||
equateTable.createEquate("Test3", 200);
|
equateTable.createEquate("Test3", 200);
|
||||||
|
@ -407,8 +393,8 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
assertEquals(eq, temp);
|
assertEquals(eq, temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenameEquateDuplicate() throws Exception {
|
public void testRenameEquateDuplicate() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test1", 100);
|
Equate eq = equateTable.createEquate("Test1", 100);
|
||||||
equateTable.createEquate("Test2", 200);
|
equateTable.createEquate("Test2", 200);
|
||||||
equateTable.createEquate("Test3", 200);
|
equateTable.createEquate("Test3", 200);
|
||||||
|
@ -419,6 +405,7 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
Assert.fail("Should have gotten DuplicateNameException");
|
Assert.fail("Should have gotten DuplicateNameException");
|
||||||
}
|
}
|
||||||
catch (DuplicateNameException e) {
|
catch (DuplicateNameException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
eq = equateTable.createEquate("foo", 100);
|
eq = equateTable.createEquate("foo", 100);
|
||||||
eq.renameEquate("foo");// nothing should happen
|
eq.renameEquate("foo");// nothing should happen
|
||||||
|
@ -427,23 +414,26 @@ public class EquateManagerTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
Assert.fail("Should have gotten DuplicateNameException");
|
Assert.fail("Should have gotten DuplicateNameException");
|
||||||
}
|
}
|
||||||
catch (DuplicateNameException e) {
|
catch (DuplicateNameException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenameEquateBadName() throws Exception {
|
public void testRenameEquateBadName() throws Exception {
|
||||||
Equate eq = equateTable.createEquate("Test1", 100);
|
Equate eq = equateTable.createEquate("Test1", 100);
|
||||||
try {
|
try {
|
||||||
eq.renameEquate("");
|
eq.renameEquate("");
|
||||||
Assert.fail("Empty string should be invalid!");
|
Assert.fail("Empty string should be invalid!");
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
eq.renameEquate(null);
|
eq.renameEquate(null);
|
||||||
Assert.fail("Empty string should be invalid!");
|
Assert.fail("Empty string should be invalid!");
|
||||||
}
|
}
|
||||||
catch (InvalidInputException e) {
|
catch (InvalidInputException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ import ghidra.program.database.*;
|
||||||
import ghidra.program.database.map.AddressKeyAddressIterator;
|
import ghidra.program.database.map.AddressKeyAddressIterator;
|
||||||
import ghidra.program.database.map.AddressMap;
|
import ghidra.program.database.map.AddressMap;
|
||||||
import ghidra.program.model.address.*;
|
import ghidra.program.model.address.*;
|
||||||
import ghidra.program.model.data.DataTypeManager;
|
|
||||||
import ghidra.program.model.data.Enum;
|
import ghidra.program.model.data.Enum;
|
||||||
import ghidra.program.model.listing.*;
|
import ghidra.program.model.listing.*;
|
||||||
import ghidra.program.model.scalar.Scalar;
|
import ghidra.program.model.scalar.Scalar;
|
||||||
|
@ -40,9 +39,7 @@ import ghidra.util.exception.*;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation for the Equate Table.
|
* Implementation of the Equate Table
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
|
|
||||||
|
@ -60,14 +57,12 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param handle database handle
|
* @param handle database handle
|
||||||
* @param addrMap map that converts addresses to longs and longs to
|
* @param addrMap map that converts addresses to longs and longs to addresses
|
||||||
* addresses
|
|
||||||
* @param openMode one of ProgramDB.CREATE, UPDATE, UPGRADE, or READ_ONLY
|
* @param openMode one of ProgramDB.CREATE, UPDATE, UPGRADE, or READ_ONLY
|
||||||
* @param lock the program synchronization lock
|
* @param lock the program synchronization lock
|
||||||
* @param monitor the progress monitor used when upgrading.
|
* @param monitor the progress monitor used when upgrading.
|
||||||
* @throws VersionException if the database version doesn't match the current version.
|
* @throws VersionException if the database version doesn't match the current version.
|
||||||
* @throws IOException if a database error occurs.
|
* @throws IOException if a database error occurs.
|
||||||
* @throws CancelledException if the user cancels the upgrade.
|
|
||||||
*/
|
*/
|
||||||
public EquateManager(DBHandle handle, AddressMap addrMap, int openMode, Lock lock,
|
public EquateManager(DBHandle handle, AddressMap addrMap, int openMode, Lock lock,
|
||||||
TaskMonitor monitor) throws VersionException, IOException {
|
TaskMonitor monitor) throws VersionException, IOException {
|
||||||
|
@ -103,26 +98,17 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.database.ManagerDB#setProgram(ghidra.program.database.ProgramDB)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void setProgram(ProgramDB program) {
|
public void setProgram(ProgramDB program) {
|
||||||
this.program = program;
|
this.program = program;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.database.ManagerDB#programReady(int, int, ghidra.util.task.TaskMonitor)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void programReady(int openMode, int currentRevision, TaskMonitor monitor)
|
public void programReady(int openMode, int currentRevision, TaskMonitor monitor)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see db.util.ErrorHandler#dbError(java.io.IOException)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void dbError(IOException e) {
|
public void dbError(IOException e) {
|
||||||
program.dbError(e);
|
program.dbError(e);
|
||||||
|
@ -167,12 +153,9 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
InstructionIterator it = listing.getInstructions(addresses, true);
|
InstructionIterator it = listing.getInstructions(addresses, true);
|
||||||
Stream<Instruction> instructions = StreamSupport.stream(it.spliterator(), false);
|
Stream<Instruction> instructions = StreamSupport.stream(it.spliterator(), false);
|
||||||
|
|
||||||
DataTypeManager dtm = program.getDataTypeManager();
|
|
||||||
try {
|
try {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
int id = dtm.startTransaction("Apply Enum");
|
|
||||||
instructions.forEach(applyEquates);
|
instructions.forEach(applyEquates);
|
||||||
dtm.endTransaction(id, true);
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
lock.release();
|
lock.release();
|
||||||
|
@ -198,13 +181,7 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (program.getDataTypeManager().findDataTypeForID(enoom.getUniversalID()) == null) {
|
if (program.getDataTypeManager().findDataTypeForID(enoom.getUniversalID()) == null) {
|
||||||
int transactionID = program.startTransaction("Set Equate Dialog");
|
enoom = (Enum) program.getDataTypeManager().addDataType(enoom, null);
|
||||||
try {
|
|
||||||
enoom = (Enum) program.getDataTypeManager().addDataType(enoom, null);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
program.endTransaction(transactionID, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Address addr = instruction.getAddress();
|
Address addr = instruction.getAddress();
|
||||||
|
@ -243,9 +220,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return equate;
|
return equate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#createEquate(java.lang.String, long)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Equate createEquate(String name, long value)
|
public Equate createEquate(String name, long value)
|
||||||
throws DuplicateNameException, InvalidInputException {
|
throws DuplicateNameException, InvalidInputException {
|
||||||
|
@ -271,9 +245,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquate(ghidra.program.model.address.Address, int, long)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Equate getEquate(Address reference, int opIndex, long scalarValue) {
|
public Equate getEquate(Address reference, int opIndex, long scalarValue) {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
|
@ -302,9 +273,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquates(ghidra.program.model.address.Address, int)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public List<Equate> getEquates(Address reference, int opIndex) {
|
public List<Equate> getEquates(Address reference, int opIndex) {
|
||||||
List<Equate> ret = new LinkedList<>();
|
List<Equate> ret = new LinkedList<>();
|
||||||
|
@ -331,9 +299,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquates(ghidra.program.model.address.Address)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public List<Equate> getEquates(Address reference) {
|
public List<Equate> getEquates(Address reference) {
|
||||||
List<Equate> ret = new LinkedList<>();
|
List<Equate> ret = new LinkedList<>();
|
||||||
|
@ -358,9 +323,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquate(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Equate getEquate(String name) {
|
public Equate getEquate(String name) {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
|
@ -369,6 +331,7 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return getEquateDB(equateID);
|
return getEquateDB(equateID);
|
||||||
}
|
}
|
||||||
catch (NotFoundException e) {
|
catch (NotFoundException e) {
|
||||||
|
// just return null below
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
program.dbError(e);
|
program.dbError(e);
|
||||||
|
@ -379,9 +342,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquateAddresses()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public AddressIterator getEquateAddresses() {
|
public AddressIterator getEquateAddresses() {
|
||||||
|
|
||||||
|
@ -395,9 +355,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return new EmptyAddressIterator();
|
return new EmptyAddressIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquateAddresses(ghidra.program.model.address.Address)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public AddressIterator getEquateAddresses(Address startAddr) {
|
public AddressIterator getEquateAddresses(Address startAddr) {
|
||||||
try {
|
try {
|
||||||
|
@ -421,9 +378,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return new EmptyAddressIterator();
|
return new EmptyAddressIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquateAddresses(ghidra.program.model.address.AddressSetView)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public AddressIterator getEquateAddresses(AddressSetView set) {
|
public AddressIterator getEquateAddresses(AddressSetView set) {
|
||||||
try {
|
try {
|
||||||
|
@ -436,9 +390,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return new EmptyAddressIterator();
|
return new EmptyAddressIterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquates()
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Equate> getEquates() {
|
public Iterator<Equate> getEquates() {
|
||||||
try {
|
try {
|
||||||
|
@ -451,9 +402,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return new EquateIterator(null);
|
return new EquateIterator(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#getEquates(long)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public List<Equate> getEquates(long value) {
|
public List<Equate> getEquates(long value) {
|
||||||
ArrayList<Equate> list = new ArrayList<>();
|
ArrayList<Equate> list = new ArrayList<>();
|
||||||
|
@ -473,9 +421,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.database.ManagerDB#deleteAddressRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address, ghidra.util.task.TaskMonitor)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
|
public void deleteAddressRange(Address startAddr, Address endAddr, TaskMonitor monitor)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
|
@ -516,9 +461,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.model.symbol.EquateTable#removeEquate(java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean removeEquate(String name) {
|
public boolean removeEquate(String name) {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
|
@ -562,30 +504,18 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the address map.
|
|
||||||
*/
|
|
||||||
AddressMap getAddressMap() {
|
AddressMap getAddressMap() {
|
||||||
return addrMap;
|
return addrMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the database adapter for equate table.
|
|
||||||
*/
|
|
||||||
EquateDBAdapter getEquateDatabaseAdapter() {
|
EquateDBAdapter getEquateDatabaseAdapter() {
|
||||||
return equateAdapter;
|
return equateAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the database adapter for the equate references table.
|
|
||||||
*/
|
|
||||||
EquateRefDBAdapter getRefDatabaseAdapter() {
|
EquateRefDBAdapter getRefDatabaseAdapter() {
|
||||||
return refAdapter;
|
return refAdapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a reference for an equate at the given operand position.
|
|
||||||
*/
|
|
||||||
void addReference(long equateID, Address address, int opIndex, long dynamicHash)
|
void addReference(long equateID, Address address, int opIndex, long dynamicHash)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
|
@ -622,9 +552,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the references for the given equate ID.
|
|
||||||
*/
|
|
||||||
EquateRefDB[] getReferences(long equateID) throws IOException {
|
EquateRefDB[] getReferences(long equateID) throws IOException {
|
||||||
long[] keys = refAdapter.getRecordKeysForEquateID(equateID);
|
long[] keys = refAdapter.getRecordKeysForEquateID(equateID);
|
||||||
EquateRefDB[] refs = new EquateRefDB[keys.length];
|
EquateRefDB[] refs = new EquateRefDB[keys.length];
|
||||||
|
@ -634,19 +561,10 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
return refs;
|
return refs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the number of references for the given equate ID.
|
|
||||||
*/
|
|
||||||
int getReferenceCount(long equateID) throws IOException {
|
int getReferenceCount(long equateID) throws IOException {
|
||||||
return getReferences(equateID).length;
|
return getReferences(equateID).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the reference.
|
|
||||||
* @param equateDB equate
|
|
||||||
* @param refAddr ref address to remove
|
|
||||||
* @param opIndex operand index
|
|
||||||
*/
|
|
||||||
void removeReference(EquateDB equateDB, Address refAddr, short opIndex) throws IOException {
|
void removeReference(EquateDB equateDB, Address refAddr, short opIndex) throws IOException {
|
||||||
|
|
||||||
long[] keys = refAdapter.getRecordKeysForEquateID(equateDB.getKey());
|
long[] keys = refAdapter.getRecordKeysForEquateID(equateDB.getKey());
|
||||||
|
@ -659,13 +577,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the reference.
|
|
||||||
* @param equateDB equate
|
|
||||||
* @param dynamicHash hash value
|
|
||||||
* @param refAddr ref address to remove
|
|
||||||
* @param opIndex operand index
|
|
||||||
*/
|
|
||||||
void removeReference(EquateDB equateDB, long dynamicHash, Address refAddr) throws IOException {
|
void removeReference(EquateDB equateDB, long dynamicHash, Address refAddr) throws IOException {
|
||||||
|
|
||||||
long[] keys = refAdapter.getRecordKeysForEquateID(equateDB.getKey());
|
long[] keys = refAdapter.getRecordKeysForEquateID(equateDB.getKey());
|
||||||
|
@ -678,10 +589,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify that the name is not null and not the empty string.
|
|
||||||
* @throws InvalidInputException if the name is null or is empty
|
|
||||||
*/
|
|
||||||
void validateName(String name) throws InvalidInputException {
|
void validateName(String name) throws InvalidInputException {
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
throw new InvalidInputException("Name is null");
|
throw new InvalidInputException("Name is null");
|
||||||
|
@ -693,7 +600,7 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send notification that the equate name changed.
|
* Send notification that the equate name changed
|
||||||
* @param oldName old name
|
* @param oldName old name
|
||||||
* @param newName new name
|
* @param newName new name
|
||||||
*/
|
*/
|
||||||
|
@ -784,66 +691,10 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
null);
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
|
||||||
private class EquateIterator implements Iterator<Equate> {
|
|
||||||
private RecordIterator iter;
|
|
||||||
|
|
||||||
private EquateIterator(RecordIterator iter) {
|
|
||||||
this.iter = iter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see java.util.Iterator#hasNext()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
if (iter != null) {
|
|
||||||
try {
|
|
||||||
return iter.hasNext();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
program.dbError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see java.util.Iterator#next()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Equate next() {
|
|
||||||
if (iter != null) {
|
|
||||||
try {
|
|
||||||
Record record = iter.next();
|
|
||||||
if (record != null) {
|
|
||||||
return getEquateDB(record.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
program.dbError(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see java.util.Iterator#remove()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("remove is not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Lock getLock() {
|
Lock getLock() {
|
||||||
return lock;
|
return lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.database.ManagerDB#invalidateCache(boolean)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidateCache(boolean all) {
|
public void invalidateCache(boolean all) {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
|
@ -856,9 +707,6 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ghidra.program.database.ManagerDB#moveAddressRange(ghidra.program.model.address.Address, ghidra.program.model.address.Address, long, ghidra.util.task.TaskMonitor)
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
|
public void moveAddressRange(Address fromAddr, Address toAddr, long length, TaskMonitor monitor)
|
||||||
throws CancelledException {
|
throws CancelledException {
|
||||||
|
@ -879,7 +727,7 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
* Formats a string to the equate format given the enum UUID and the value for the equate. The
|
* Formats a string to the equate format given the enum UUID and the value for the equate. The
|
||||||
* formatted strings are used when setting equates from datatypes so that information can be
|
* formatted strings are used when setting equates from datatypes so that information can be
|
||||||
* stored with an equate to point back to that datatype.
|
* stored with an equate to point back to that datatype.
|
||||||
* @param dtID The enums data type UUID
|
* @param dtID The enum's data type UUID
|
||||||
* @param equateValue The value intended for the equate
|
* @param equateValue The value intended for the equate
|
||||||
* @return The formatted equate name
|
* @return The formatted equate name
|
||||||
*/
|
*/
|
||||||
|
@ -922,4 +770,51 @@ public class EquateManager implements EquateTable, ErrorHandler, ManagerDB {
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==================================================================================================
|
||||||
|
// Inner Classes
|
||||||
|
//==================================================================================================
|
||||||
|
|
||||||
|
private class EquateIterator implements Iterator<Equate> {
|
||||||
|
private RecordIterator iter;
|
||||||
|
|
||||||
|
private EquateIterator(RecordIterator iter) {
|
||||||
|
this.iter = iter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
if (iter != null) {
|
||||||
|
try {
|
||||||
|
return iter.hasNext();
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
program.dbError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Equate next() {
|
||||||
|
if (iter != null) {
|
||||||
|
try {
|
||||||
|
Record record = iter.next();
|
||||||
|
if (record != null) {
|
||||||
|
return getEquateDB(record.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
program.dbError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
throw new UnsupportedOperationException("remove is not supported.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue