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,35 +378,31 @@ 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) {
allMatch = true;
for (int i = 0; i < sourceParameters.length; i++) { for (int i = 0; i < sourceParameters.length; i++) {
Parameter sourceParameter = sourceParameters[i]; Parameter sourceParameter = sourceParameters[i];
Parameter destinationParameter = destinationParameters[i]; Parameter destinationParameter = destinationParameters[i];
if (!sourceParameter.isValid() || !destinationParameter.isValid() || if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
sourceParameter.getLength() != destinationParameter.getLength()) { return;
// - an invalid parameter does not have defined storage (or address)
// - length must also match
allMatch = false;
break;
} }
Address dest = destinationParameter.getVariableStorage().getMinAddress(); VariableStorage sourceParamStorage = sourceParameter.getVariableStorage();
Address src = sourceParameter.getVariableStorage().getMinAddress(); VariableStorage destParamStorage = destinationParameter.getVariableStorage();
if (!sourceParamStorage.equals(destParamStorage)) {
return;
}
Address dest = sourceParamStorage.getMinAddress();
Address src = destParamStorage.getMinAddress();
map.put(src, new CorrelationContainer(CorrelationKind.PARAMETERS, map.put(src, new CorrelationContainer(CorrelationKind.PARAMETERS,
new AddressRangeImpl(dest, dest))); 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,
Map<CodeUnit, TreeSet<AddressRange>> destinationMap, CodeUnitContainer sourceCodeUnit, Map<CodeUnit, TreeSet<AddressRange>> destinationMap, CodeUnitContainer sourceCodeUnit,

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) {
allMatch = true;
for (int i = 0; i < sourceParameters.length; i++) { for (int i = 0; i < sourceParameters.length; i++) {
Parameter sourceParameter = sourceParameters[i]; Parameter sourceParameter = sourceParameters[i];
Parameter destinationParameter = destinationParameters[i]; Parameter destinationParameter = destinationParameters[i];
DataType sourceDataType = sourceParameter.getDataType(); if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
DataType destinationDataType = destinationParameter.getDataType(); return;
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,34 +93,30 @@ 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) {
allMatch = true;
for (int i = 0; i < sourceParameters.length; i++) { for (int i = 0; i < sourceParameters.length; i++) {
Parameter sourceParameter = sourceParameters[i]; Parameter sourceParameter = sourceParameters[i];
Parameter destinationParameter = destinationParameters[i]; Parameter destinationParameter = destinationParameters[i];
DataType sourceDataType = sourceParameter.getDataType(); if (!sourceParameter.isValid() || !destinationParameter.isValid()) {
DataType destinationDataType = destinationParameter.getDataType(); return;
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);
} }
}
/** /**
* Save address correlation between two code units to the map * Save address correlation between two code units to the map