mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 09:49:23 +02:00
Merge remote-tracking branch 'origin/patch'
This commit is contained in:
commit
d83b7abdb1
3 changed files with 63 additions and 76 deletions
|
@ -378,35 +378,31 @@ public class CodeCompareAddressCorrelation implements AddressCorrelation {
|
|||
computeParamCorrelation();
|
||||
}
|
||||
|
||||
protected void computeParamCorrelation() {
|
||||
int sourceCount = sourceFunction.getParameterCount();
|
||||
int destinationCount = destinationFunction.getParameterCount();
|
||||
private void computeParamCorrelation() {
|
||||
Parameter[] sourceParameters = sourceFunction.getParameters();
|
||||
Parameter[] destinationParameters = destinationFunction.getParameters();
|
||||
boolean allMatch = false;
|
||||
if (sourceParameters.length != destinationParameters.length) {
|
||||
return;
|
||||
}
|
||||
Map<Address, CorrelationContainer> map = new HashMap<Address, CorrelationContainer>();
|
||||
if (sourceCount == destinationCount) {
|
||||
allMatch = true;
|
||||
for (int i = 0; i < sourceParameters.length; i++) {
|
||||
Parameter sourceParameter = sourceParameters[i];
|
||||
Parameter destinationParameter = destinationParameters[i];
|
||||
if (!sourceParameter.isValid() || !destinationParameter.isValid() ||
|
||||
sourceParameter.getLength() != destinationParameter.getLength()) {
|
||||
// - an invalid parameter does not have defined storage (or address)
|
||||
// - length must also match
|
||||
allMatch = false;
|
||||
break;
|
||||
if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
|
||||
return;
|
||||
}
|
||||
Address dest = destinationParameter.getVariableStorage().getMinAddress();
|
||||
Address src = sourceParameter.getVariableStorage().getMinAddress();
|
||||
VariableStorage sourceParamStorage = sourceParameter.getVariableStorage();
|
||||
VariableStorage destParamStorage = destinationParameter.getVariableStorage();
|
||||
if (!sourceParamStorage.equals(destParamStorage)) {
|
||||
return;
|
||||
}
|
||||
Address dest = sourceParamStorage.getMinAddress();
|
||||
Address src = destParamStorage.getMinAddress();
|
||||
map.put(src, new CorrelationContainer(CorrelationKind.PARAMETERS,
|
||||
new AddressRangeImpl(dest, dest)));
|
||||
}
|
||||
}
|
||||
if (allMatch) {
|
||||
cachedForwardAddressMap.putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
private void defineRange(Map<CodeUnit, TreeSet<AddressRange>> sourceMap,
|
||||
Map<CodeUnit, TreeSet<AddressRange>> destinationMap, CodeUnitContainer sourceCodeUnit,
|
||||
|
|
|
@ -15,16 +15,14 @@
|
|||
*/
|
||||
package ghidra.feature.vt.api.correlator.address;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.Parameter;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.util.AddressCorrelation;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class LinearFunctionAddressCorrelation implements AddressCorrelation {
|
||||
|
||||
public static final String NAME = "LinearFunctionAddressCorrelation";
|
||||
|
@ -103,32 +101,29 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
|
|||
return srcBody.getMaxAddress();
|
||||
}
|
||||
|
||||
protected void computeParamCorrelation() {
|
||||
int sourceCount = sourceFunction.getParameterCount();
|
||||
int destinationCount = destinationFunction.getParameterCount();
|
||||
private void computeParamCorrelation() {
|
||||
Parameter[] sourceParameters = sourceFunction.getParameters();
|
||||
Parameter[] destinationParameters = destinationFunction.getParameters();
|
||||
boolean allMatch = false;
|
||||
if (sourceParameters.length != destinationParameters.length) {
|
||||
return;
|
||||
}
|
||||
Map<Address, AddressRange> map = new HashMap<Address, AddressRange>();
|
||||
if (sourceCount == destinationCount) {
|
||||
allMatch = true;
|
||||
for (int i = 0; i < sourceParameters.length; i++) {
|
||||
Parameter sourceParameter = sourceParameters[i];
|
||||
Parameter destinationParameter = destinationParameters[i];
|
||||
DataType sourceDataType = sourceParameter.getDataType();
|
||||
DataType destinationDataType = destinationParameter.getDataType();
|
||||
int sourceLength = sourceDataType.getLength();
|
||||
int destinationLength = destinationDataType.getLength();
|
||||
Address dest = destinationParameter.getMinAddress();
|
||||
map.put(sourceParameter.getMinAddress(), new AddressRangeImpl(dest, dest));
|
||||
if (sourceLength != destinationLength) {
|
||||
allMatch = false;
|
||||
break;
|
||||
if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
|
||||
return;
|
||||
}
|
||||
VariableStorage sourceParamStorage = sourceParameter.getVariableStorage();
|
||||
VariableStorage destParamStorage = destinationParameter.getVariableStorage();
|
||||
if (!sourceParamStorage.equals(destParamStorage)) {
|
||||
return;
|
||||
}
|
||||
Address dest = sourceParamStorage.getMinAddress();
|
||||
Address src = destParamStorage.getMinAddress();
|
||||
map.put(src, new AddressRangeImpl(dest, dest));
|
||||
}
|
||||
if (allMatch) {
|
||||
cachedForwardAddressMap.putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
*/
|
||||
package ghidra.feature.vt.api.correlator.address;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import ghidra.program.model.address.*;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.listing.*;
|
||||
import ghidra.program.util.*;
|
||||
import ghidra.program.util.AddressCorrelation;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Generate address correlations by viewing each function as a list of instructions in address order
|
||||
* Instructions are paired one at a time, in order, if the mnemonics of the instructions match.
|
||||
|
@ -93,34 +93,30 @@ public class StraightLineCorrelation implements AddressCorrelation {
|
|||
/**
|
||||
* Add address correlations for the parameters.
|
||||
*/
|
||||
protected void computeParamCorrelation() {
|
||||
int sourceCount = sourceFunction.getParameterCount();
|
||||
int destinationCount = destinationFunction.getParameterCount();
|
||||
private void computeParamCorrelation() {
|
||||
Parameter[] sourceParameters = sourceFunction.getParameters();
|
||||
Parameter[] destinationParameters = destinationFunction.getParameters();
|
||||
boolean allMatch = false;
|
||||
if (sourceParameters.length != destinationParameters.length) {
|
||||
return;
|
||||
}
|
||||
Map<Address, AddressRange> map = new HashMap<Address, AddressRange>();
|
||||
if (sourceCount == destinationCount) {
|
||||
allMatch = true;
|
||||
for (int i = 0; i < sourceParameters.length; i++) {
|
||||
Parameter sourceParameter = sourceParameters[i];
|
||||
Parameter destinationParameter = destinationParameters[i];
|
||||
DataType sourceDataType = sourceParameter.getDataType();
|
||||
DataType destinationDataType = destinationParameter.getDataType();
|
||||
int sourceLength = sourceDataType.getLength();
|
||||
int destinationLength = destinationDataType.getLength();
|
||||
Address dest = destinationParameter.getMinAddress();
|
||||
map.put(sourceParameter.getMinAddress(), new AddressRangeImpl(dest, dest));
|
||||
if (sourceLength != destinationLength) {
|
||||
allMatch = false;
|
||||
break;
|
||||
if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
|
||||
return;
|
||||
}
|
||||
VariableStorage sourceParamStorage = sourceParameter.getVariableStorage();
|
||||
VariableStorage destParamStorage = destinationParameter.getVariableStorage();
|
||||
if (!sourceParamStorage.equals(destParamStorage)) {
|
||||
return;
|
||||
}
|
||||
Address dest = sourceParamStorage.getMinAddress();
|
||||
Address src = destParamStorage.getMinAddress();
|
||||
map.put(src, new AddressRangeImpl(dest, dest));
|
||||
}
|
||||
if (allMatch) {
|
||||
cachedForwardAddressMap.putAll(map);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save address correlation between two code units to the map
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue