Ghidra is a software reverse engineering (SRE) framework
GP-1 Change Range class to be long based instead of int based
ghidragon6a90e9903907
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.javaindex 6b5bf8870d..bc23ca0348 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/AreaMarkerSet.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -97,8 +97,8 @@ class AreaMarkerSet extends MarkerSetImpl {g.setColor(markerColor);for (Range range : rangeList) {- int startY = range.min;- int endY = range.max;+ int startY = range.getMinAsInt();+ int endY = range.getMaxAsInt();int len = endY - startY;if (len < MARKER_HEIGHT) {len = MARKER_HEIGHT;diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.javaindex 1897c2865c..63059ca7d9 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/marker/PointMarkerSet.java@@ -137,8 +137,8 @@ class PointMarkerSet extends MarkerSetImpl {g.setColor(markerColor);for (Range range : rangeList) {- int startY = range.min;- int endY = range.max;+ int startY = range.getMinAsInt();+ int endY = range.getMaxAsInt();if ((endY - startY) % 2 != 0) {endY--;}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/FieldMatcher.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/FieldMatcher.javaindex 4edfae1d22..c5178ab186 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/FieldMatcher.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/FieldMatcher.java@@ -104,7 +104,7 @@ public class FieldMatcher {return null;}- int offset = fieldOffsets.getMin();+ int offset = fieldOffsets.getMinAsInt();if (dataType instanceof Structure) {Structure structure = (Structure) dataType;DataTypeComponent dtc = structure.getComponentContaining(offset);diff --git a/Ghidra/Features/Base/src/test.slow/java/docking/widgets/dialogs/NumberRangeInputDialogTest.java b/Ghidra/Features/Base/src/test.slow/java/docking/widgets/dialogs/NumberRangeInputDialogTest.javaindex 2ec455a8c9..cd94e7dd16 100644--- a/Ghidra/Features/Base/src/test.slow/java/docking/widgets/dialogs/NumberRangeInputDialogTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/docking/widgets/dialogs/NumberRangeInputDialogTest.java@@ -186,7 +186,7 @@ public class NumberRangeInputDialogTest extends AbstractDockingTest {}for (Range range : ranges) {- for (int value : range) {+ for (long value : range) {assertTrue("Range value not expected: " + value, set.contains(value));}}diff --git a/Ghidra/Features/DataGraph/src/main/java/datagraph/data/graph/panel/DataVertexPanel.java b/Ghidra/Features/DataGraph/src/main/java/datagraph/data/graph/panel/DataVertexPanel.javaindex 85d4216a81..b1821a6756 100644--- a/Ghidra/Features/DataGraph/src/main/java/datagraph/data/graph/panel/DataVertexPanel.java+++ b/Ghidra/Features/DataGraph/src/main/java/datagraph/data/graph/panel/DataVertexPanel.java@@ -603,7 +603,7 @@ public class DataVertexPanel extends JPanel {private List<Address> getVisibleAddresses() {Range visibleRows = gTrable.getVisibleRows();List<Address> visiblePaths = new ArrayList<>((int) visibleRows.size());- for (int i = visibleRows.min; i <= visibleRows.max; i++) {+ for (int i = visibleRows.getMinAsInt(); i <= visibleRows.max; i++) {DataRowObject displayRow = model.getRow(i);Data data = displayRow.getData();visiblePaths.add(data.getAddress());@@ -615,7 +615,7 @@ public class DataVertexPanel extends JPanel {private List<int[]> getVisibleDataPaths() {Range visibleRows = gTrable.getVisibleRows();List<int[]> visiblePaths = new ArrayList<>((int) visibleRows.size());- for (int i = visibleRows.min; i <= visibleRows.max; i++) {+ for (int i = visibleRows.getMinAsInt(); i <= visibleRows.max; i++) {DataRowObject displayRow = model.getRow(i);Data data = displayRow.getData();visiblePaths.add(data.getComponentPath());diff --git a/Ghidra/Framework/Docking/src/test/java/docking/widgets/trable/GTrableTest.java b/Ghidra/Framework/Docking/src/test/java/docking/widgets/trable/GTrableTest.javaindex 4a6aa6c930..71eaa02aec 100644--- a/Ghidra/Framework/Docking/src/test/java/docking/widgets/trable/GTrableTest.java+++ b/Ghidra/Framework/Docking/src/test/java/docking/widgets/trable/GTrableTest.java@@ -250,7 +250,7 @@ public class GTrableTest extends AbstractGuiTest {private void assertVisibleRows(String... expectedRows) {Range visibleRows = gTrable.getVisibleRows();- List<String> actualRows = getRowsAsText(visibleRows.min, visibleRows.max);+ List<String> actualRows = getRowsAsText((int) visibleRows.min, (int) visibleRows.max);assertEquals(expectedRows.length, actualRows.size());List<String> expectedList = Arrays.asList(expectedRows);assertListEqualOrdered(expectedList, actualRows);diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/SortedRangeList.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/SortedRangeList.javaindex c9502608e0..5f3403b3f3 100644--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/SortedRangeList.java+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/datastruct/SortedRangeList.java@@ -17,6 +17,8 @@ package ghidra.util.datastruct;import java.util.*;+import ghidra.util.exception.AssertException;+/*** Provides a list of integer ranges that are maintained in sorted order. When a range is added* any ranges that overlap or are adjacent to one another will coalesce into a single range.@@ -50,7 +52,7 @@ public class SortedRangeList implements Iterable<Range> {* @param min the range minimum* @param max the range maximum (inclusive)*/- public void addRange(int min, int max) {+ public void addRange(long min, long max) {Range key = new Range(min, min);SortedSet<Range> headSet = set.headSet(key);if (!headSet.isEmpty()) {@@ -105,30 +107,54 @@ public class SortedRangeList implements Iterable<Range> {}/**- * Returns the minimum int value in this sorted range list.+ * Returns the minimum long value in this sorted range list.* @return the min value* @throws NoSuchElementException if the list is empty.*/- public int getMin() throws NoSuchElementException {+ public long getMin() throws NoSuchElementException {Range r = set.first();return r.min;}/**- * Returns the maximum int value in this sorted range list.+ * Returns the maximum long value in this sorted range list.* @return the max value* @throws NoSuchElementException if the list is empty.*/- public int getMax() throws NoSuchElementException {+ public long getMax() throws NoSuchElementException {Range r = set.last();return r.max;}+ /**+ * Returns the minimum value in this sorted range list as an int. This method should only be+ * used when you know that only int values are placed in this SortedRangeMap.+ * @return the min value+ * @throws NoSuchElementException if the list is empty.+ * @throws AssertException if the value is not in range of an int value.+ */+ public int getMinAsInt() throws NoSuchElementException {+ Range r = set.first();+ return r.getMinAsInt();+ }++ /**+ * Returns the maximum value in this sorted range list as an int. This method should only be+ * used when you know that only int values are placed in this SortedRangeMap.+ * @return the max value+ * @throws NoSuchElementException if the list is empty.+ * @throws AssertException if the value is not in range of an int value.+ */+ public int getMaxAsInt() throws NoSuchElementException {+ Range r = set.last();+ return r.getMaxAsInt();+ }+/*** Returns the number of ranges in the list.* @return the number of ranges*/- public int getNumRanges() {+ public long getNumRanges() {return set.size();}@@ -138,7 +164,7 @@ public class SortedRangeList implements Iterable<Range> {* @param min the minimum value for the range to remove.* @param max the maximum value for the range to remove.*/- public void removeRange(int min, int max) {+ public void removeRange(long min, long max) {Range key = new Range(min, min);SortedSet<Range> headSet = set.headSet(key);if (!headSet.isEmpty()) {@@ -187,7 +213,7 @@ public class SortedRangeList implements Iterable<Range> {* @param value the value to check for.* @return true if the value is contained in any ranges within this list.*/- public boolean contains(int value) {+ public boolean contains(long value) {Range key = new Range(value, value);SortedSet<Range> head = set.headSet(key);if (!head.isEmpty()) {@@ -198,7 +224,7 @@ public class SortedRangeList implements Iterable<Range> {return set.contains(key);}- private Range getRangeContaining(int value) {+ private Range getRangeContaining(long value) {Range key = new Range(value, value);SortedSet<Range> head = set.headSet(key);if (!head.isEmpty()) {@@ -223,7 +249,7 @@ public class SortedRangeList implements Iterable<Range> {* @param max the maximum value* @return true if a single range contains all the values from min to max.*/- public boolean contains(int min, int max) {+ public boolean contains(long min, long max) {Range range = getRangeContaining(min);if (range != null) {return range.contains(max);@@ -236,7 +262,7 @@ public class SortedRangeList implements Iterable<Range> {* @param value the value to look for.* @return the range index or a negative value if the range list doesn't contain the value.*/- public int getRangeIndex(int value) {+ public int getRangeIndex(long value) {Range key = new Range(value, value);SortedSet<Range> head = set.headSet(key);int index = head.size() - 1;@@ -276,7 +302,7 @@ public class SortedRangeList implements Iterable<Range> {/*** Gets the total number of int values in this range.- * @return the number of int values.+ * @return the number of long values.*/public long getNumValues() {Iterator<Range> it = set.iterator();@@ -296,7 +322,7 @@ public class SortedRangeList implements Iterable<Range> {* @return true if the range from min to max intersects (overlaps) any ranges in this sorted* range list.*/- public boolean intersects(int min, int max) {+ public boolean intersects(long min, long max) {Range key = new Range(min, min);SortedSet<Range> head = set.headSet(key);if (!head.isEmpty()) {diff --git a/Ghidra/Framework/Utility/src/main/java/ghidra/util/datastruct/Range.java b/Ghidra/Framework/Utility/src/main/java/ghidra/util/datastruct/Range.javaindex 5379451ff9..3c449d77bb 100644--- a/Ghidra/Framework/Utility/src/main/java/ghidra/util/datastruct/Range.java+++ b/Ghidra/Framework/Utility/src/main/java/ghidra/util/datastruct/Range.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -16,16 +16,18 @@package ghidra.util.datastruct;import java.util.Iterator;-import java.util.stream.IntStream;+import java.util.stream.LongStream;++import ghidra.util.exception.AssertException;/*** A class for holding a minimum and maximum signed int values that define a range.*/-public class Range implements Comparable<Range>, Iterable<Integer> {+public class Range implements Comparable<Range>, Iterable<Long> {/** The range's minimum extent. */- public int min;+ public long min;/** The range's maximum extent (inclusive). */- public int max;+ public long max;/*** Creates a range whose extent is from min to max.@@ -33,7 +35,7 @@ public class Range implements Comparable<Range>, Iterable<Integer> {* @param max the maximum extent (inclusive).* @throws IllegalArgumentException if max is less than min.*/- public Range(int min, int max) {+ public Range(long min, long max) {if (max < min) {throw new IllegalArgumentException("Range max (" + max + ") cannot be less than min (" + min + ").");@@ -77,7 +79,7 @@ public class Range implements Comparable<Range>, Iterable<Integer> {* @param value the value to check.* @return true if the value is within the ranges extent.*/- public boolean contains(int value) {+ public boolean contains(long value) {return value >= min && value <= max;}@@ -86,11 +88,54 @@ public class Range implements Comparable<Range>, Iterable<Integer> {* @return the size*/public long size() {- return (long) max - (long) min + 1;+ return max - min + 1;}@Override- public Iterator<Integer> iterator() {- return IntStream.range(min, max + 1).iterator();+ public Iterator<Long> iterator() {+ return LongStream.range(min, max + 1).iterator();+ }++ /**+ * {@return the max value in this range}+ */+ public long getMax() {+ return max;+ }++ /**+ * {@return the min value in this range}+ */+ public long getMin() {+ return min;}++ /**+ * Returns the min value as in int value. This should only be used when you know that only+ * int values are possible. If the min value is not within the range of an int value,+ * an exception will be thrown.+ * @throws AssertException if the min value in not within the range of an int value.+ * @return the min value as an int value+ */+ public int getMinAsInt() {+ if (min > Integer.MAX_VALUE || min < Integer.MIN_VALUE) {+ throw new AssertException("Expected min value to be in the integer range");+ }+ return (int) max;+ }++ /**+ * Returns the max value as in int value. This should only be used when you know that only+ * int values are possible. If the max value is not within the range of an int value,+ * an exception will be thrown.+ * @throws AssertException if the max value in not within the range of an int value.+ * @return the max value as an int value+ */+ public int getMaxAsInt() {+ if (max > Integer.MAX_VALUE || max < Integer.MIN_VALUE) {+ throw new AssertException("Expected max value to be in the integer range");+ }+ return (int) max;+ }+}