Merge remote-tracking branch 'origin/GP-1679-dragonmacher-navigation-actions-update--SQUASHED'

This commit is contained in:
Ryan Kurtz 2022-03-07 14:00:40 -05:00
commit 42ce259932
24 changed files with 1804 additions and 1492 deletions

View file

@ -31,12 +31,9 @@ import ghidra.program.model.util.CodeUnitInsertionException;
import ghidra.program.model.util.PropertyMap;
import ghidra.util.exception.*;
import ghidra.util.task.TaskMonitor;
import ghidra.util.task.TaskMonitorAdapter;
/**
* Database implementation of Listing.
*
*
*/
class ListingDB implements Listing {
@ -45,9 +42,6 @@ class ListingDB implements Listing {
private TreeManager treeMgr;
private FunctionManager functionMgr;
/**
* Set the program.
*/
public void setProgram(ProgramDB program) {
this.program = program;
codeMgr = program.getCodeManager();
@ -55,261 +49,165 @@ class ListingDB implements Listing {
functionMgr = program.getFunctionManager();
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitAt(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getCodeUnitAt(Address addr) {
return codeMgr.getCodeUnitAt(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitContaining(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getCodeUnitContaining(Address addr) {
return codeMgr.getCodeUnitContaining(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitAfter(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getCodeUnitAfter(Address addr) {
return codeMgr.getCodeUnitAfter(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitBefore(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getCodeUnitBefore(Address addr) {
return codeMgr.getCodeUnitBefore(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String)
*/
@Override
public CodeUnitIterator getCodeUnitIterator(String property, boolean forward) {
return codeMgr.getCodeUnitIterator(property, program.getMinAddress(), forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String, ghidra.program.model.address.Address)
*/
@Override
public CodeUnitIterator getCodeUnitIterator(String property, Address addr, boolean forward) {
return codeMgr.getCodeUnitIterator(property, addr, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnitIterator(java.lang.String, ghidra.program.model.address.AddressSetView)
*/
@Override
public CodeUnitIterator getCodeUnitIterator(String property, AddressSetView addrSet,
boolean forward) {
return codeMgr.getCodeUnitIterator(property, addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnits()
*/
@Override
public CodeUnitIterator getCodeUnits(boolean forward) {
return codeMgr.getCodeUnits(program.getMemory(), forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnits(ghidra.program.model.address.Address)
*/
@Override
public CodeUnitIterator getCodeUnits(Address addr, boolean forward) {
return codeMgr.getCodeUnits(addr, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCodeUnits(ghidra.program.model.address.AddressSetView)
*/
@Override
public CodeUnitIterator getCodeUnits(AddressSetView addrSet, boolean forward) {
return codeMgr.getCodeUnits(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructionAt(ghidra.program.model.address.Address)
*/
@Override
public Instruction getInstructionAt(Address addr) {
return codeMgr.getInstructionAt(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructionContaining(ghidra.program.model.address.Address)
*/
@Override
public Instruction getInstructionContaining(Address addr) {
return codeMgr.getInstructionContaining(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructionAfter(ghidra.program.model.address.Address)
*/
@Override
public Instruction getInstructionAfter(Address addr) {
return codeMgr.getInstructionAfter(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructionBefore(ghidra.program.model.address.Address)
*/
@Override
public Instruction getInstructionBefore(Address addr) {
return codeMgr.getInstructionBefore(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructions()
*/
@Override
public InstructionIterator getInstructions(boolean forward) {
return codeMgr.getInstructions(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructions(ghidra.program.model.address.Address)
*/
@Override
public InstructionIterator getInstructions(Address addr, boolean forward) {
return codeMgr.getInstructions(addr, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getInstructions(ghidra.program.model.address.AddressSetView)
*/
@Override
public InstructionIterator getInstructions(AddressSetView addrSet, boolean forward) {
return codeMgr.getInstructions(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getDataAt(ghidra.program.model.address.Address)
*/
@Override
public Data getDataAt(Address addr) {
return codeMgr.getDataAt(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDataContaining(ghidra.program.model.address.Address)
*/
@Override
public Data getDataContaining(Address addr) {
return codeMgr.getDataContaining(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDataAfter(ghidra.program.model.address.Address)
*/
@Override
public Data getDataAfter(Address addr) {
return codeMgr.getDataAfter(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDataBefore(ghidra.program.model.address.Address)
*/
@Override
public Data getDataBefore(Address addr) {
return codeMgr.getDataBefore(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getData()
*/
@Override
public DataIterator getData(boolean forward) {
return codeMgr.getData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
/**
* @see ghidra.program.model.listing.Listing#getData(ghidra.program.model.address.Address)
*/
@Override
public DataIterator getData(Address addr, boolean forward) {
return codeMgr.getData(addr, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getData(ghidra.program.model.address.AddressSetView)
*/
@Override
public DataIterator getData(AddressSetView addrSet, boolean forward) {
return codeMgr.getData(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedDataAt(ghidra.program.model.address.Address)
*/
@Override
public Data getDefinedDataAt(Address addr) {
return codeMgr.getDefinedDataAt(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedDataContaining(ghidra.program.model.address.Address)
*/
@Override
public Data getDefinedDataContaining(Address addr) {
return codeMgr.getDefinedDataContaining(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedDataAfter(ghidra.program.model.address.Address)
*/
@Override
public Data getDefinedDataAfter(Address addr) {
return codeMgr.getDefinedDataAfter(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedDataBefore(ghidra.program.model.address.Address)
*/
@Override
public Data getDefinedDataBefore(Address addr) {
return codeMgr.getDefinedDataBefore(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedData()
*/
@Override
public DataIterator getDefinedData(boolean forward) {
return codeMgr.getDefinedData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedData(ghidra.program.model.address.Address)
*/
@Override
public DataIterator getDefinedData(Address addr, boolean forward) {
return codeMgr.getDefinedData(addr, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedData(ghidra.program.model.address.AddressSetView)
*/
@Override
public DataIterator getDefinedData(AddressSetView addrSet, boolean forward) {
return codeMgr.getDefinedData(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getUndefinedDataAt(ghidra.program.model.address.Address)
*/
@Override
public Data getUndefinedDataAt(Address addr) {
return codeMgr.getUndefinedAt(addr);
@ -321,295 +219,190 @@ class ListingDB implements Listing {
return codeMgr.getUndefinedRanges(set, initializedMemoryOnly, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#getUndefinedDataAfter(ghidra.program.model.address.Address)
*/
@Override
public Data getUndefinedDataAfter(Address addr, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedDataAfter(addr, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#getFirstUndefinedData(ghidra.program.model.address.AddressSetView)
*/
@Override
public Data getFirstUndefinedData(AddressSetView set, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedData(set, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#getUndefinedDataBefore(ghidra.program.model.address.Address)
*/
@Override
public Data getUndefinedDataBefore(Address addr, TaskMonitor monitor) {
return codeMgr.getFirstUndefinedDataBefore(addr, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#getCompositeData()
*/
@Override
public DataIterator getCompositeData(boolean forward) {
return codeMgr.getCompositeData(forward ? program.getMinAddress() : program.getMaxAddress(),
forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCompositeData(ghidra.program.model.address.Address)
*/
@Override
public DataIterator getCompositeData(Address start, boolean forward) {
return codeMgr.getCompositeData(start, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCompositeData(ghidra.program.model.address.AddressSetView)
*/
@Override
public DataIterator getCompositeData(AddressSetView addrSet, boolean forward) {
return codeMgr.getCompositeData(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getUserDefinedProperties()
*/
@Override
public Iterator<String> getUserDefinedProperties() {
return codeMgr.getUserDefinedProperties();
}
/**
* @see ghidra.program.model.listing.Listing#removeUserDefinedProperty(java.lang.String)
*/
@Override
public void removeUserDefinedProperty(String propertyName) {
codeMgr.removeUserDefinedProperty(propertyName);
}
/**
* @see ghidra.program.model.listing.Listing#getPropertyMap(java.lang.String)
*/
@Override
public PropertyMap getPropertyMap(String propertyName) {
return codeMgr.getPropertyMap(propertyName);
}
/**
* @see ghidra.program.model.listing.Listing#createInstruction(ghidra.program.model.address.Address, ghidra.program.model.lang.InstructionPrototype, ghidra.program.model.mem.MemBuffer, ghidra.program.model.lang.ProcessorContext)
*/
@Override
public Instruction createInstruction(Address addr, InstructionPrototype prototype,
MemBuffer memBuf, ProcessorContextView context) throws CodeUnitInsertionException {
return codeMgr.createCodeUnit(addr, prototype, memBuf, context);
}
/**
* @see ghidra.program.model.listing.Listing#addInstructions(ghidra.program.model.lang.InstructionSet, boolean)
*/
@Override
public AddressSetView addInstructions(InstructionSet instructionSet, boolean overwrite)
throws CodeUnitInsertionException {
return codeMgr.addInstructions(instructionSet, overwrite);
}
/**
*
* @see ghidra.program.model.listing.Listing#createData(ghidra.program.model.address.Address, ghidra.program.model.data.DataType)
*/
@Override
public Data createData(Address addr, DataType dataType)
throws CodeUnitInsertionException, DataTypeConflictException {
return codeMgr.createCodeUnit(addr, dataType, dataType.getLength());
}
/**
* @see ghidra.program.model.listing.Listing#createData(ghidra.program.model.address.Address, ghidra.program.model.data.DataType)
*/
@Override
public Data createData(Address addr, DataType dataType, int length)
throws CodeUnitInsertionException, DataTypeConflictException {
return codeMgr.createCodeUnit(addr, dataType, length);
}
/**
* @see ghidra.program.model.listing.Listing#clearCodeUnits(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean)
*/
@Override
public void clearCodeUnits(Address startAddr, Address endAddr, boolean clearContext) {
try {
codeMgr.clearCodeUnits(startAddr, endAddr, clearContext,
TaskMonitorAdapter.DUMMY_MONITOR);
TaskMonitor.DUMMY);
}
catch (CancelledException e) {
// can't happen with dummy monitor
}
}
/**
* @see ghidra.program.model.listing.Listing#clearCodeUnits(ghidra.program.model.address.Address, ghidra.program.model.address.Address, boolean, ghidra.util.task.TaskMonitor)
*/
@Override
public void clearCodeUnits(Address startAddr, Address endAddr, boolean clearContext,
TaskMonitor monitor) throws CancelledException {
codeMgr.clearCodeUnits(startAddr, endAddr, clearContext, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#isUndefined(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
*/
@Override
public boolean isUndefined(Address start, Address end) {
return codeMgr.isUndefined(start, end);
}
/**
* @see ghidra.program.model.listing.Listing#clearComments(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
*/
@Override
public void clearComments(Address startAddr, Address endAddr) {
codeMgr.clearComments(startAddr, endAddr);
}
/**
* @see ghidra.program.model.listing.Listing#clearProperties(ghidra.program.model.address.Address, ghidra.program.model.address.Address)
*/
@Override
public void clearProperties(Address startAddr, Address endAddr, TaskMonitor monitor)
throws CancelledException {
codeMgr.clearProperties(startAddr, endAddr, monitor);
}
/**
* @see ghidra.program.model.listing.Listing#clearAll(boolean, TaskMonitor)
*/
@Override
public void clearAll(boolean clearContext, TaskMonitor monitor) {
codeMgr.clearAll(false, TaskMonitorAdapter.DUMMY_MONITOR);
codeMgr.clearAll(false, TaskMonitor.DUMMY);
}
/**
* @see ghidra.program.model.listing.Listing#getNumCodeUnits()
*/
@Override
public long getNumCodeUnits() {
return getNumDefinedData() + getNumInstructions();
}
/**
* @see ghidra.program.model.listing.Listing#getNumDefinedData()
*/
@Override
public long getNumDefinedData() {
return codeMgr.getNumDefinedData();
}
/**
* @see ghidra.program.model.listing.Listing#getNumInstructions()
*/
@Override
public long getNumInstructions() {
return codeMgr.getNumInstructions();
}
/**
* @see ghidra.program.model.listing.Listing#getFragment(java.lang.String, ghidra.program.model.address.Address)
*/
@Override
public ProgramFragment getFragment(String treeName, Address addr) {
return treeMgr.getFragment(treeName, addr);
}
/**
* @see ghidra.program.model.listing.Listing#getModule(java.lang.String, java.lang.String)
*/
@Override
public ProgramModule getModule(String treeName, String name) {
return treeMgr.getModule(treeName, name);
}
/**
* @see ghidra.program.model.listing.Listing#getFragment(java.lang.String, java.lang.String)
*/
@Override
public ProgramFragment getFragment(String treeName, String name) {
return treeMgr.getFragment(treeName, name);
}
/**
* @see ghidra.program.model.listing.Listing#createRootModule(java.lang.String)
*/
@Override
public ProgramModule createRootModule(String treeName) throws DuplicateNameException {
return treeMgr.createRootModule(treeName);
}
/**
* @see ghidra.program.model.listing.Listing#getRootModule(java.lang.String)
*/
@Override
public ProgramModule getRootModule(String treeName) {
return treeMgr.getRootModule(treeName);
}
/**
* @see ghidra.program.model.listing.Listing#getRootModule(long)
*/
@Override
public ProgramModule getRootModule(long treeID) {
return treeMgr.getRootModule(treeID);
}
/**
* @see ghidra.program.model.listing.Listing#getRootModule(long)
*/
@Override
public ProgramModule getDefaultRootModule() {
return treeMgr.getDefaultRootModule();
}
/**
* @see ghidra.program.model.listing.Listing#getTreeNames()
*/
@Override
public String[] getTreeNames() {
return treeMgr.getTreeNames();
}
/**
* @see ghidra.program.model.listing.Listing#removeTree(java.lang.String)
*/
@Override
public boolean removeTree(String treeName) {
return treeMgr.removeTree(treeName);
}
/**
* @see ghidra.program.model.listing.Listing#renameTree(java.lang.String, java.lang.String)
*/
@Override
public void renameTree(String oldName, String newName) throws DuplicateNameException {
treeMgr.renameTree(oldName, newName);
}
/**
* @see ghidra.program.model.listing.Listing#getDataTypeManager()
*/
@Override
public DataTypeManager getDataTypeManager() {
return program.getDataTypeManager();
}
/* (non-Javadoc)
* @see ghidra.program.model.listing.Listing#createFunction(java.lang.String, ghidra.program.model.address.Address, ghidra.program.model.address.AddressSetView, int)
*/
@Override
public Function createFunction(String name, Address entryPoint, AddressSetView body,
SourceType source) throws InvalidInputException, OverlappingFunctionException {
return functionMgr.createFunction(name, entryPoint, body, source);
}
/* (non-Javadoc)
* @see ghidra.program.model.listing.Listing#createFunction(java.lang.String, ghidra.program.model.symbol.Namespace, ghidra.program.model.address.Address, ghidra.program.model.address.AddressSetView, int)
*/
@Override
public Function createFunction(String name, Namespace nameSpace, Address entryPoint,
AddressSetView body, SourceType source)
@ -617,17 +410,11 @@ class ListingDB implements Listing {
return functionMgr.createFunction(name, nameSpace, entryPoint, body, source);
}
/**
* @see ghidra.program.model.listing.Listing#removeFunction(ghidra.program.model.address.Address)
*/
@Override
public void removeFunction(Address entryPoint) {
functionMgr.removeFunction(entryPoint);
}
/**
* @see ghidra.program.model.listing.Listing#getFunctionAt(ghidra.program.model.address.Address)
*/
@Override
public Function getFunctionAt(Address entryPoint) {
return functionMgr.getFunctionAt(entryPoint);
@ -662,9 +449,6 @@ class ListingDB implements Listing {
return list;
}
/**
* @see ghidra.program.model.listing.Listing#getFirstFunctionContaining(ghidra.program.model.address.Address)
*/
@Override
public Function getFunctionContaining(Address addr) {
return functionMgr.getFunctionContaining(addr);
@ -675,90 +459,57 @@ class ListingDB implements Listing {
return functionMgr.getExternalFunctions();
}
/**
* @see ghidra.program.model.listing.Listing#getFunctions(boolean)
*/
@Override
public FunctionIterator getFunctions(boolean forward) {
return functionMgr.getFunctions(forward);
}
/**
* @see ghidra.program.model.listing.Listing#getFunctions(ghidra.program.model.address.Address, boolean)
*/
@Override
public FunctionIterator getFunctions(Address start, boolean forward) {
return functionMgr.getFunctions(start, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getFunctions(ghidra.program.model.address.AddressSetView, boolean)
*/
@Override
public FunctionIterator getFunctions(AddressSetView asv, boolean forward) {
return functionMgr.getFunctions(asv, forward);
}
/**
* @see ghidra.program.model.listing.Listing#isInFunction(ghidra.program.model.address.Address)
*/
@Override
public boolean isInFunction(Address addr) {
return functionMgr.isInFunction(addr);
}
/**
* @see ghidra.program.model.listing.Listing#getCommentHistory(ghidra.program.model.address.Address, int)
*/
@Override
public CommentHistory[] getCommentHistory(Address addr, int commentType) {
return codeMgr.getCommentHistory(addr, commentType);
}
/**
* @see ghidra.program.model.listing.Listing#getCommentCodeUnitIterator(int, ghidra.program.model.address.AddressSetView)
*/
@Override
public CodeUnitIterator getCommentCodeUnitIterator(int commentType, AddressSetView addrSet) {
return codeMgr.getCommentCodeUnitIterator(commentType, addrSet);
}
/**
* @see ghidra.program.model.listing.Listing#getCommentAddressIterator(int, ghidra.program.model.address.AddressSetView, boolean)
*/
@Override
public AddressIterator getCommentAddressIterator(int commentType, AddressSetView addrSet,
boolean forward) {
return codeMgr.getCommentAddressIterator(commentType, addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getCommentAddressIterator(ghidra.program.model.address.AddressSetView, boolean)
*/
@Override
public AddressIterator getCommentAddressIterator(AddressSetView addrSet, boolean forward) {
return codeMgr.getCommentAddressIterator(addrSet, forward);
}
/**
* @see ghidra.program.model.listing.Listing#getComment(int, ghidra.program.model.address.Address)
*/
@Override
public String getComment(int commentType, Address address) {
return codeMgr.getComment(commentType, address);
}
/**
* @see ghidra.program.model.listing.Listing#setComment(ghidra.program.model.address.Address, int, java.lang.String)
*/
@Override
public void setComment(Address address, int commentType, String comment) {
codeMgr.setComment(address, commentType, comment);
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedCodeUnitAfter(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getDefinedCodeUnitAfter(Address addr) {
CodeUnit data = codeMgr.getDefinedDataAfter(addr);
@ -777,9 +528,6 @@ class ListingDB implements Listing {
return inst;
}
/**
* @see ghidra.program.model.listing.Listing#getDefinedCodeUnitBefore(ghidra.program.model.address.Address)
*/
@Override
public CodeUnit getDefinedCodeUnitBefore(Address addr) {
CodeUnit data = codeMgr.getDefinedDataBefore(addr);

View file

@ -50,7 +50,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
private boolean upgrade = false;
private Map<String, BookmarkType> typesByName = new TreeMap<String, BookmarkType>();
private Map<String, BookmarkType> typesByName = new TreeMap<>();
private ObjectArray typesArray = new ObjectArray();
private Lock lock;
@ -73,7 +73,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
bookmarkTypeAdapter = BookmarkTypeDBAdapter.getAdapter(handle, openMode);
int[] types = bookmarkTypeAdapter.getTypeIds();
bookmarkAdapter = BookmarkDBAdapter.getAdapter(handle, openMode, types, addrMap, monitor);
cache = new DBObjectCache<BookmarkDB>(100);
cache = new DBObjectCache<>(100);
}
@Override
@ -388,16 +388,6 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
boolean isSpecificType = type != null && type != BookmarkType.ALL_TYPES;
if (!isSpecificType) {
// no type specified; remove all
Iterator<String> iter = typesByName.keySet().iterator();
while (iter.hasNext()) {
removeBookmarks(iter.next());
}
return;
}
try {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesByName.get(type);
if (bmt.hasBookmarks()) {
@ -474,7 +464,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
int n = typesArray.getLastNonEmptyIndex();
List<Bookmark> list = new ArrayList<Bookmark>();
List<Bookmark> list = new ArrayList<>();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);
if (bmt != null && bmt.hasBookmarks()) {
@ -512,7 +502,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
lock.acquire();
try {
Bookmark[] bookmarks = null;
List<Bookmark> list = new ArrayList<Bookmark>();
List<Bookmark> list = new ArrayList<>();
BookmarkType bmt = getBookmarkType(type);
if (bmt != null && bmt.hasBookmarks()) {
getBookmarks(address, bmt.getTypeId(), list);
@ -681,18 +671,18 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
@Override
public Iterator<Bookmark> getBookmarksIterator(Address startAddress, boolean forward) {
List<PeekableIterator<Bookmark>> list = new ArrayList<PeekableIterator<Bookmark>>();
List<PeekableIterator<Bookmark>> list = new ArrayList<>();
int n = typesArray.getLastNonEmptyIndex();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);
if (bmt != null && bmt.hasBookmarks()) {
Iterator<Bookmark> bookmarksIterator =
getBookmarksIterator(startAddress, bmt, forward);
list.add(new WrappingPeekableIterator<Bookmark>(bookmarksIterator));
list.add(new WrappingPeekableIterator<>(bookmarksIterator));
}
}
return new MultiIterator<Bookmark>(list, forward);
return new MultiIterator<>(list, forward);
}
@Override
@ -880,7 +870,7 @@ public class BookmarkDBManager implements BookmarkManager, ErrorHandler, Manager
Iterator<Bookmark> bookmarkIt;
TotalIterator() {
List<BookmarkTypeDB> list = new ArrayList<BookmarkTypeDB>();
List<BookmarkTypeDB> list = new ArrayList<>();
int n = typesArray.getLastNonEmptyIndex();
for (int i = 0; i <= n; i++) {
BookmarkTypeDB bmt = (BookmarkTypeDB) typesArray.get(i);

View file

@ -21,7 +21,7 @@ import ghidra.program.model.address.*;
import ghidra.program.model.listing.*;
/**
* Combines an Instruction iterator and Data iterator into a codeunit iterator
* Combines an Instruction iterator and Data iterator into a code unit iterator
*/
class CodeUnitRecordIterator implements CodeUnitIterator {
@ -38,7 +38,7 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
/**
* Constructs a new CodeUnitRecordIterator
* @param codeMgr the code managaer
* @param codeMgr the code manager
* @param instIt the instruction iterator
* @param dataIt the data iterator
* @param set the address set (required)
@ -57,17 +57,11 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
}
/**
* @see java.util.Iterator#remove()
*/
@Override
public void remove() {
throw new UnsupportedOperationException();
}
/**
* @see ghidra.program.model.listing.CodeUnitIterator#hasNext()
*/
@Override
public boolean hasNext() {
if (nextCu == null) {
@ -76,9 +70,6 @@ class CodeUnitRecordIterator implements CodeUnitIterator {
return nextCu != null;
}
/**
* @see ghidra.program.model.listing.CodeUnitIterator#next()
*/
@Override
public CodeUnit next() {
if (hasNext()) {

View file

@ -62,7 +62,7 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
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<String, MemoryBlock>();
private HashMap<String, MemoryBlock> nameBlockMap = new HashMap<>();
private final static MemoryBlock NoBlock = new MemoryBlockStub(); // placeholder for no block, not given out
Lock lock;
@ -1257,8 +1257,13 @@ public class MemoryMapDB implements Memory, ManagerDB, LiveMemoryListener {
* Tests if the memory contains a sequence of contiguous bytes that match the given byte array
* at all bit positions where the mask contains an "on" bit. The test will be something like
*
* for(int i=0;i<bytes.length;i++) { if (bytes[i] != memory.getByte(addr+i) &amp; masks[i]) {
* return false; } } return false;
* <PRE>
* for(int i = 0; i &lt; bytes.length; i++) {
* if (bytes[i] != memory.getByte(addr+i) &amp; masks[i]) {
* return false;
* }
* }
* </PRE>
*
* @param addr The beginning address in memory to test against.
* @param bytes the array of bytes to test for.

View file

@ -18,23 +18,22 @@ package ghidra.program.model.address;
import java.math.BigInteger;
import ghidra.program.model.data.DataOrganization;
import ghidra.program.model.lang.Register;
/**
* An address represents a location in a program. Conceptually, addresses consist
* of an "address space" and an offset within that space. Many processors have only
* one "real" address space, but some have several spaces. Also, there are
* "artificial" address spaces used for analysis and representing other non-memory locations
* such as a register or an offset on the stack relative to a functions frame pointer.
*
* An address represents a location in a program. Conceptually, addresses consist of an
* "address space" and an offset within that space. Many processors have only one "real" address
* space, but some have several spaces. Also, there are "artificial" address spaces used for
* analysis and representing other non-memory locations such as a register or an offset on the
* stack relative to a functions frame pointer.
*/
public interface Address extends Comparable<Address> {
/**
* Address object representing an invalid address.
*/
public static final Address NO_ADDRESS = new SpecialAddress("NO ADDRESS");
/**
* Address object representing an extenal entry address.
* Address object representing an external entry address.
*/
public static final Address EXT_FROM_ADDRESS = new SpecialAddress("Entry Point");
/**
@ -43,14 +42,14 @@ public interface Address extends Comparable<Address> {
public final char SEPARATOR_CHAR = ':';
/**
* Creates a new Address by parsing a String representation of an address. The
* string may be either a simple number (just the offset part of an address) or take
* the form "addressSpaceName:offset". If the latter form is used, the
* "addressSpaceName" must match the name of the space for this address.
* Creates a new Address by parsing a String representation of an address. The string may be
* either a simple number (just the offset part of an address) or take the form
* "addressSpaceName:offset". If the latter form is used, the "addressSpaceName" must match
* the name of the space for this address.
*
* @param addrString the String to parse.
* @return the new Address if the string is a legally formed address or null
* if the string contains an address space name that does not match this address's space.
* @return the new Address if the string is a legally formed address or null if the string
* contains an address space name that does not match this address's space.
* @throws AddressFormatException if the string cannot be parsed or the
* parsed offset is larger than the size for this address' space.
*/
@ -68,71 +67,70 @@ public interface Address extends Comparable<Address> {
/**
* Returns a new address in this address's space with the given offset.
* NOTE: for those spaces with an addressable unit size other than 1, the address
* returned may not correspond to an addressable unit/word boundary if a byte-offset
* is specified.
* <P>NOTE: for those spaces with an addressable unit size other than 1, the address returned
* may not correspond to an addressable unit/word boundary if a byte-offset is specified.
*
* @param offset the offset for the new address.
* @param isAddressableWordOffset if true the specified offset is an addressable unit/word offset,
* otherwise offset is a byte offset. See {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* @param isAddressableWordOffset if true the specified offset is an addressable unit/word
* offset, otherwise offset is a byte offset. See
* {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* AddressSpace#getAddressableUnitSize()} to understand the distinction
* (i.e., wordOffset = byteOffset * addressableUnitSize).
* @return address with given offset
* @throws AddressOutOfBoundsException if the offset is less than 0 or greater
* than the max offset allowed for this space.
* @throws AddressOutOfBoundsException if the offset is less than 0 or greater than the max
* offset allowed for this space.
*/
Address getNewAddress(long offset, boolean isAddressableWordOffset)
throws AddressOutOfBoundsException;
/**
* Returns a new address in this address's space with the given offset. The specified
* offset will be truncated within the space and will not throw an exception.
* NOTE: for those spaces with an addressable unit size other than 1, the address
* returned may not correspond to a word boundary (addressable unit) if a byte-offset
* is specified.
* Returns a new address in this address's space with the given offset. The specified offset
* will be truncated within the space and will not throw an exception.
* <p>NOTE: for those spaces with an addressable unit size other than 1, the address returned
* may not correspond to a word boundary (addressable unit) if a byte-offset is specified.
* @param offset the offset for the new address.
* @param isAddressableWordOffset if true the specified offset is an addressable unit/word offset,
* otherwise offset is a byte offset. See {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* @param isAddressableWordOffset if true the specified offset is an addressable unit/word
* offset, otherwise offset is a byte offset. See
* {@link ghidra.program.model.address.AddressSpace#getAddressableUnitSize()
* AddressSpace#getAddressableUnitSize()} to understand the distinction
* (i.e., wordOffset = byteOffset * addressableUnitSize).
* (i.e., wordOffset = byteOffset * addressableUnitSize).
* @return address with given byte offset truncated to the physical space size
*/
Address getNewTruncatedAddress(long offset, boolean isAddressableWordOffset);
/**
* Returns the number of bytes needed to form a pointer to this address. The
* result will be one of {1,2,4,8}.
* @see DataOrganization#getPointerSize() for compiler-specific size of pointers stored in memory.
* Returns the number of bytes needed to form a pointer to this address. The result will be
* one of {1,2,4,8}.
* @return the pointer size
* @see DataOrganization#getPointerSize() for compiler-specific size of pointers stored in
* memory.
*/
public int getPointerSize();
/**
* Returns the address's successor. In most cases, this is equivalent
* to addr.add(1), but segmented addresses could span segments. The result
* of calling this on the highest address will result in a null return value.
* @return the next higher address, or null if already at the
* highest address.
* Returns the address's successor. In most cases, this is equivalent to addr.add(1), but
* segmented addresses could span segments. The result of calling this on the highest address
* will result in a null return value.
* @return the next higher address, or null if already at the highest address.
*/
public Address next();
/**
* Returns the address's predecessor. In most cases, this is equivalent to
* addr.subtract(1), but segmented addresses could span segments. The
* result of calling this on the lowest address will result in a null return value.
* @return the next lower address, or null if already at the
* lowest address.
* Returns the address's predecessor. In most cases, this is equivalent to addr.subtract(1),
* but segmented addresses could span segments. The result of calling this on the lowest
* address will result in a null return value.
* @return the next lower address, or null if already at the lowest address.
*/
public Address previous();
/**
* Get the offset of this Address.
*
* Get the offset of this Address.
* @return the offset of this Address.
*/
public long getOffset();
/**
* Get the offset of this Address as a BigInteger
*
* Get the offset of this Address as a BigInteger.
* @return the offset of this Address.
*/
public BigInteger getOffsetAsBigInteger();
@ -152,17 +150,21 @@ public interface Address extends Comparable<Address> {
/**
* Returns the address space associated with this address.
* @return the address space
*/
public AddressSpace getAddressSpace();
/**
* Return true if this address' address space is equal to the
* address space for addr.
* Return true if this address' address space is equal to the address space for addr.
* @param addr the address to check
* @return true if the same space
*/
public boolean hasSameAddressSpace(Address addr);
/** Returns the number of bits that are used to form the address. Thus
* the maximum offset for this address space will be 2^size-1.
/**
* Returns the number of bits that are used to form the address. Thus the maximum offset for
* this address space will be 2^size-1.
* @return the size
*/
public int getSize();
@ -176,10 +178,9 @@ public interface Address extends Comparable<Address> {
public long subtract(Address addr);
/**
* Creates a new address by subtracting the displacement from the current
* address. The new address will wrap in a manner that depends on the
* address space. For a generic address space this will wrap at the
* extents of the address space. For a segmented address space it will
* Creates a new address by subtracting the displacement from the current address. The new
* address will wrap in a manner that depends on the address space. For a generic address space
* this will wrap at the extents of the address space. For a segmented address space it will
* wrap at the extents of the segment.
*
* @param displacement the displacement to subtract.
@ -188,43 +189,41 @@ public interface Address extends Comparable<Address> {
public Address subtractWrap(long displacement);
/**
* Creates a new address by subtracting the displacement from the current
* address. If the offset is greater than the max offset of the address space, the high
* order bits are masked off, making the address wrap. For non-segmented addresses this
* will be the same as subtractWrap(). For segmented addresses, the address will wrap when
* the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
* Creates a new address by subtracting the displacement from the current address. If the
* offset is greater than the max offset of the address space, the high order bits are masked
* off, making the address wrap. For non-segmented addresses this will be the same as
* subtractWrap(). For segmented addresses, the address will wrap when the 20 bit (oxfffff)
* offset is exceeded, as opposed to when the segment offset is exceeded.
* @param displacement the displacement to add.
* @return The new Address formed by subtracting the displacement from this address's offset.
*/
public Address subtractWrapSpace(long displacement);
/**
* Creates a new Address by subtracting displacement from the
* Address. The Address will not wrap within the space and in fact will throw
* an exception if the result is less than the min address in this space or
* greater than the max address in this space.
* Creates a new Address by subtracting displacement from the Address. The Address will not
* wrap within the space and in fact will throw an exception if the result is less than the min
* address in this space or greater than the max address in this space.
*
* @param displacement the displacement to subtract.
* @return The new Address
* @throws AddressOverflowException if the offset in this Address would
* overflow due to this operation.
* @throws AddressOverflowException if the offset in this Address would overflow due to this
* operation.
*/
public Address subtractNoWrap(long displacement) throws AddressOverflowException;
/**
* Creates a new address (possibly in a new space) by subtracting the displacement to
* this address.
* Creates a new address (possibly in a new space) by subtracting the displacement to this
* address.
* @param displacement the amount to subtract from this offset.
* @return The address using the subtracted offset.
*/
public Address subtract(long displacement);
/**
* Creates a new address by adding the displacement to the current
* address. The new address will wrap in a manner that depends on the
* address space. For a generic address space this will wrap at the
* extents of the address space. For a segmented address space it will
* wrap at the extents of the segment.
* Creates a new address by adding the displacement to the current address. The new address
* will wrap in a manner that depends on the address space. For a generic address space this
* will wrap at the extents of the address space. For a segmented address space it will wrap at
* the extents of the segment.
*
* @param displacement the displacement to add.
* @return The new Address formed by adding the displacement to this address's offset.
@ -232,112 +231,110 @@ public interface Address extends Comparable<Address> {
public Address addWrap(long displacement);
/**
* Creates a new address by adding the displacement to the current
* address. If the offset is greater than the max offset of the address space, the high
* order bits are masked off, making the address wrap. For non-segmented addresses this
* will be the same as addWrap(). For segmented addresses, the address will wrap when
* the 20 bit (oxfffff) offset is exceeded, as opposed to when the segment offset is exceeded.
* Creates a new address by adding the displacement to the current address. If the offset is
* greater than the max offset of the address space, the high order bits are masked off, making
* the address wrap. For non-segmented addresses this will be the same as addWrap(). For
* segmented addresses, the address will wrap when the 20 bit (oxfffff) offset is exceeded, as
* opposed to when the segment offset is exceeded.
* @param displacement the displacement to add.
* @return The new Address formed by adding the displacement to this address's offset.
*/
public Address addWrapSpace(long displacement);
/**
* Creates a new Address with a displacement relative to this
* Address. The Address will not wrap around! An exception will be
* throw if the result is not within this address space.
* Creates a new Address with a displacement relative to this Address. The Address will not
* wrap around! An exception will be throw if the result is not within this address space.
*
* @param displacement the displacement to add.
* @return The new Address
* @throws AddressOverflowException if the offset in this Address would
* overflow (wrap around) due to this operation.
* @param displacement the displacement to add.
* @return the new address.
* @throws AddressOverflowException if the offset in this Address would overflow (wrap around)
* due to this operation.
*/
public Address addNoWrap(long displacement) throws AddressOverflowException;
public Address addNoWrap(BigInteger displacement) throws AddressOverflowException;
/**
* Creates a new address (possibly in a new space) by adding the displacement to
* this address.
* Creates a new address (possibly in a new space) by adding the displacement to this address.
* @param displacement the amount to add to this offset.
* @return The new address.
* @throws AddressOutOfBoundsException if wrapping is not supported by the
* corresponding address space and the addition causes an out-of-bounds
* error
* @throws AddressOutOfBoundsException if wrapping is not supported by the corresponding
* address space and the addition causes an out-of-bounds error
*/
public Address add(long displacement) throws AddressOutOfBoundsException;
/**
* Tests whether the given address immediately follows this address.
*
* @param addr the address to test.
* @param addr the address to test.
* @return true if the address follows this address.
*/
public boolean isSuccessor(Address addr);
/**
* Returns a String representation of the address in hex and padded
* to the appropriate size.
* Returns a String representation of the address in hex and padded to the appropriate size.
* @return the string
*/
@Override
public String toString();
/**
* Returns a String representation of the address using the
* given string as a prefix. Equivalent of prefix + ":" + toString(false)
* Returns a String representation of the address using the given string as a prefix.
* Equivalent of prefix + ":" + toString(false)
* @param prefix the string to prepend to the address string.
* @return the string
*/
public String toString(String prefix);
/**
* Returns a String representation that may include the address space name
* @param showAddressSpace true if the address space should be included in
* resulting string.
* @param showAddressSpace true if the address space should be included in resulting string.
* @return String the string representation of the address
*/
public String toString(boolean showAddressSpace);
/**
* Returns a String representation that may include the address space name and may or may
* not pad the address with leading zeros.
* @param showAddressSpace if true, the addressSpace name will be prepended to the address string.
* Returns a String representation that may include the address space name and may or may not
* pad the address with leading zeros.
* @param showAddressSpace if true, the addressSpace name will be prepended to the address
* string.
* @param pad if true, the address will be prepended with leading zeros to completely fill out
* the max digits the address could contain. If false, the address will be prepended only to make
* the number of hex digits at least 4.
* the max digits the address could contain. If false, the address will be prepended only to
* make the number of hex digits at least 4.
* @return the address as a String.
*/
public String toString(boolean showAddressSpace, boolean pad);
/**
* Returns a String representation that may include the address space name and may or may
* not pad the address with leading zeros.
* @param showAddressSpace if true, the addressSpace name will be prepended to the address string.
* @param minNumDigits specifies the minimum number of digits to use. If the address space size
* is less that minNumDigits, the address will be padded to the address space size. If the address
* space size is larger that minNumDigits, the address will be displayed with as many digits as
* necessary, but will contain leading zeros to make the address string have at least minNumDigits.
* Returns a String representation that may include the address space name and may or may not
* pad the address with leading zeros.
* @param showAddressSpace if true, the addressSpace name will be prepended to the address
* string.
* @param minNumDigits specifies the minimum number of digits to use. If the address space
* size is less that minNumDigits, the address will be padded to the address space size. If
* the address space size is larger that minNumDigits, the address will be displayed with as
* many digits as necessary, but will contain leading zeros to make the address string have at
* least minNumDigits.
* @return the address as a String.
*/
public String toString(boolean showAddressSpace, int minNumDigits);
/**
* Compares this Address to the specified object.
* The result is <code>true</code> if and only if the argument is not
* <code>null</code> and is a <code>Address</code> object that represents
* the same address as this object.
* Compares this Address to the specified object. The result is <code>true</code> if and only
* if the argument is not <code>null</code> and is a <code>Address</code> object that
* represents the same address as this object.
*
* @param o the object to compare this <code>String</code>
* against.
* @return <code>true</code> if the <code>Addresses</code>are equal;
* <code>false</code> otherwise.
* @param o the object to compare this <code>String</code> against.
* @return <code>true</code> if the <code>Addresses</code>are equal; <code>false</code>
* otherwise.
*/
@Override
public boolean equals(Object o);
/**
* Returns a hashcode for this Address. The hashcode for an
* <code>Address</code> should be a value such that two Address
* objects which are equal will return the same hashcode.
* This method should generally return the same value as getLong().
* Returns a hash code for this Address. The hash code for an <code>Address</code> should be a
* value such that two Address objects which are equal will return the same hash code. This
* method should generally return the same value as getLong().
*
* @return a hash code value for this object.
*/
@ -347,61 +344,69 @@ public interface Address extends Comparable<Address> {
/**
* Returns the physical Address that corresponds to this Address.
*
* @return address in a physical space corresponding to this
* address.
* @return address in a physical space corresponding to this address.
*/
public Address getPhysicalAddress();
/**
* Returns true if this address represents a location in memory
* Returns true if this address represents a location in memory.
* @return true if this address represents a location in memory.
*/
public boolean isMemoryAddress();
/**
* Returns true if this address represents an address in a loaded memory block
* Returns true if this address represents an address in a loaded memory block.
* @return true if this address represents an address in a loaded memory block.
*/
public boolean isLoadedMemoryAddress();
/**
* Returns true if this address represents an address not loaded in real memory (i.e. OTHER)
* Returns true if this address represents an address not loaded in real memory (i.e. OTHER).
* @return true if this address represents an address not loaded in real memory (i.e. OTHER).
*/
public boolean isNonLoadedMemoryAddress();
/**
* Returns true if this address represents a location in stack space
* Returns true if this address represents a location in stack space.
* @return true if this address represents a location in stack space.
*/
public boolean isStackAddress();
/**
* Returns true if this address represents a location in unique space
* Returns true if this address represents a location in unique space.
* @return true if this address represents a location in unique space.
*/
public boolean isUniqueAddress();
/**
* Returns true if this address represents a location in constant space
* Returns true if this address represents a location in constant space.
* @return true if this address represents a location in constant space.
*/
public boolean isConstantAddress();
/**
* Returns true if this address represents a location in the HASH space
* Returns true if this address represents a location in the HASH space.
* @return true if this address represents a location in the HASH space.
*/
public boolean isHashAddress();
/**
* Returns true if this address represents a location in the register space.
* <P>NOTE: It is important to note that a {@link Register} could reside within
* a memory space and not the register space in which case this method would return
* false for its address.
* <P>NOTE: It is important to note that a {@link Register} could reside within a memory space
* and not the register space in which case this method would return false for its address.
* @return true if a register address
*/
public boolean isRegisterAddress();
/**
* Returns true if this address represents a location in variable space
* Returns true if this address represents a location in variable space.
* @return true if this address represents a location in variable space.
*/
public boolean isVariableAddress();
/**
* Returns true if this address represents an external location in the external address space
* Returns true if this address represents an external location in the external address space.
* @return true if this address represents an external location in the external address space.
*/
public boolean isExternalAddress();

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.
@ -30,38 +29,43 @@ public interface BookmarkType {
public static final String ERROR = "Error";
public static final String WARNING = "Warning";
public static final String ANALYSIS = "Analysis";
public static final String ALL_TYPES = "All Bookmark Types";
/**
* Returns the type as a string
* Returns the type as a string.
* @return the type as a string.
*/
String getTypeString();
public String getTypeString();
/**
* Returns Icon associated with this type or null if one has not been
* set by a plugin.
* @return the icon.
*/
ImageIcon getIcon();
public ImageIcon getIcon();
/**
* Returns marker color associated with this type or null if one has not been
* set by a plugin.
* @return the color.
*/
Color getMarkerColor();
public Color getMarkerColor();
/**
* Returns marker priority associated with this type or -1 if one has not been
* set by a plugin.
* @return the priority.
*/
int getMarkerPriority();
public int getMarkerPriority();
/**
* Returns true if there is at least one bookmark defined for this type
* Returns true if there is at least one bookmark defined for this type.
* @return true if there is at least one bookmark defined for this type.
*/
boolean hasBookmarks();
public boolean hasBookmarks();
/**
* Returns the id associated with this bookmark type.
* @return the id associated with this bookmark type.
*/
int getTypeId();
public int getTypeId();
}