Merge remote-tracking branch 'origin/patch'

This commit is contained in:
Ryan Kurtz 2024-04-05 08:48:00 -04:00
commit d83b7abdb1
3 changed files with 63 additions and 76 deletions

View file

@ -378,34 +378,30 @@ public class CodeCompareAddressCorrelation implements AddressCorrelation {
computeParamCorrelation(); computeParamCorrelation();
} }
protected void computeParamCorrelation() { private void computeParamCorrelation() {
int sourceCount = sourceFunction.getParameterCount();
int destinationCount = destinationFunction.getParameterCount();
Parameter[] sourceParameters = sourceFunction.getParameters(); Parameter[] sourceParameters = sourceFunction.getParameters();
Parameter[] destinationParameters = destinationFunction.getParameters(); Parameter[] destinationParameters = destinationFunction.getParameters();
boolean allMatch = false; if (sourceParameters.length != destinationParameters.length) {
return;
}
Map<Address, CorrelationContainer> map = new HashMap<Address, CorrelationContainer>(); Map<Address, CorrelationContainer> map = new HashMap<Address, CorrelationContainer>();
if (sourceCount == destinationCount) { for (int i = 0; i < sourceParameters.length; i++) {
allMatch = true; Parameter sourceParameter = sourceParameters[i];
for (int i = 0; i < sourceParameters.length; i++) { Parameter destinationParameter = destinationParameters[i];
Parameter sourceParameter = sourceParameters[i]; if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
Parameter destinationParameter = destinationParameters[i]; return;
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;
}
Address dest = destinationParameter.getVariableStorage().getMinAddress();
Address src = sourceParameter.getVariableStorage().getMinAddress();
map.put(src, new CorrelationContainer(CorrelationKind.PARAMETERS,
new AddressRangeImpl(dest, dest)));
} }
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);
cachedForwardAddressMap.putAll(map);
}
} }
private void defineRange(Map<CodeUnit, TreeSet<AddressRange>> sourceMap, private void defineRange(Map<CodeUnit, TreeSet<AddressRange>> sourceMap,

View file

@ -15,16 +15,14 @@
*/ */
package ghidra.feature.vt.api.correlator.address; package ghidra.feature.vt.api.correlator.address;
import java.util.*;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.data.DataType; import ghidra.program.model.listing.*;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Parameter;
import ghidra.program.util.AddressCorrelation; import ghidra.program.util.AddressCorrelation;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.*;
public class LinearFunctionAddressCorrelation implements AddressCorrelation { public class LinearFunctionAddressCorrelation implements AddressCorrelation {
public static final String NAME = "LinearFunctionAddressCorrelation"; public static final String NAME = "LinearFunctionAddressCorrelation";
@ -103,32 +101,29 @@ public class LinearFunctionAddressCorrelation implements AddressCorrelation {
return srcBody.getMaxAddress(); return srcBody.getMaxAddress();
} }
protected void computeParamCorrelation() { private void computeParamCorrelation() {
int sourceCount = sourceFunction.getParameterCount();
int destinationCount = destinationFunction.getParameterCount();
Parameter[] sourceParameters = sourceFunction.getParameters(); Parameter[] sourceParameters = sourceFunction.getParameters();
Parameter[] destinationParameters = destinationFunction.getParameters(); Parameter[] destinationParameters = destinationFunction.getParameters();
boolean allMatch = false; if (sourceParameters.length != destinationParameters.length) {
return;
}
Map<Address, AddressRange> map = new HashMap<Address, AddressRange>(); Map<Address, AddressRange> map = new HashMap<Address, AddressRange>();
if (sourceCount == destinationCount) { for (int i = 0; i < sourceParameters.length; i++) {
allMatch = true; Parameter sourceParameter = sourceParameters[i];
for (int i = 0; i < sourceParameters.length; i++) { Parameter destinationParameter = destinationParameters[i];
Parameter sourceParameter = sourceParameters[i]; if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
Parameter destinationParameter = destinationParameters[i]; return;
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;
}
} }
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);
cachedForwardAddressMap.putAll(map);
}
} }
} }

View file

@ -15,15 +15,15 @@
*/ */
package ghidra.feature.vt.api.correlator.address; package ghidra.feature.vt.api.correlator.address;
import java.util.HashMap;
import java.util.Map;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.data.DataType;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.program.util.*; import ghidra.program.util.AddressCorrelation;
import ghidra.util.exception.CancelledException; import ghidra.util.exception.CancelledException;
import ghidra.util.task.TaskMonitor; import ghidra.util.task.TaskMonitor;
import java.util.*;
/** /**
* Generate address correlations by viewing each function as a list of instructions in address order * 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. * Instructions are paired one at a time, in order, if the mnemonics of the instructions match.
@ -93,33 +93,29 @@ public class StraightLineCorrelation implements AddressCorrelation {
/** /**
* Add address correlations for the parameters. * Add address correlations for the parameters.
*/ */
protected void computeParamCorrelation() { private void computeParamCorrelation() {
int sourceCount = sourceFunction.getParameterCount();
int destinationCount = destinationFunction.getParameterCount();
Parameter[] sourceParameters = sourceFunction.getParameters(); Parameter[] sourceParameters = sourceFunction.getParameters();
Parameter[] destinationParameters = destinationFunction.getParameters(); Parameter[] destinationParameters = destinationFunction.getParameters();
boolean allMatch = false; if (sourceParameters.length != destinationParameters.length) {
return;
}
Map<Address, AddressRange> map = new HashMap<Address, AddressRange>(); Map<Address, AddressRange> map = new HashMap<Address, AddressRange>();
if (sourceCount == destinationCount) { for (int i = 0; i < sourceParameters.length; i++) {
allMatch = true; Parameter sourceParameter = sourceParameters[i];
for (int i = 0; i < sourceParameters.length; i++) { Parameter destinationParameter = destinationParameters[i];
Parameter sourceParameter = sourceParameters[i]; if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
Parameter destinationParameter = destinationParameters[i]; return;
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;
}
} }
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);
cachedForwardAddressMap.putAll(map);
}
} }
/** /**