AnalyzerType.INSTRUCTIONS. It is also useful for
* those analyzers that depend on code, but want to analyze flow, such as non-returning
* functions, that should happen before functions are widely laid down. If
- * bad flow is not fixed at an early priority, switch stmt recovery, function
+ * bad flow is not fixed at an early priority, switch statement recovery, function
* boundaries, etc... may need to be redone and bad stuff cleaned up.
*/
public final static AnalysisPriority CODE_ANALYSIS = DISASSEMBLY.getNext("CODE");
@@ -114,8 +113,8 @@ public class AnalysisPriority {
DATA_ANALYSIS.getNext("FUNCTION ID");
/**
- * Defines data type propogation as the ninth priority for automatic analysis.
- * Data type propogation analysis should hapen as late as possible so that all basic code
+ * Defines data type propagation as the ninth priority for automatic analysis.
+ * Data type propagation analysis should happen as late as possible so that all basic code
* recovery, reference analysis, etc... has taken place.
*/
public final static AnalysisPriority DATA_TYPE_PROPOGATION =
@@ -136,6 +135,7 @@ public class AnalysisPriority {
/**
* Construct a new priority object.
+ * @param name the name
* @param priority priority to use
*/
public AnalysisPriority(String name, int priority) {
@@ -145,6 +145,7 @@ public class AnalysisPriority {
/**
* Return the priority specified for this analysis priority.
+ * @return the priority specified for this analysis priority.
*/
public int priority() {
return priority;
@@ -160,7 +161,7 @@ public class AnalysisPriority {
}
/**
- * Get a piority that is a little lower than this one.
+ * Get a priority that is a little lower than this one.
*
* @return a lower priority
*/
@@ -170,6 +171,7 @@ public class AnalysisPriority {
/**
* Return first gross priority.
+ * @param name the name
* @return first gross priority
*/
public static AnalysisPriority getInitial(String name) {
@@ -178,6 +180,7 @@ public class AnalysisPriority {
/**
* Get the next gross priority.
+ * @param nextName the next name
* @return return next gross priority
*/
public AnalysisPriority getNext(String nextName) {
diff --git a/Ghidra/Features/CodeCompare/src/main/java/ghidra/features/codecompare/correlator/CodeCompareAddressCorrelation.java b/Ghidra/Features/CodeCompare/src/main/java/ghidra/features/codecompare/correlator/CodeCompareAddressCorrelation.java
index d5f601330b..c2de2d952f 100755
--- a/Ghidra/Features/CodeCompare/src/main/java/ghidra/features/codecompare/correlator/CodeCompareAddressCorrelation.java
+++ b/Ghidra/Features/CodeCompare/src/main/java/ghidra/features/codecompare/correlator/CodeCompareAddressCorrelation.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.
@@ -31,6 +31,9 @@ import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
public class CodeCompareAddressCorrelation implements AddressCorrelation {
+
+ public static final String NAME = "CodeCompareAddressCorrelator";
+
static enum CorrelationKind {
CODE_COMPARE, LCS, PARAMETERS;
}
@@ -65,15 +68,16 @@ public class CodeCompareAddressCorrelation implements AddressCorrelation {
}
@Override
- public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor)
- throws CancelledException {
+ public AddressCorrelationRange getCorrelatedDestinationRange(Address sourceAddress,
+ TaskMonitor monitor) throws CancelledException {
initialize(monitor);
CorrelationContainer container = cachedForwardAddressMap.get(sourceAddress);
if (container == null) {
return null;
}
- return container.range;
+
+ return new AddressCorrelationRange(container.range, getName());
}
private static final Comparator+ * This interface supplies a {@link #getPriority() priority} of {@link #DEFAULT_PRIORITY}. + * {@link DiscoverableAddressCorrelator discoverable} correlators can change this priority to be a + * lower value to be run before the supplied system correlators. Generally, the more specific or + * restrictive a correlator, the earlier (higher priority) it should be. */ public interface AddressCorrelator { + /** + * The default priority. This applies to client-supplied {@link DiscoverableAddressCorrelator}s + */ + public static final int DEFAULT_PRIORITY = 500; + + /** + * A high priority (low number value) for correlators that should used before other correlators + */ + public static final int EARLY_PRIORITY = 100; + + /** + * A low priority (high number value) for correlators that should used after other correlators + */ + public static final int LATE_CHANCE_PRIORITY = 1000; + + /** + * A value used to raise or lower priorities. + */ + public static final int PRIORITY_OFFSET = 10; + /** * Returns an address mapping from one function to another. * @param sourceFunction the source function. @@ -61,4 +86,18 @@ public interface AddressCorrelator { * @return the options with the default settings for this correlator. */ public Options getDefaultOptions(); + + /** + * Returns a number based on an arbitrary number scheme that dictates the order that correlators + * should be used. If a correlator returns a null value from one of the {@code correlate()} + * methods, then the next highest priority correlator will be called, and so on until a non-null + * correlation is found or all correlators have been called. + *
+ * A lower number value is a higher priority. See {@link #DEFAULT_PRIORITY}.
+ *
+ * @return the priority
+ */
+ public default int getPriority() {
+ return DEFAULT_PRIORITY;
+ }
}
diff --git a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearDataAddressCorrelation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearDataAddressCorrelation.java
index 235601b33d..1899e9d42d 100644
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearDataAddressCorrelation.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearDataAddressCorrelation.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.
@@ -15,7 +15,8 @@
*/
package ghidra.program.util;
-import ghidra.program.model.address.*;
+import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressRangeImpl;
import ghidra.program.model.listing.Data;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -30,13 +31,14 @@ public class LinearDataAddressCorrelation implements AddressCorrelation {
}
@Override
- public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor)
- throws CancelledException {
+ public AddressCorrelationRange getCorrelatedDestinationRange(Address sourceAddress,
+ TaskMonitor monitor) throws CancelledException {
long offset = sourceAddress.getOffset();
long base = sourceData.getAddress().getOffset();
long delta = offset - base;
Address address = destinationData.getAddress().add(delta);
- return new AddressRangeImpl(address, address);
+ AddressRangeImpl range = new AddressRangeImpl(address, address);
+ return new AddressCorrelationRange(range, getName());
}
@Override
diff --git a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/address/LinearFunctionAddressCorrelation.java b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearFunctionAddressCorrelation.java
similarity index 88%
rename from Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/address/LinearFunctionAddressCorrelation.java
rename to Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearFunctionAddressCorrelation.java
index c8b5d77b20..bfcc84a9f4 100644
--- a/Ghidra/Features/VersionTracking/src/main/java/ghidra/feature/vt/api/correlator/address/LinearFunctionAddressCorrelation.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/LinearFunctionAddressCorrelation.java
@@ -4,22 +4,22 @@
* 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package ghidra.feature.vt.api.correlator.address;
+package ghidra.program.util;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Map;
import ghidra.program.model.address.*;
import ghidra.program.model.listing.*;
-import ghidra.program.util.AddressCorrelation;
import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor;
@@ -31,7 +31,7 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
private final Function sourceFunction;
private final Function destinationFunction;
- LinearFunctionAddressCorrelation(Function sourceFunction, Function destinationFunction) {
+ public LinearFunctionAddressCorrelation(Function sourceFunction, Function destinationFunction) {
this.sourceFunction = sourceFunction;
this.destinationFunction = destinationFunction;
}
@@ -42,8 +42,8 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
}
@Override
- public AddressRange getCorrelatedDestinationRange(Address sourceAddress, TaskMonitor monitor)
- throws CancelledException {
+ public AddressCorrelationRange getCorrelatedDestinationRange(Address sourceAddress,
+ TaskMonitor monitor) throws CancelledException {
initialize(monitor);
AddressRange toRange = cachedForwardAddressMap.get(sourceAddress);
if (toRange == null) {
@@ -51,7 +51,7 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
Address destinationAddress = getDestinationAddress(percentOffset);
toRange = new AddressRangeImpl(destinationAddress, destinationAddress);
}
- return toRange;
+ return new AddressCorrelationRange(toRange, getName());
}
private void initialize(TaskMonitor monitor) {
@@ -66,9 +66,7 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
long accumulatedLength = 0;
- Iterator