From 85e0af69c4cec25b13b3bf42b71d0a2b8db040ec Mon Sep 17 00:00:00 2001 From: ghidra1 Date: Thu, 5 May 2022 22:52:33 -0400 Subject: [PATCH] GP-2002 simplified AddressMap interface --- .../map/AbstractAddressRangeMapTest.java | 4 +- .../feature/vt/db/AddressMapTestDummy.java | 51 +------------- .../program/database/map/AddressMap.java | 66 ------------------- .../program/database/map/AddressMapDB.java | 58 ++++++++-------- .../map/AddressMapDBAdapterNoTable.java | 50 +------------- 5 files changed, 34 insertions(+), 195 deletions(-) diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/map/AbstractAddressRangeMapTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/map/AbstractAddressRangeMapTest.java index c16f790e46..a328fabcb6 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/map/AbstractAddressRangeMapTest.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/program/database/map/AbstractAddressRangeMapTest.java @@ -40,7 +40,7 @@ public abstract class AbstractAddressRangeMapTest extends AbstractGhidraHeadedIn private TestEnv env; // needed to discover languages private ProgramDB program; - private AddressMap addrMap; + private AddressMapDB addrMap; private AddressSpace space; private int txId; @@ -55,7 +55,7 @@ public abstract class AbstractAddressRangeMapTest extends AbstractGhidraHeadedIn program = createProgram(); MemoryMapDB memory = program.getMemory(); - addrMap = (AddressMap) getInstanceField("addrMap", memory); + addrMap = (AddressMapDB) getInstanceField("addrMap", memory); space = program.getAddressFactory().getDefaultAddressSpace(); spaceMax = space.getMaxAddress(); ErrorHandler errHandler = e -> fail(); diff --git a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/db/AddressMapTestDummy.java b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/db/AddressMapTestDummy.java index 576c89a32b..4fdbd53d3b 100644 --- a/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/db/AddressMapTestDummy.java +++ b/Ghidra/Features/VersionTracking/src/test/java/ghidra/feature/vt/db/AddressMapTestDummy.java @@ -15,16 +15,13 @@ */ 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.List; import ghidra.program.database.map.AddressMap; import ghidra.program.model.address.*; -import ghidra.program.model.lang.Language; -import ghidra.program.util.LanguageTranslator; public class AddressMapTestDummy implements AddressMap { @@ -33,11 +30,6 @@ public class AddressMapTestDummy implements AddressMap { return addr(value); } - @Override - public void deleteOverlaySpace(String name) throws IOException { - throw new RuntimeException("Unimplmented!"); - } - @Override public int findKeyRange(List keyRangeList, Address addr) { throw new RuntimeException("Unimplmented!"); @@ -92,55 +84,14 @@ public class AddressMapTestDummy implements AddressMap { return list; } - @Override - public int getModCount() { - throw new RuntimeException("Unimplmented!"); - } - @Override public AddressMap getOldAddressMap() { 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 public boolean isUpgraded() { 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!"); - } - } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMap.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMap.java index c8024eee4c..2f8d0196c7 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMap.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMap.java @@ -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); } diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java index ab180107ac..8fc1578742 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDB.java @@ -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 { lastBaseAddress = null; 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). * 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; @@ -616,30 +620,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(); @@ -709,7 +698,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(); @@ -723,11 +715,6 @@ public class AddressMapDB implements AddressMap { baseImageOffset = base.getOffset(); } - @Override - public synchronized int getModCount() { - return baseAddrs.length; - } - @Override public int findKeyRange(List keyRangeList, Address addr) { // 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); } - @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 { @@ -993,13 +986,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(); diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDBAdapterNoTable.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDBAdapterNoTable.java index 81e9d45551..688254c3bc 100644 --- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDBAdapterNoTable.java +++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/map/AddressMapDBAdapterNoTable.java @@ -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