mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-2002 simplified AddressMap interface
This commit is contained in:
@@ -40,7 +40,7 @@ public abstract class AbstractAddressRangeMapTest extends AbstractGhidraHeadedIn
|
|||||||
|
|
||||||
private TestEnv env; // needed to discover languages
|
private TestEnv env; // needed to discover languages
|
||||||
private ProgramDB program;
|
private ProgramDB program;
|
||||||
private AddressMap addrMap;
|
private AddressMapDB addrMap;
|
||||||
private AddressSpace space;
|
private AddressSpace space;
|
||||||
private int txId;
|
private int txId;
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ public abstract class AbstractAddressRangeMapTest extends AbstractGhidraHeadedIn
|
|||||||
|
|
||||||
program = createProgram();
|
program = createProgram();
|
||||||
MemoryMapDB memory = program.getMemory();
|
MemoryMapDB memory = program.getMemory();
|
||||||
addrMap = (AddressMap) getInstanceField("addrMap", memory);
|
addrMap = (AddressMapDB) getInstanceField("addrMap", memory);
|
||||||
space = program.getAddressFactory().getDefaultAddressSpace();
|
space = program.getAddressFactory().getDefaultAddressSpace();
|
||||||
spaceMax = space.getMaxAddress();
|
spaceMax = space.getMaxAddress();
|
||||||
ErrorHandler errHandler = e -> fail();
|
ErrorHandler errHandler = e -> fail();
|
||||||
|
|||||||
@@ -15,16 +15,13 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.feature.vt.db;
|
package ghidra.feature.vt.db;
|
||||||
|
|
||||||
import static ghidra.feature.vt.db.VTTestUtils.addr;
|
import static ghidra.feature.vt.db.VTTestUtils.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
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.lang.Language;
|
|
||||||
import ghidra.program.util.LanguageTranslator;
|
|
||||||
|
|
||||||
public class AddressMapTestDummy implements AddressMap {
|
public class AddressMapTestDummy implements AddressMap {
|
||||||
|
|
||||||
@@ -33,11 +30,6 @@ public class AddressMapTestDummy implements AddressMap {
|
|||||||
return addr(value);
|
return addr(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteOverlaySpace(String name) throws IOException {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int findKeyRange(List<KeyRange> keyRangeList, Address addr) {
|
public int findKeyRange(List<KeyRange> keyRangeList, Address addr) {
|
||||||
throw new RuntimeException("Unimplmented!");
|
throw new RuntimeException("Unimplmented!");
|
||||||
@@ -92,55 +84,14 @@ public class AddressMapTestDummy implements AddressMap {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getModCount() {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AddressMap getOldAddressMap() {
|
public AddressMap getOldAddressMap() {
|
||||||
throw new RuntimeException("Unimplmented!");
|
throw new RuntimeException("Unimplmented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasSameKeyBase(long addrKey1, long addrKey2) {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidateCache() throws IOException {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMax(long addrKey) {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMin(long addrKey) {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUpgraded() {
|
public boolean isUpgraded() {
|
||||||
throw new RuntimeException("Unimplmented!");
|
throw new RuntimeException("Unimplmented!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renameOverlaySpace(String oldName, String newName) throws IOException {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setImageBase(Address base) {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLanguage(Language newLanguage, AddressFactory addrFactory,
|
|
||||||
LanguageTranslator translator) throws IOException {
|
|
||||||
throw new RuntimeException("Unimplmented!");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.program.database.map;
|
package ghidra.program.database.map;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import ghidra.program.model.address.*;
|
import ghidra.program.model.address.*;
|
||||||
import ghidra.program.model.lang.Language;
|
|
||||||
import ghidra.program.util.LanguageTranslator;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Address map interface add methods need by the program database implementation to manage its address map.
|
* Address map interface add methods need by the program database implementation to manage its address map.
|
||||||
@@ -169,72 +166,9 @@ public interface AddressMap {
|
|||||||
*/
|
*/
|
||||||
public boolean isUpgraded();
|
public boolean isUpgraded();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the image base, effectively changing the mapping between addresses and longs.
|
|
||||||
* @param base the new base address.
|
|
||||||
*/
|
|
||||||
public void setImageBase(Address base);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a modification number that always increases when the address map base table has
|
|
||||||
* changed.
|
|
||||||
*/
|
|
||||||
public int getModCount();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current image base setting.
|
* Returns the current image base setting.
|
||||||
*/
|
*/
|
||||||
public Address getImageBase();
|
public Address getImageBase();
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts the current base addresses to addresses compatible with the new language.
|
|
||||||
* @param newLanguage the new language to use.
|
|
||||||
* @param addrFactory the new AddressFactory.
|
|
||||||
* @param translator translates address spaces from the old language to the new language.
|
|
||||||
*/
|
|
||||||
public void setLanguage(Language newLanguage, AddressFactory addrFactory,
|
|
||||||
LanguageTranslator translator) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears any cached values.
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void invalidateCache() throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Rename an existing overlay space.
|
|
||||||
* @param oldName old overlay name
|
|
||||||
* @param newName new overlay name (must be unique among all space names within this map)
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void renameOverlaySpace(String oldName, String newName) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the specified overlay space from this address map.
|
|
||||||
* @param name overlay space name (must be unique among all space names within this map)
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void deleteOverlaySpace(String name) throws IOException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the two address keys share a common key base and can be
|
|
||||||
* used within a single key-range.
|
|
||||||
* @param addrKey1
|
|
||||||
* @param addrKey2
|
|
||||||
*/
|
|
||||||
public boolean hasSameKeyBase(long addrKey1, long addrKey2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the specified addrKey is the minimum key within
|
|
||||||
* its key-range.
|
|
||||||
* @param addrKey
|
|
||||||
*/
|
|
||||||
public boolean isKeyRangeMin(long addrKey);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the specified addrKey is the maximum key within
|
|
||||||
* its key-range.
|
|
||||||
* @param addrKey
|
|
||||||
*/
|
|
||||||
public boolean isKeyRangeMax(long addrKey);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -253,7 +253,10 @@ public class AddressMapDB implements AddressMap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Clears any cached values.
|
||||||
|
* @throws IOException if an IO error occurs
|
||||||
|
*/
|
||||||
public synchronized void invalidateCache() throws IOException {
|
public synchronized void invalidateCache() throws IOException {
|
||||||
lastBaseAddress = null;
|
lastBaseAddress = null;
|
||||||
if (!readOnly) {
|
if (!readOnly) {
|
||||||
@@ -491,6 +494,7 @@ public class AddressMapDB implements AddressMap {
|
|||||||
* @param useMemorySegmentation if true and the program's default address space is segmented (i.e., SegmentedAddressSpace).
|
* @param useMemorySegmentation if true and the program's default address space is segmented (i.e., SegmentedAddressSpace).
|
||||||
* the address returned will be normalized to defined segmented memory blocks if possible. This parameter should
|
* the address returned will be normalized to defined segmented memory blocks if possible. This parameter should
|
||||||
* generally always be true except when used by the Memory map objects to avoid recursion problems.
|
* generally always be true except when used by the Memory map objects to avoid recursion problems.
|
||||||
|
* @return decoded address
|
||||||
*/
|
*/
|
||||||
public synchronized Address decodeAddress(long value, boolean useMemorySegmentation) {
|
public synchronized Address decodeAddress(long value, boolean useMemorySegmentation) {
|
||||||
Address addr;
|
Address addr;
|
||||||
@@ -616,30 +620,15 @@ public class AddressMapDB implements AddressMap {
|
|||||||
* stack space. This makes bad stack addresses which previously existed
|
* stack space. This makes bad stack addresses which previously existed
|
||||||
* impossible to decode. Instead of return NO_ADDRESS, we will simply truncate such
|
* impossible to decode. Instead of return NO_ADDRESS, we will simply truncate such
|
||||||
* bad stack offsets to the MIN or MAX offsets.
|
* bad stack offsets to the MIN or MAX offsets.
|
||||||
* @param offset
|
* @param offset stack offset
|
||||||
* @param stackSpace
|
* @param stackSpace stack memory space
|
||||||
* @return
|
* @return truncated stack offset
|
||||||
*/
|
*/
|
||||||
private long truncateStackOffset(long offset, AddressSpace stackSpace) {
|
private long truncateStackOffset(long offset, AddressSpace stackSpace) {
|
||||||
return offset < 0 ? stackSpace.getMinAddress().getOffset()
|
return offset < 0 ? stackSpace.getMinAddress().getOffset()
|
||||||
: stackSpace.getMaxAddress().getOffset();
|
: stackSpace.getMaxAddress().getOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasSameKeyBase(long addrKey1, long addrKey2) {
|
|
||||||
return (addrKey1 >> ADDR_OFFSET_SIZE) == (addrKey2 >> ADDR_OFFSET_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMax(long addrKey) {
|
|
||||||
return (addrKey & ADDR_OFFSET_MASK) == MAX_OFFSET;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMin(long addrKey) {
|
|
||||||
return (addrKey & ADDR_OFFSET_MASK) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private long encodeRelative(Address addr, boolean addrIsNormalized, int indexOperation) {
|
private long encodeRelative(Address addr, boolean addrIsNormalized, int indexOperation) {
|
||||||
AddressSpace addressSpace = addr.getAddressSpace();
|
AddressSpace addressSpace = addr.getAddressSpace();
|
||||||
int type = addressSpace.getType();
|
int type = addressSpace.getType();
|
||||||
@@ -709,7 +698,10 @@ public class AddressMapDB implements AddressMap {
|
|||||||
return addrFactory;
|
return addrFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Sets the image base, effectively changing the mapping between addresses and longs.
|
||||||
|
* @param base the new base address.
|
||||||
|
*/
|
||||||
public void setImageBase(Address base) {
|
public void setImageBase(Address base) {
|
||||||
if (useOldAddrMap) {
|
if (useOldAddrMap) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
@@ -723,11 +715,6 @@ public class AddressMapDB implements AddressMap {
|
|||||||
baseImageOffset = base.getOffset();
|
baseImageOffset = base.getOffset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public synchronized int getModCount() {
|
|
||||||
return baseAddrs.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int findKeyRange(List<KeyRange> keyRangeList, Address addr) {
|
public int findKeyRange(List<KeyRange> keyRangeList, Address addr) {
|
||||||
// TODO: Will not handle mixed list of relative and absolute key ranges
|
// TODO: Will not handle mixed list of relative and absolute key ranges
|
||||||
@@ -952,7 +939,13 @@ public class AddressMapDB implements AddressMap {
|
|||||||
return defaultAddrSpace.getAddress(baseImageOffset);
|
return defaultAddrSpace.getAddress(baseImageOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Converts the current base addresses to addresses compatible with the new language.
|
||||||
|
* @param newLanguage the new language to use.
|
||||||
|
* @param addrFactory the new AddressFactory.
|
||||||
|
* @param translator translates address spaces from the old language to the new language.
|
||||||
|
* @throws IOException if IO error occurs
|
||||||
|
*/
|
||||||
public synchronized void setLanguage(Language newLanguage, AddressFactory addrFactory,
|
public synchronized void setLanguage(Language newLanguage, AddressFactory addrFactory,
|
||||||
LanguageTranslator translator) throws IOException {
|
LanguageTranslator translator) throws IOException {
|
||||||
|
|
||||||
@@ -993,13 +986,22 @@ public class AddressMapDB implements AddressMap {
|
|||||||
init(true);
|
init(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Rename an existing overlay space.
|
||||||
|
* @param oldName old overlay name
|
||||||
|
* @param newName new overlay name (must be unique among all space names within this map)
|
||||||
|
* @throws IOException if IO error occurs
|
||||||
|
*/
|
||||||
public synchronized void renameOverlaySpace(String oldName, String newName) throws IOException {
|
public synchronized void renameOverlaySpace(String oldName, String newName) throws IOException {
|
||||||
adapter.renameOverlaySpace(oldName, newName);
|
adapter.renameOverlaySpace(oldName, newName);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
|
* Delete the specified overlay space from this address map.
|
||||||
|
* @param name overlay space name (must be unique among all space names within this map)
|
||||||
|
* @throws IOException if IO error occurs
|
||||||
|
*/
|
||||||
public synchronized void deleteOverlaySpace(String name) throws IOException {
|
public synchronized void deleteOverlaySpace(String name) throws IOException {
|
||||||
adapter.deleteOverlaySpace(name);
|
adapter.deleteOverlaySpace(name);
|
||||||
invalidateCache();
|
invalidateCache();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
/* ###
|
/* ###
|
||||||
* IP: GHIDRA
|
* IP: GHIDRA
|
||||||
* REVIEWED: YES
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,14 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package ghidra.program.database.map;
|
package ghidra.program.database.map;
|
||||||
|
|
||||||
import ghidra.program.model.address.*;
|
|
||||||
import ghidra.program.model.lang.Language;
|
|
||||||
import ghidra.program.util.LanguageTranslator;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import db.DBHandle;
|
import db.DBHandle;
|
||||||
|
import ghidra.program.model.address.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adapter for when no addr map database existed.
|
* Adapter for when no addr map database existed.
|
||||||
@@ -113,21 +109,6 @@ class AddressMapDBAdapterNoTable extends AddressMapDBAdapter {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasSameKeyBase(long addrKey1, long addrKey2) {
|
|
||||||
return (addrKey1 >> 32) == (addrKey2 >> 32);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMax(long addrKey) {
|
|
||||||
return (addrKey & 0xffffffff) == 0xffffffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isKeyRangeMin(long addrKey) {
|
|
||||||
return (addrKey & 0xffffffff) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getKey(Address addr, boolean create) {
|
public long getKey(Address addr, boolean create) {
|
||||||
if (create) {
|
if (create) {
|
||||||
@@ -204,44 +185,15 @@ class AddressMapDBAdapterNoTable extends AddressMapDBAdapter {
|
|||||||
return factory.getDefaultAddressSpace().getAddress(0);
|
return factory.getDefaultAddressSpace().getAddress(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getModCount() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AddressMap getOldAddressMap() {
|
public AddressMap getOldAddressMap() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidateCache() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUpgraded() {
|
public boolean isUpgraded() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deleteOverlaySpace(String name) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void renameOverlaySpace(String oldName, String newName) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setImageBase(Address base) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setLanguage(Language newLanguage, AddressFactory addrFactory,
|
|
||||||
LanguageTranslator translator) {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user