mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-5314: Destroy LiveMemoryHandler
This commit is contained in:
parent
7c74de60e6
commit
bef0660e6a
32 changed files with 667 additions and 783 deletions
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -362,9 +362,6 @@ public class MemoryBlockDB implements MemoryBlock {
|
|||
|
||||
@Override
|
||||
public byte getByte(Address addr) throws MemoryAccessException {
|
||||
if (memMap.getLiveMemoryHandler() != null) {
|
||||
return memMap.getByte(addr);
|
||||
}
|
||||
checkValid();
|
||||
long offset = getBlockOffset(addr);
|
||||
return getByte(offset);
|
||||
|
@ -378,10 +375,6 @@ public class MemoryBlockDB implements MemoryBlock {
|
|||
@Override
|
||||
public int getBytes(Address addr, byte[] b, int off, int len)
|
||||
throws IndexOutOfBoundsException, MemoryAccessException {
|
||||
if (memMap.getLiveMemoryHandler() != null) {
|
||||
return memMap.getBytes(addr, b, off, len);
|
||||
}
|
||||
|
||||
checkValid();
|
||||
long offset = getBlockOffset(addr);
|
||||
return getBytes(offset, b, off, len);
|
||||
|
@ -389,10 +382,6 @@ public class MemoryBlockDB implements MemoryBlock {
|
|||
|
||||
@Override
|
||||
public void putByte(Address addr, byte b) throws MemoryAccessException {
|
||||
if (memMap.getLiveMemoryHandler() != null) {
|
||||
memMap.setByte(addr, b);
|
||||
return;
|
||||
}
|
||||
long offset = getBlockOffset(addr);
|
||||
memMap.lock.acquire();
|
||||
try {
|
||||
|
@ -414,10 +403,6 @@ public class MemoryBlockDB implements MemoryBlock {
|
|||
@Override
|
||||
public int putBytes(Address addr, byte[] b, int off, int len)
|
||||
throws IndexOutOfBoundsException, MemoryAccessException {
|
||||
if (memMap.getLiveMemoryHandler() != null) {
|
||||
memMap.setBytes(addr, b, off, len);
|
||||
return len;
|
||||
}
|
||||
memMap.lock.acquire();
|
||||
try {
|
||||
checkValid();
|
||||
|
|
|
@ -40,7 +40,7 @@ import ghidra.util.task.TaskMonitor;
|
|||
/**
|
||||
* The database memory map manager.
|
||||
*/
|
||||
public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
||||
public class MemoryMapDB implements Memory, ManagerDB {
|
||||
|
||||
private ProgramDB program;
|
||||
private AddressMapDB addrMap;
|
||||
|
@ -68,7 +68,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
}
|
||||
|
||||
private MemoryBlock lastBlock;// the last accessed block
|
||||
private LiveMemoryHandler liveMemory;
|
||||
|
||||
// lazy hashmap of block names to blocks, must be reloaded if blocks are removed or added
|
||||
private HashMap<String, MemoryBlock> nameBlockMap = new HashMap<>();
|
||||
|
@ -260,9 +259,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
initializeBlocks();
|
||||
buildAddressSets(true);
|
||||
}
|
||||
if (liveMemory != null) {
|
||||
liveMemory.clearCache();
|
||||
}
|
||||
addrMap.memoryMapChanged(this);
|
||||
}
|
||||
|
||||
|
@ -359,10 +355,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
|
||||
@Override
|
||||
public AddressSetView getLoadedAndInitializedAddressSet() {
|
||||
if (liveMemory != null) {
|
||||
return this; // all memory is initialized!
|
||||
}
|
||||
|
||||
MemoryAddressSetViews localAddrSetViews = buildAddressSets(false);
|
||||
return new AddressSetViewAdapter(localAddrSetViews.initializedAndLoaded);
|
||||
}
|
||||
|
@ -586,29 +578,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
return defaultEndian == BIG_ENDIAN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLiveMemoryHandler(LiveMemoryHandler handler) {
|
||||
lock.acquire();
|
||||
try {
|
||||
if (liveMemory != null) {
|
||||
liveMemory.removeLiveMemoryListener(this);
|
||||
}
|
||||
liveMemory = handler;
|
||||
if (liveMemory != null) {
|
||||
liveMemory.addLiveMemoryListener(this);
|
||||
}
|
||||
program.invalidate();
|
||||
}
|
||||
finally {
|
||||
lock.release();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveMemoryHandler getLiveMemoryHandler() {
|
||||
return liveMemory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryBlock createInitializedBlock(String name, Address start, long size,
|
||||
byte initialValue, TaskMonitor monitor, boolean overlay) throws LockException,
|
||||
|
@ -976,10 +945,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
lock.acquire();
|
||||
try {
|
||||
program.checkExclusiveAccess();
|
||||
if (liveMemory != null) {
|
||||
throw new MemoryBlockException(
|
||||
"Memory move operation not permitted while live memory is active");
|
||||
}
|
||||
checkBlock(block);
|
||||
MemoryBlockDB memBlock = (MemoryBlockDB) block;
|
||||
|
||||
|
@ -1026,10 +991,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
lock.acquire();
|
||||
try {
|
||||
program.checkExclusiveAccess();
|
||||
if (liveMemory != null) {
|
||||
throw new MemoryBlockException(
|
||||
"Memory split operation not permitted while live memory is active");
|
||||
}
|
||||
checkBlock(block);
|
||||
MemoryBlockDB memBlock = (MemoryBlockDB) block;
|
||||
if (!memBlock.contains(addr)) {
|
||||
|
@ -1115,10 +1076,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
throws MemoryBlockException, LockException {
|
||||
|
||||
program.checkExclusiveAccess();
|
||||
if (liveMemory != null) {
|
||||
throw new MemoryBlockException(
|
||||
"Memory join operation not permitted while live memory is active");
|
||||
}
|
||||
|
||||
checkBlockForJoining(block1);
|
||||
checkBlockForJoining(block2);
|
||||
|
@ -1433,9 +1390,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
|
||||
@Override
|
||||
public byte getByte(Address addr) throws MemoryAccessException {
|
||||
if (liveMemory != null) {
|
||||
return liveMemory.getByte(addr);
|
||||
}
|
||||
MemoryBlock block = getBlockDB(addr);
|
||||
if (block == null) {
|
||||
throw new MemoryAccessException(
|
||||
|
@ -1452,9 +1406,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
@Override
|
||||
public int getBytes(Address addr, byte[] dest, int dIndex, int size)
|
||||
throws MemoryAccessException {
|
||||
if (liveMemory != null) {
|
||||
return liveMemory.getBytes(addr, dest, dIndex, size);
|
||||
}
|
||||
int numRead = 0;
|
||||
long lastRead = 0;
|
||||
while (numRead < size) {
|
||||
|
@ -1685,11 +1636,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
|
||||
@Override
|
||||
public void setByte(Address addr, byte value) throws MemoryAccessException {
|
||||
if (liveMemory != null) {
|
||||
liveMemory.putByte(addr, value);
|
||||
fireBytesChanged(addr, 1);
|
||||
return;
|
||||
}
|
||||
lock.acquire();
|
||||
try {
|
||||
MemoryBlock block = getBlock(addr);
|
||||
|
@ -1714,12 +1660,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
@Override
|
||||
public void setBytes(Address address, byte[] source, int sIndex, int size)
|
||||
throws MemoryAccessException {
|
||||
if (liveMemory != null) {
|
||||
int cnt = liveMemory.putBytes(address, source, sIndex, size);
|
||||
fireBytesChanged(address, cnt);
|
||||
return;
|
||||
}
|
||||
|
||||
lock.acquire();
|
||||
try {
|
||||
Address addr = address;
|
||||
|
@ -2149,11 +2089,6 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
|
|||
return super.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void memoryChanged(Address addr, int size) {
|
||||
fireBytesChanged(addr, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AddressRangeIterator getAddressRanges(Address start, boolean forward) {
|
||||
return allAddrSet.getAddressRanges(start, forward);
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.program.model.mem;
|
||||
|
||||
import ghidra.program.model.address.Address;
|
||||
|
||||
/**
|
||||
* Live memory handler interface.
|
||||
*/
|
||||
public interface LiveMemoryHandler {
|
||||
|
||||
/**
|
||||
* Called when the memory map is re-initializing. Usually after an undo or redo.
|
||||
*/
|
||||
public void clearCache();
|
||||
|
||||
/**
|
||||
* Gets the byte at the given address.
|
||||
* @param addr the address of the byte to be retrieved
|
||||
* @return the byte at the given address.
|
||||
* @throws MemoryAccessException if the byte can't be read.
|
||||
*/
|
||||
public byte getByte(Address addr) throws MemoryAccessException;
|
||||
|
||||
/**
|
||||
* Get the bytes at the given address and size and put them into the destination buffer.
|
||||
* @param address the address of the first byte to be retrieved.
|
||||
* @param buffer the byte buffer in which to place the bytes.
|
||||
* @param startIndex the starting index in the buffer to put the first byte.
|
||||
* @param size the number of bytes to retrieve and put in the buffer.
|
||||
* @return the number of bytes placed into the given buffer.
|
||||
* @throws MemoryAccessException if the bytes can't be read.
|
||||
*/
|
||||
public int getBytes(Address address, byte[] buffer, int startIndex, int size) throws MemoryAccessException;
|
||||
|
||||
/**
|
||||
* Writes the given byte value to the address in memory.
|
||||
* @param address the address whose byte is to be updated to the new value.
|
||||
* @param value the value to set at the given address.
|
||||
* @throws MemoryAccessException if the value can not be written to the memory.
|
||||
*/
|
||||
public void putByte(Address address, byte value) throws MemoryAccessException;
|
||||
|
||||
/**
|
||||
* Writes the given bytes to memory starting at the given address.
|
||||
* @param address the address in memory to write the bytes.
|
||||
* @param source the buffer containing the byte values to be written to memory.
|
||||
* @param startIndex the starting index in the buffer to get byte values.
|
||||
* @param size the number of bytes to write to memory.
|
||||
* @return the number of bytes written to memory.
|
||||
* @throws MemoryAccessException if the bytes can't be written to memory.
|
||||
*/
|
||||
public int putBytes(Address address, byte[] source, int startIndex, int size) throws MemoryAccessException;
|
||||
|
||||
/**
|
||||
* Adds a LiveMemoryListener to this handler. The listener will be notified when memory
|
||||
* bytes change.
|
||||
* @param listener the listener to be notified of memory byte value changes.
|
||||
*/
|
||||
public void addLiveMemoryListener(LiveMemoryListener listener);
|
||||
|
||||
/**
|
||||
* Removes the LiveMemoryListener from this handler.
|
||||
* @param listener the listener to be removed.
|
||||
*/
|
||||
public void removeLiveMemoryListener(LiveMemoryListener listener);
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package ghidra.program.model.mem;
|
||||
|
||||
import ghidra.program.model.address.Address;
|
||||
|
||||
public interface LiveMemoryListener {
|
||||
public void memoryChanged(Address addr, int size);
|
||||
}
|
|
@ -151,18 +151,6 @@ public interface Memory extends AddressSetView {
|
|||
return block != null && block.isExternalBlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the live memory handler
|
||||
* @param handler the live memory handler
|
||||
*/
|
||||
public void setLiveMemoryHandler(LiveMemoryHandler handler);
|
||||
|
||||
/**
|
||||
* Returns the live memory handler instance used by this memory.
|
||||
* @return the live memory handler
|
||||
*/
|
||||
public LiveMemoryHandler getLiveMemoryHandler();
|
||||
|
||||
/**
|
||||
* Create an initialized memory block based upon a data {@link InputStream} and add it to
|
||||
* this Memory.
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -175,16 +175,6 @@ public class StubMemory extends AddressSet implements Memory {
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLiveMemoryHandler(LiveMemoryHandler handler) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiveMemoryHandler getLiveMemoryHandler() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemoryBlock createInitializedBlock(String name, Address start, InputStream is,
|
||||
long length, TaskMonitor monitor, boolean overlay) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue