Ghidra is a software reverse engineering (SRE) framework
GT-2872 - Search - review fixes
dragonmacher8a7a58a2970b
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.javaindex 4c608b84be..c2c4ffe6c6 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/searchtext/databasesearcher/ProgramDatabaseSearcher.java@@ -55,10 +55,14 @@ import ghidra.util.task.TaskMonitor;*/public class ProgramDatabaseSearcher implements Searcher {+private List<ProgramDatabaseFieldSearcher> searchers = new ArrayList<>();private Address currentAddress;private boolean isForward;private SearchOptions searchOptions;++ private long totalSearchCount;+ private AddressSet remainingAddresses;private TaskMonitor monitor;public ProgramDatabaseSearcher(ServiceProvider serviceProvider, Program program,@@ -74,7 +78,7 @@ public class ProgramDatabaseSearcher implements Searcher {initialize(serviceProvider, program, startLoc, set, options);currentAddress = findNextSignificantAddress();- monitor.initialize(set.getNumAddresses());+ monitor.initialize(totalSearchCount);}@Override@@ -105,8 +109,22 @@ public class ProgramDatabaseSearcher implements Searcher {return; // finished}- int diff = (int) Math.abs(newAddress.subtract(lastAddress));- monitor.incrementProgress(diff);+ AddressSpace lastSpace = lastAddress.getAddressSpace();+ AddressSpace newSpace = newAddress.getAddressSpace();+ if (!lastSpace.equals(newSpace)) {+ remainingAddresses.delete(lastSpace.getMinAddress(), lastSpace.getMaxAddress());+ }++ Address from = newSpace.getMinAddress();+ Address to = newAddress.subtract(1);+ if (!isForward) {+ to = newSpace.getMaxAddress();+ from = newAddress.add(1);+ }++ remainingAddresses.delete(from, to);+ long progress = totalSearchCount - remainingAddresses.getNumAddresses();+ monitor.setProgress(progress);}@Override@@ -129,6 +147,7 @@ public class ProgramDatabaseSearcher implements Searcher {nextAddress = isForward ? getMin(nextAddress, nextAddressToCheck): getMax(nextAddress, nextAddressToCheck);}+return nextAddress;}@@ -160,6 +179,8 @@ public class ProgramDatabaseSearcher implements Searcher {AddressSetView trimmedSet = adjustSearchSet(program, start, view, forward);ProgramLocation adjustedStart = adjustStartLocation(program, start, trimmedSet, forward);+ remainingAddresses = new AddressSet(trimmedSet);+ totalSearchCount = trimmedSet.getNumAddresses();Pattern pattern =UserSearchUtils.createSearchPattern(options.getText(), options.isCaseSensitive());diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.javaindex 5973654cfa..86aa76494c 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/Address.java@@ -165,12 +165,11 @@ public interface Address extends Comparable<Address> {public int getSize();/**- * Calculates the displacement between two addresses (<code>this -- * addr</code>).- *- * @param addr the Address to subtract from <code>this</code> address.- * @return the difference. (thisAddress.offset - thatAddress.offset+ * Calculates the displacement between two addresses (<code>this - addr</code>)*+ * @param addr the Address to subtract from <code>this</code> address+ * @return the difference (thisAddress.offset - thatAddress.offset)+ * @throws IllegalArgumentException if the two addresses are not in the same address space*/public long subtract(Address addr);diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/AddressSet.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/AddressSet.javaindex fb180c52cc..178aa2bdf8 100644--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/AddressSet.java+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/address/AddressSet.java@@ -29,7 +29,7 @@ import ghidra.util.datastruct.RedBlackTree;public class AddressSet implements AddressSetView {private final static double LOGBASE2 = Math.log(2);- private RedBlackTree<Address, Address> rbTree = new RedBlackTree<Address, Address>();+ private RedBlackTree<Address, Address> rbTree = new RedBlackTree<>();private RedBlackEntry<Address, Address> lastNode;private long addressCount = 0;@@ -282,7 +282,7 @@ public class AddressSet implements AddressSetView {/*** Deletes a range of addresses from this set* @param start the starting address of the range to be removed- * @param end the ending address of the range to be removed+ * @param end the ending address of the range to be removed (inclusive)*/public final void delete(Address start, Address end) {if (start.compareTo(end) > 0) {@@ -403,7 +403,7 @@ public class AddressSet implements AddressSetView {* @return a list of the AddressRanges in this set.*/public List<AddressRange> toList() {- ArrayList<AddressRange> list = new ArrayList<AddressRange>();+ ArrayList<AddressRange> list = new ArrayList<>();for (AddressRange range : this) {list.add(range);}