Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring + Insert Modification for Strings, Integer, BigInteger, Long + Some more Modifications for Long #182

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a1cb9cc
Simplify all return statements in the equal() methods of the
C0D3D3V Oct 12, 2024
7f3fb2f
Replace constant string concatenations that are used as arguments to …
C0D3D3V Oct 12, 2024
4ee5dd0
Fix getModifiedCopy() of ByteArrayShuffleModification. Before the Mod…
C0D3D3V Oct 14, 2024
24750a5
Fix getModifiedCopy() of StringModifications, so that the methods act…
C0D3D3V Oct 14, 2024
31bfb2f
Make createRandomModification() more readable by using Enums for the …
C0D3D3V Oct 14, 2024
753cf1b
Create StingInsertValueModification class. Very similar to the ByteAr…
C0D3D3V Oct 14, 2024
457a67b
Fix Typo getinsertValue to getInsertValue
C0D3D3V Oct 14, 2024
0763c71
Merge remote-tracking branch 'origin/main' into daniel-main
C0D3D3V Nov 4, 2024
79c0218
Merge branch 'main' into daniel-main
ic0ns Nov 6, 2024
fc9d71b
fix bytesToLong
C0D3D3V Nov 12, 2024
8599859
Change the hashCode() function of all Modifications, so they have a b…
C0D3D3V Nov 20, 2024
9789ee7
Move the Moodifications from SSH-Fuzzer to ModifiableVaraible.
C0D3D3V Nov 21, 2024
413d6d4
fix tests
C0D3D3V Nov 21, 2024
ca69bbf
Change the Insert Prepend and Append Modifications of Integer, BigInt…
C0D3D3V Nov 21, 2024
3337cba
run formatter
C0D3D3V Nov 21, 2024
0e71c4c
Add simple insertion test for long and BigInteger
C0D3D3V Nov 21, 2024
8c67bff
Actually remove magic values from hashCode() method of all modificati…
C0D3D3V Nov 21, 2024
5f31e08
Add copy constructors to all modifiable variables
C0D3D3V Nov 29, 2024
9598313
Fix equals() of ModifiableLengthField (I broke it in last commit)
C0D3D3V Nov 29, 2024
580b528
Undo changes to use String.format() instead of string concatenation
C0D3D3V Nov 29, 2024
b153a9e
Change CopyConstructors. Throw NullPointerException instead of allowi…
C0D3D3V Dec 1, 2024
4b606ee
Add Project_Defaults.xml to repo. So everyone developing on this repo…
C0D3D3V Dec 1, 2024
509333d
Add FromFileModifications, so one can distinguish it from normal expl…
C0D3D3V Dec 2, 2024
da88f9b
Fix CreateCopy() of ByteExplicitValue
C0D3D3V Dec 2, 2024
be36e78
Add missing XmlElement for explicit from file modifications
C0D3D3V Dec 3, 2024
c073a2b
Add PathModification. Fix copy methods
C0D3D3V Dec 4, 2024
3bb9d9f
Add ModifiablePath utilities and missing XmlElement Annotations
C0D3D3V Dec 4, 2024
753aa9d
run formatter
C0D3D3V Dec 4, 2024
6566fb9
Add PathInsertDirectorySeparatorModification
C0D3D3V Dec 5, 2024
95bb1ec
Fix some comments
C0D3D3V Dec 5, 2024
4ded76c
Add PathExplicitValueModification and
C0D3D3V Dec 5, 2024
f9b1a01
Be kind to negative and null count in PathInsertDirectoryTraversalMod…
C0D3D3V Dec 5, 2024
7309434
Add some toString() methods. Change backslashEscapeString() to return…
C0D3D3V Dec 6, 2024
149ceb2
Replace StringBuffer with StringBuilder in backslashEscapeString. To …
C0D3D3V Dec 6, 2024
882c926
fix logger of ModifiableByteArrayTest
C0D3D3V Dec 6, 2024
09a055a
Make ByteArrayDeleteModification more useful by allowing more random …
C0D3D3V Dec 6, 2024
e688cae
Fix tests because I changed the behavior of ByteArrayDeleteModification
C0D3D3V Dec 6, 2024
0ba036f
Fix ByteArrayShuffleModification to also shuffle byte arrays with len…
C0D3D3V Dec 6, 2024
2adcc69
Also print modifications in toString() methods. Not very nicely imple…
C0D3D3V Dec 9, 2024
272f6b6
Just some renaming of parameters
C0D3D3V Dec 9, 2024
d613cdd
Change behavior of ByteArrayXorModification. Allow arbitrary start po…
C0D3D3V Dec 9, 2024
ad139d1
Change behaviour of reduceToOriginalValue()
C0D3D3V Dec 12, 2024
564be80
Add Swap Endian Modifications for long and integer
C0D3D3V Dec 13, 2024
6a0d506
Allow multiple modifications on one modifiable variable
C0D3D3V Dec 13, 2024
3a3a2ad
Fi some overflows
C0D3D3V Dec 16, 2024
dc19dd4
Add softlySetValue methods for all modifiable variables.
C0D3D3V Dec 18, 2024
e4237b5
Add softlySetValue with alwaysSet option
C0D3D3V Dec 18, 2024
8684f65
Rename createRandomModification to setRandomModification, and make it…
C0D3D3V Dec 20, 2024
ff01b27
Rename longToUint64Bytes to longToEightBytes since it can also be use…
C0D3D3V Dec 30, 2024
c0fb825
run linter
C0D3D3V Dec 30, 2024
2ca2f90
Fix fourBytesToInt
C0D3D3V Dec 30, 2024
01f2f20
Fix fourBytesToInt but for real -.-
C0D3D3V Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import de.rub.nds.modifiablevariable.singlebyte.ByteXorModification;
import de.rub.nds.modifiablevariable.string.StringAppendValueModification;
import de.rub.nds.modifiablevariable.string.StringExplicitValueModification;
import de.rub.nds.modifiablevariable.string.StringInsertValueModification;
import de.rub.nds.modifiablevariable.string.StringPrependValueModification;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
Expand Down Expand Up @@ -149,7 +150,10 @@ public abstract class ModifiableVariable<E> implements Serializable {
name = "StringAppendValueModification"),
@XmlElement(
type = StringExplicitValueModification.class,
name = "StringExplicitValueModification")
name = "StringExplicitValueModification"),
@XmlElement(
type = StringInsertValueModification.class,
name = "StringInsertValueModification")
})
private VariableModification<E> modification = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public abstract class VariableModification<E> {

public E modify(E input) {
E modifiedValue = modifyImplementationHook(input);
if ((modificationFilter == null) || (modificationFilter.filterModification() == false)) {
if ((modificationFilter == null) || (!modificationFilter.filterModification())) {
debug(modifiedValue);
return modifiedValue;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerAddModification other = (BigIntegerAddModification) obj;
if (!Objects.equals(this.summand, other.summand)) {
return false;
}
return true;
return Objects.equals(this.summand, other.summand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerExplicitValueModification other = (BigIntegerExplicitValueModification) obj;
if (!Objects.equals(this.explicitValue, other.explicitValue)) {
return false;
}
return true;
return Objects.equals(this.explicitValue, other.explicitValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@

public class BigIntegerModificationFactory {

private static final int MODIFICATION_COUNT = 7;
private enum ModificationType {
ADD, SUBTRACT, XOR, EXPLICIT, SHIFT_LEFT, SHIFT_RIGHT, EXPLICIT_FROM_FILE
}

private static final int MODIFICATION_COUNT = ModificationType.values().length;

private static final int MAX_MODIFICATION_VALUE = 320000;

Expand Down Expand Up @@ -138,7 +142,7 @@ public static synchronized List<VariableModification<BigInteger>> modificationsF
String line;
while ((line = br.readLine()) != null) {
String value = line.trim().split(" ")[0];
if (!value.equals("")) {
if (!value.isEmpty()) {
modificationsFromFile.add(explicitValue(value));
}
}
Expand All @@ -152,35 +156,26 @@ public static synchronized List<VariableModification<BigInteger>> modificationsF

public static VariableModification<BigInteger> createRandomModification() {
Random random = RandomHelper.getRandom();
int r = random.nextInt(MODIFICATION_COUNT);
ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)];
BigInteger modification = BigInteger.valueOf(random.nextInt(MAX_MODIFICATION_VALUE));
int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE);
VariableModification<BigInteger> vm = null;
switch (r) {
case 0:
vm = new BigIntegerAddModification(modification);
return vm;
case 1:
vm = new BigIntegerSubtractModification(modification);
return vm;
case 2:
vm = new BigIntegerXorModification(modification);
return vm;
case 3:
vm = new BigIntegerExplicitValueModification(modification);
return vm;
case 4:
vm = new BigIntegerShiftLeftModification(shiftModification);
return vm;
case 5:
vm = new BigIntegerShiftRightModification(shiftModification);
return vm;
case 6:
vm = explicitValueFromFile(MAX_MODIFICATION_VALUE);
return vm;
default: // unreachable but included for checkstyle
vm = explicitValueFromFile(MAX_MODIFICATION_VALUE);
return vm;
switch (randomType) {
case ADD:
return new BigIntegerAddModification(modification);
case SUBTRACT:
return new BigIntegerSubtractModification(modification);
case XOR:
return new BigIntegerXorModification(modification);
case EXPLICIT:
return new BigIntegerExplicitValueModification(modification);
case SHIFT_LEFT:
return new BigIntegerShiftLeftModification(shiftModification);
case SHIFT_RIGHT:
return new BigIntegerShiftRightModification(shiftModification);
case EXPLICIT_FROM_FILE:
return explicitValueFromFile(MAX_MODIFICATION_VALUE);
default:
throw new IllegalStateException("Unexpected modification type: " + randomType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj;
if (!Objects.equals(this.factor, other.factor)) {
return false;
}
return true;
return Objects.equals(this.factor, other.factor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerShiftLeftModification other = (BigIntegerShiftLeftModification) obj;
if (this.shift != other.shift) {
return false;
}
return true;
return this.shift == other.shift;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerShiftRightModification other = (BigIntegerShiftRightModification) obj;
if (this.shift != other.shift) {
return false;
}
return true;
return this.shift == other.shift;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerSubtractModification other = (BigIntegerSubtractModification) obj;
if (!Objects.equals(this.subtrahend, other.subtrahend)) {
return false;
}
return true;
return Objects.equals(this.subtrahend, other.subtrahend);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ public boolean equals(Object obj) {
return false;
}
final BigIntegerXorModification other = (BigIntegerXorModification) obj;
if (!Objects.equals(this.xor, other.xor)) {
return false;
}
return true;
return Objects.equals(this.xor, other.xor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public byte[] getByteArray(int size) {
@Override
public boolean validateAssertions() {
if (assertEquals != null) {
if (assertEquals.compareTo(getValue()) != 0) {
return false;
}
return assertEquals.compareTo(getValue()) == 0;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ public boolean equals(Object obj) {
return false;
}
final BooleanExplicitValueModification other = (BooleanExplicitValueModification) obj;
if (this.explicitValue != other.explicitValue) {
return false;
}
return true;
return this.explicitValue == other.explicitValue;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@

public class BooleanModificationFactory {

private static final int MODIFICATION_COUNT = 3;
private enum ModificationType {
EXPLICIT_TRUE, EXPLICIT_FALSE, TOGGLE
}
private static final int MODIFICATION_COUNT = ModificationType.values().length;

public static VariableModification<Boolean> createRandomModification() {
Random random = RandomHelper.getRandom();
switch (random.nextInt(MODIFICATION_COUNT)) {
case 0:
ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)];
switch (randomType) {
case EXPLICIT_TRUE:
return new BooleanExplicitValueModification(true);
case 1:
case EXPLICIT_FALSE:
return new BooleanExplicitValueModification(false);
case 2:
case TOGGLE:
return new BooleanToggleModification();
default:
return null;
throw new IllegalStateException("Unexpected modification type: " + randomType);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
return true;
return getClass() == obj.getClass();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ public boolean isOriginalValueModified() {
@Override
public boolean validateAssertions() {
if (assertEquals != null) {
if (assertEquals.compareTo(getValue()) != 0) {
return false;
}
return assertEquals.compareTo(getValue()) == 0;
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,17 @@ protected byte[] modifyImplementationHook(byte[] input) {
if (start < 0) {
start += input.length;
if (start < 0) {
LOGGER.debug(
"Trying to delete from too negative Startposition. start = "
+ (start - input.length));
LOGGER.debug("Trying to delete from too negative Startposition. start = {}", start - input.length);
return input;
}
}
final int endPosition = start + count;
if ((endPosition) > input.length) {
LOGGER.debug(
String.format(
"Bytes %d..%d cannot be deleted from {%s} of length %d",
start, endPosition, bytesToHexString(input), input.length));
LOGGER.debug("Bytes {}..{} cannot be deleted from {{}} of length {}", start, endPosition, bytesToHexString(input), input.length);
return input;
}
if (count <= 0) {
LOGGER.debug("You must delete at least one byte. count = " + count);
LOGGER.debug("You must delete at least one byte. count = {}", count);
return input;
}
byte[] ret1 = Arrays.copyOf(input, start);
Expand Down Expand Up @@ -132,10 +127,7 @@ public boolean equals(Object obj) {
if (this.count != other.count) {
return false;
}
if (this.startPosition != other.startPosition) {
return false;
}
return true;
return this.startPosition == other.startPosition;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
return true;
return getClass() == obj.getClass();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ public boolean equals(Object obj) {
return false;
}
final ByteArrayExplicitValueModification other = (ByteArrayExplicitValueModification) obj;
if (!Arrays.equals(this.explicitValue, other.explicitValue)) {
return false;
}
return true;
return Arrays.equals(this.explicitValue, other.explicitValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,17 @@ protected byte[] modifyImplementationHook(byte[] input) {
if (start < 0) {
start += input.length;
if (start < 0) {
LOGGER.debug(
"Trying to insert from too negative Startposition. start = "
+ startPosition);
LOGGER.debug("Trying to insert from too negative Startposition. start = {}", startPosition);
return input;
}
}
if (startPosition > input.length) {
LOGGER.debug(
"Trying to insert behind the Array. ArraySize:"
+ input.length
+ " Insert Position:"
+ startPosition);
if (start > input.length) {
LOGGER.debug("Trying to insert behind the Array. ArraySize:{} Insert Position:{}", input.length, startPosition);
return input;
}
byte[] ret1 = Arrays.copyOf(input, start);
byte[] ret3 = null;
if ((start) < input.length) {
if (start < input.length) {
ret3 = Arrays.copyOfRange(input, start, input.length);
}
return ArrayConverter.concatenate(ret1, bytesToInsert, ret3);
Expand Down Expand Up @@ -133,10 +127,7 @@ public boolean equals(Object obj) {
if (this.startPosition != other.startPosition) {
return false;
}
if (!Arrays.equals(this.bytesToInsert, other.bytesToInsert)) {
return false;
}
return true;
return Arrays.equals(this.bytesToInsert, other.bytesToInsert);
}

@Override
Expand Down
Loading