Added bias to resizeStackVarnode calculation, fixed big endian resizing

This commit is contained in:
caheckman 2019-10-03 13:07:02 -04:00
parent fdcf0744ec
commit 4c4623bbf4

View file

@ -446,14 +446,17 @@ public class VariableUtilities {
// complex data-type: always left align
// simple data-type: right align within minimum number of aligned cells
int endStackOffset = stackOffset + varnode.getSize() - 1;
int stackAlign = stackAttributes.stackAlign;
if (endStackOffset % stackAlign != 0) {
if ((stackOffset + varnode.getSize() - stackAttributes.bias) % stackAlign != 0) {
stackAlign = 1; // was not aligned to start with
}
newStackOffset -= newStackOffset % stackAlign; // left-alignment of start offset
int newAlign = (newStackOffset - stackAttributes.bias) % stackAlign;
if (newAlign < 0) {
newAlign += stackAlign;
}
newStackOffset -= newAlign; // left-alignment of start offset
if (!complexDt) {
// right-align non-complex data
int cellExcess = newVarnodeSize % stackAlign;
@ -475,10 +478,12 @@ public class VariableUtilities {
private static class StackAttributes {
final int stackAlign;
final int bias;
final boolean rightJustify; // only applies to primitives
public StackAttributes(int stackAlign, boolean rightJustify) {
public StackAttributes(int stackAlign, int bias, boolean rightJustify) {
this.stackAlign = stackAlign;
this.bias = bias;
this.rightJustify = rightJustify;
}
}
@ -495,7 +500,15 @@ public class VariableUtilities {
if (stackAlign < 0) {
stackAlign = 1;
}
return new StackAttributes(stackAlign, rightJustify);
int bias = 0;
Long stackBase = callingConvention.getStackParameterOffset();
if (stackBase != null) {
bias = (int) (stackBase.longValue() % stackAlign);
if (bias < 0) {
bias += stackAlign;
}
}
return new StackAttributes(stackAlign, bias, rightJustify);
}
/**