Merge remote-tracking branch 'origin/GP-2002_ghidra1_SimplifyAddressMapInterface'

This commit is contained in:
Ryan Kurtz 2022-05-12 00:39:56 -04:00
commit cc2a6666cb
5 changed files with 34 additions and 195 deletions

View file

@ -15,12 +15,9 @@
*/
package ghidra.program.database.map;
import java.io.IOException;
import java.util.List;
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.
@ -169,72 +166,9 @@ public interface AddressMap {
*/
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.
*/
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);
}

View file

@ -232,7 +232,10 @@ public class AddressMapDB implements AddressMap {
}
}
@Override
/**
* Clears any cached values.
* @throws IOException if an IO error occurs
*/
public synchronized void invalidateCache() throws IOException {
lastBaseAddress = null;
if (!readOnly) {
@ -470,6 +473,7 @@ public class AddressMapDB implements AddressMap {
* @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
* 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) {
Address addr;
@ -595,30 +599,15 @@ public class AddressMapDB implements AddressMap {
* stack space. This makes bad stack addresses which previously existed
* impossible to decode. Instead of return NO_ADDRESS, we will simply truncate such
* bad stack offsets to the MIN or MAX offsets.
* @param offset
* @param stackSpace
* @return
* @param offset stack offset
* @param stackSpace stack memory space
* @return truncated stack offset
*/
private long truncateStackOffset(long offset, AddressSpace stackSpace) {
return offset < 0 ? stackSpace.getMinAddress().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) {
AddressSpace addressSpace = addr.getAddressSpace();
int type = addressSpace.getType();
@ -688,7 +677,10 @@ public class AddressMapDB implements AddressMap {
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) {
if (useOldAddrMap) {
throw new IllegalStateException();
@ -702,11 +694,6 @@ public class AddressMapDB implements AddressMap {
baseImageOffset = base.getOffset();
}
@Override
public synchronized int getModCount() {
return baseAddrs.length;
}
@Override
public int findKeyRange(List<KeyRange> keyRangeList, Address addr) {
// TODO: Will not handle mixed list of relative and absolute key ranges
@ -931,7 +918,13 @@ public class AddressMapDB implements AddressMap {
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,
LanguageTranslator translator) throws IOException {
@ -972,13 +965,22 @@ public class AddressMapDB implements AddressMap {
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 {
adapter.renameOverlaySpace(oldName, newName);
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 {
adapter.deleteOverlaySpace(name);
invalidateCache();

View file

@ -1,6 +1,5 @@
/* ###
* 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.
@ -16,14 +15,11 @@
*/
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.util.*;
import db.DBHandle;
import ghidra.program.model.address.*;
/**
* 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
public long getKey(Address addr, boolean create) {
if (create) {
@ -204,44 +185,15 @@ class AddressMapDBAdapterNoTable extends AddressMapDBAdapter {
return factory.getDefaultAddressSpace().getAddress(0);
}
@Override
public int getModCount() {
return 0;
}
@Override
public AddressMap getOldAddressMap() {
return this;
}
@Override
public void invalidateCache() {
}
@Override
public boolean isUpgraded() {
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