mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Corrected test fallout from Memory changes
This commit is contained in:
parent
cee8a138c0
commit
7385544bed
11 changed files with 93 additions and 59 deletions
|
@ -360,13 +360,16 @@ class AddBlockModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasMappedAddressIfNeeded() {
|
private boolean hasMappedAddressIfNeeded() {
|
||||||
if (blockType == MemoryBlockType.BIT_MAPPED || blockType == MemoryBlockType.BYTE_MAPPED) {
|
if (blockType != MemoryBlockType.BIT_MAPPED && blockType != MemoryBlockType.BYTE_MAPPED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (baseAddr == null) {
|
if (baseAddr == null) {
|
||||||
String blockTypeStr =
|
String blockTypeStr =
|
||||||
(blockType == MemoryBlockType.BIT_MAPPED) ? "bit-mapped" : "byte-mapped";
|
(blockType == MemoryBlockType.BIT_MAPPED) ? "bit-mapped" : "byte-mapped";
|
||||||
message = "Please enter a source address for the " + blockTypeStr + " block";
|
message = "Please enter a source address for the " + blockTypeStr + " block";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (blockType == MemoryBlockType.BYTE_MAPPED) {
|
||||||
if (schemeDestByteCount <= 0 || schemeDestByteCount > Byte.MAX_VALUE ||
|
if (schemeDestByteCount <= 0 || schemeDestByteCount > Byte.MAX_VALUE ||
|
||||||
schemeSrcByteCount <= 0 || schemeSrcByteCount > Byte.MAX_VALUE) {
|
schemeSrcByteCount <= 0 || schemeSrcByteCount > Byte.MAX_VALUE) {
|
||||||
message = "Mapping ratio values must be within range: 1 to 127";
|
message = "Mapping ratio values must be within range: 1 to 127";
|
||||||
|
|
|
@ -267,7 +267,7 @@ class MemoryMapModel extends AbstractSortedTableModel<MemoryBlock> {
|
||||||
if (name.equals(block.getName())) {
|
if (name.equals(block.getName())) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Memory.isValidAddressSpaceName(name)) {
|
if (!Memory.isValidAddressSpaceName(name)) {
|
||||||
Msg.showError(this, provider.getComponent(), "Invalid Name",
|
Msg.showError(this, provider.getComponent(), "Invalid Name",
|
||||||
"Invalid Memory Block Name: " + name);
|
"Invalid Memory Block Name: " + name);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -112,11 +112,17 @@ public class MemoryBlockStartFieldFactory extends FieldFactory {
|
||||||
}
|
}
|
||||||
CodeUnit cu = (CodeUnit) proxyObject;
|
CodeUnit cu = (CodeUnit) proxyObject;
|
||||||
|
|
||||||
|
String[] comments;
|
||||||
List<AttributedString> attributedStrings = createBlockStartText(cu);
|
List<AttributedString> attributedStrings = createBlockStartText(cu);
|
||||||
String[] comments = new String[attributedStrings.size()];
|
if (attributedStrings == null) {
|
||||||
|
comments = new String[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
comments = new String[attributedStrings.size()];
|
||||||
for (int i = 0; i < comments.length; i++) {
|
for (int i = 0; i < comments.length; i++) {
|
||||||
comments[i] = attributedStrings.get(i).getText();
|
comments[i] = attributedStrings.get(i).getText();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new MemoryBlockStartFieldLocation(cu.getProgram(), cu.getMinAddress(), null, row,
|
return new MemoryBlockStartFieldLocation(cu.getProgram(), cu.getMinAddress(), null, row,
|
||||||
col, comments, 0);
|
col, comments, 0);
|
||||||
|
|
|
@ -332,6 +332,7 @@ public class ProgramBuilder {
|
||||||
// can't happen
|
// can't happen
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
throw new RuntimeException("Exception building memory", e);
|
throw new RuntimeException("Exception building memory", e);
|
||||||
}
|
}
|
||||||
endTransaction();
|
endTransaction();
|
||||||
|
@ -419,7 +420,8 @@ public class ProgramBuilder {
|
||||||
startTransaction();
|
startTransaction();
|
||||||
MemoryBlock block = program.getMemory().getBlock(address);
|
MemoryBlock block = program.getMemory().getBlock(address);
|
||||||
if (block == null) {
|
if (block == null) {
|
||||||
createMemory("Block_" + stringAddress, stringAddress, bytes.length);
|
createMemory("Block_" + stringAddress.toString().replace(':', '_'), stringAddress,
|
||||||
|
bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
Memory memory = program.getMemory();
|
Memory memory = program.getMemory();
|
||||||
|
|
|
@ -268,36 +268,38 @@ public class MemoryMapProvider1Test extends AbstractGhidraHeadedIntegrationTest
|
||||||
assertEquals(".test", model.getValueAt(0, MemoryMapModel.NAME));
|
assertEquals(".test", model.getValueAt(0, MemoryMapModel.NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
// Test Eliminated - Memory API allows duplicate names which is a common occurance
|
||||||
public void testDuplicateName() throws Exception {
|
// with import formats such as ELF
|
||||||
table.addRowSelectionInterval(0, 0);
|
//
|
||||||
Rectangle rect = table.getCellRect(0, MemoryMapModel.NAME, true);
|
// public void testDuplicateName() throws Exception {
|
||||||
clickMouse(table, 1, rect.x, rect.y, 2, 0);
|
// table.addRowSelectionInterval(0, 0);
|
||||||
waitForPostedSwingRunnables();
|
// Rectangle rect = table.getCellRect(0, MemoryMapModel.NAME, true);
|
||||||
|
// clickMouse(table, 1, rect.x, rect.y, 2, 0);
|
||||||
SwingUtilities.invokeLater(() -> {
|
// waitForPostedSwingRunnables();
|
||||||
int row = 0;
|
//
|
||||||
TableCellEditor editor = table.getCellEditor(row, MemoryMapModel.NAME);
|
// SwingUtilities.invokeLater(() -> {
|
||||||
Component c = editor.getTableCellEditorComponent(table,
|
// int row = 0;
|
||||||
model.getValueAt(row, MemoryMapModel.NAME), true, row, MemoryMapModel.NAME);
|
// TableCellEditor editor = table.getCellEditor(row, MemoryMapModel.NAME);
|
||||||
JTextField tf = (JTextField) c;
|
// Component c = editor.getTableCellEditorComponent(table,
|
||||||
|
// model.getValueAt(row, MemoryMapModel.NAME), true, row, MemoryMapModel.NAME);
|
||||||
tf.setText(".data");
|
// JTextField tf = (JTextField) c;
|
||||||
editor.stopCellEditing();
|
//
|
||||||
});
|
// tf.setText(".data");
|
||||||
waitForPostedSwingRunnables();
|
// editor.stopCellEditing();
|
||||||
assertEquals(".text", model.getValueAt(0, MemoryMapModel.NAME));
|
// });
|
||||||
|
// waitForPostedSwingRunnables();
|
||||||
final OptionDialog d =
|
// assertEquals(".text", model.getValueAt(0, MemoryMapModel.NAME));
|
||||||
waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, 2000);
|
//
|
||||||
|
// final OptionDialog d =
|
||||||
assertNotNull(d);
|
// waitForDialogComponent(tool.getToolFrame(), OptionDialog.class, 2000);
|
||||||
String msg = findMessage(d.getComponent());
|
//
|
||||||
assertNotNull(msg);
|
// assertNotNull(d);
|
||||||
assertEquals("Block named .data already exists.", msg);
|
// String msg = findMessage(d.getComponent());
|
||||||
SwingUtilities.invokeAndWait(() -> d.close());
|
// assertNotNull(msg);
|
||||||
|
// assertEquals("Block named .data already exists.", msg);
|
||||||
}
|
// SwingUtilities.invokeAndWait(() -> d.close());
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEditComment() throws Exception {
|
public void testEditComment() throws Exception {
|
||||||
|
|
|
@ -243,7 +243,7 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
public void testWildcardInBlock() throws Exception {
|
public void testWildcardInBlock() throws Exception {
|
||||||
|
|
||||||
loadProgram("x86");
|
loadProgram("x86");
|
||||||
MemoryBlock block = createOverlay("Test Overlay", "1002000", 100);
|
MemoryBlock block = createOverlay("TestOverlay", "1002000", 100);
|
||||||
String name = block.getName();
|
String name = block.getName();
|
||||||
|
|
||||||
AddLabelCmd cmd = new AddLabelCmd(addr(name + "::1002000"), "Bob", SourceType.USER_DEFINED);
|
AddLabelCmd cmd = new AddLabelCmd(addr(name + "::1002000"), "Bob", SourceType.USER_DEFINED);
|
||||||
|
@ -252,7 +252,7 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// try a wildcard for an address in the new block (this gets us an extra code path tested)
|
// try a wildcard for an address in the new block (this gets us an extra code path tested)
|
||||||
setText(name + "::*ob");
|
setText(name + "::*ob");
|
||||||
performOkCallback();
|
performOkCallback();
|
||||||
assertEquals(addr("Test Overlay::1002000"), cbPlugin.getCurrentAddress());
|
assertEquals(addr("TestOverlay::1002000"), cbPlugin.getCurrentAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -272,7 +272,7 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// queries an address has multiple matches.
|
// queries an address has multiple matches.
|
||||||
//
|
//
|
||||||
loadProgram("x86");
|
loadProgram("x86");
|
||||||
createOverlay("Test Overlay", "1002000", 100);
|
createOverlay("TestOverlay", "1002000", 100);
|
||||||
assumeCurrentAddressSpace(false);
|
assumeCurrentAddressSpace(false);
|
||||||
showDialog();
|
showDialog();
|
||||||
setText("1002000");
|
setText("1002000");
|
||||||
|
@ -289,7 +289,7 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// addresses is off *and* the current address space has a matching address.
|
// addresses is off *and* the current address space has a matching address.
|
||||||
//
|
//
|
||||||
loadProgram("x86");
|
loadProgram("x86");
|
||||||
createOverlay("Test Overlay", "1002000", 100);
|
createOverlay("TestOverlay", "1002000", 100);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Turn off the option to show all addresses when there is a match in our current
|
// Turn off the option to show all addresses when there is a match in our current
|
||||||
|
@ -311,8 +311,8 @@ public class GoToPluginTest extends AbstractGhidraHeadedIntegrationTest {
|
||||||
// option to always show all addresses is off.
|
// option to always show all addresses is off.
|
||||||
//
|
//
|
||||||
loadProgram("x86");
|
loadProgram("x86");
|
||||||
createOverlay("Test Overlay 1", "1002000", 100);
|
createOverlay("TestOverlay1", "1002000", 100);
|
||||||
MemoryBlock overlay2Block = createOverlay("Test Overlay 2", "1003000", 100);
|
MemoryBlock overlay2Block = createOverlay("TestOverlay2", "1003000", 100);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Put us in an address space that does not have a match for the query address
|
// Put us in an address space that does not have a match for the query address
|
||||||
|
|
|
@ -95,6 +95,7 @@ public class BitMappedMemoryBlockTest extends AbstractGhidraHeadedIntegrationTes
|
||||||
Assert.fail("Should not have gotten a byte");
|
Assert.fail("Should not have gotten a byte");
|
||||||
}
|
}
|
||||||
catch (MemoryAccessException e) {
|
catch (MemoryAccessException e) {
|
||||||
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -351,4 +351,21 @@ public class ByteMappedMemoryBlockTest extends AbstractGhidraHeadedIntegrationTe
|
||||||
assertEquals(4, block2.getBytes(addr(0x100), data2));
|
assertEquals(4, block2.getBytes(addr(0x100), data2));
|
||||||
assertTrue(Arrays.equals(new byte[] { 1, 2, -3, -4 }, data2));
|
assertTrue(Arrays.equals(new byte[] { 1, 2, -3, -4 }, data2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNoUnderlyingMemory() throws Exception {
|
||||||
|
|
||||||
|
MemoryBlock byteMappedBlock = memory.createByteMappedBlock("BYTE_BLOCK", addr(0x1000),
|
||||||
|
addr(0x1020), 0x10, new ByteMappingScheme(1, 1), false);
|
||||||
|
|
||||||
|
Address addr = addr(0x1040);
|
||||||
|
MemoryBlock newblock = memory.createBlock(byteMappedBlock, "Test", addr, 0x20);
|
||||||
|
try {
|
||||||
|
newblock.getByte(addr);
|
||||||
|
Assert.fail("Should not have gotten a byte");
|
||||||
|
}
|
||||||
|
catch (MemoryAccessException e) {
|
||||||
|
// expected
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,7 @@ public class MemoryBlockDB implements MemoryBlock {
|
||||||
if (oldName.equals(name)) {
|
if (oldName.equals(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memMap.checkBlockName(name);
|
memMap.checkBlockName(name, isOverlay());
|
||||||
try {
|
try {
|
||||||
if (isOverlay()) {
|
if (isOverlay()) {
|
||||||
memMap.overlayBlockRenamed(oldName, name);
|
memMap.overlayBlockRenamed(oldName, name);
|
||||||
|
|
|
@ -597,7 +597,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
|
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
|
||||||
long length, TaskMonitor monitor, boolean overlay) throws MemoryConflictException,
|
long length, TaskMonitor monitor, boolean overlay) throws MemoryConflictException,
|
||||||
AddressOverflowException, CancelledException, LockException, DuplicateNameException {
|
AddressOverflowException, CancelledException, LockException, DuplicateNameException {
|
||||||
checkBlockName(name);
|
checkBlockName(name, overlay);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkBlockSize(length, true);
|
checkBlockSize(length, true);
|
||||||
|
@ -643,7 +643,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
long offset, long length, boolean overlay) throws LockException, DuplicateNameException,
|
long offset, long length, boolean overlay) throws LockException, DuplicateNameException,
|
||||||
MemoryConflictException, AddressOverflowException, IndexOutOfBoundsException {
|
MemoryConflictException, AddressOverflowException, IndexOutOfBoundsException {
|
||||||
|
|
||||||
checkBlockName(name);
|
checkBlockName(name, overlay);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkBlockSize(length, true);
|
checkBlockSize(length, true);
|
||||||
|
@ -696,7 +696,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
boolean overlay) throws MemoryConflictException, AddressOverflowException,
|
boolean overlay) throws MemoryConflictException, AddressOverflowException,
|
||||||
LockException, DuplicateNameException {
|
LockException, DuplicateNameException {
|
||||||
|
|
||||||
checkBlockName(name);
|
checkBlockName(name, overlay);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkBlockSize(size, false);
|
checkBlockSize(size, false);
|
||||||
|
@ -732,7 +732,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
long length, boolean overlay) throws MemoryConflictException, AddressOverflowException,
|
long length, boolean overlay) throws MemoryConflictException, AddressOverflowException,
|
||||||
LockException, IllegalArgumentException, DuplicateNameException {
|
LockException, IllegalArgumentException, DuplicateNameException {
|
||||||
|
|
||||||
checkBlockName(name);
|
checkBlockName(name, overlay);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkBlockSize(length, false);
|
checkBlockSize(length, false);
|
||||||
|
@ -768,7 +768,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
throws MemoryConflictException, AddressOverflowException, LockException,
|
throws MemoryConflictException, AddressOverflowException, LockException,
|
||||||
DuplicateNameException {
|
DuplicateNameException {
|
||||||
|
|
||||||
checkBlockName(name);
|
checkBlockName(name, overlay);
|
||||||
|
|
||||||
int mappingScheme = 0; // use for 1:1 mapping
|
int mappingScheme = 0; // use for 1:1 mapping
|
||||||
if (byteMappingScheme == null) {
|
if (byteMappingScheme == null) {
|
||||||
|
@ -810,16 +810,17 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
/**
|
/**
|
||||||
* Check new block name for validity
|
* Check new block name for validity
|
||||||
* @param name new block name
|
* @param name new block name
|
||||||
|
* @param isOverlay true if block is overlay
|
||||||
* @throws IllegalArgumentException if invalid block name specified
|
* @throws IllegalArgumentException if invalid block name specified
|
||||||
* @throws DuplicateNameException if name conflicts with an address space name
|
* @throws DuplicateNameException if name conflicts with an address space name
|
||||||
*/
|
*/
|
||||||
void checkBlockName(
|
void checkBlockName(
|
||||||
String name)
|
String name, boolean isOverlay)
|
||||||
throws IllegalArgumentException, DuplicateNameException {
|
throws IllegalArgumentException, DuplicateNameException {
|
||||||
if (!Memory.isValidAddressSpaceName(name)) {
|
if (!Memory.isValidAddressSpaceName(name)) {
|
||||||
throw new IllegalArgumentException("Invalid block name: " + name);
|
throw new IllegalArgumentException("Invalid block name: " + name);
|
||||||
}
|
}
|
||||||
if (getAddressFactory().getAddressSpace(name) != null) {
|
if (isOverlay && getAddressFactory().getAddressSpace(name) != null) {
|
||||||
throw new DuplicateNameException(
|
throw new DuplicateNameException(
|
||||||
"Block name conflicts with existing address space: " + name);
|
"Block name conflicts with existing address space: " + name);
|
||||||
}
|
}
|
||||||
|
@ -829,7 +830,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
public MemoryBlock createBlock(MemoryBlock block, String name, Address start, long length)
|
public MemoryBlock createBlock(MemoryBlock block, String name, Address start, long length)
|
||||||
throws MemoryConflictException, AddressOverflowException, LockException,
|
throws MemoryConflictException, AddressOverflowException, LockException,
|
||||||
DuplicateNameException {
|
DuplicateNameException {
|
||||||
checkBlockName(name);
|
checkBlockName(name, false);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkBlockSize(length, block.isInitialized());
|
checkBlockSize(length, block.isInitialized());
|
||||||
|
@ -840,7 +841,9 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||||
int mappingScheme = 0;
|
int mappingScheme = 0;
|
||||||
if (block.isMapped()) {
|
if (block.isMapped()) {
|
||||||
MemoryBlockSourceInfo info = block.getSourceInfos().get(0);
|
MemoryBlockSourceInfo info = block.getSourceInfos().get(0);
|
||||||
|
if (block.getType() == MemoryBlockType.BYTE_MAPPED) {
|
||||||
mappingScheme = info.getByteMappingScheme().get().getEncodedMappingScheme();
|
mappingScheme = info.getByteMappingScheme().get().getEncodedMappingScheme();
|
||||||
|
}
|
||||||
mappedAddr = info.getMappedRange().get().getMinAddress();
|
mappedAddr = info.getMappedRange().get().getMinAddress();
|
||||||
}
|
}
|
||||||
MemoryBlockDB newBlock = adapter.createBlock(block.getType(), name, start, length,
|
MemoryBlockDB newBlock = adapter.createBlock(block.getType(), name, start, length,
|
||||||
|
|
|
@ -826,7 +826,7 @@ public interface Memory extends AddressSetView {
|
||||||
}
|
}
|
||||||
for (int i = 0; i < name.length(); i++) {
|
for (int i = 0; i < name.length(); i++) {
|
||||||
char c = name.charAt(i);
|
char c = name.charAt(i);
|
||||||
if (c < 0x20 || c >= 0x7f || c == ':') {
|
if (c <= 0x20 || c >= 0x7f || c == ':') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue