Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 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
c472f23
Update Readme
C0D3D3V Jan 9, 2025
b515c13
Fix ArrayConverter.concatenate() if one of the arrays is null.
C0D3D3V Jan 30, 2025
38d4607
Fix ByteArrayInsertValueModification, that I messed up last commit
C0D3D3V Jan 30, 2025
5bc90d5
Fix Path Insertion and Deletion. Also add tests for these two modific…
C0D3D3V Jan 30, 2025
18a605b
Fix ModifiableByteArray serialization
C0D3D3V Feb 7, 2025
51887db
run formatter
C0D3D3V Feb 7, 2025
7ad8434
Fixing serialization of ByteArrays, Strings and Path for real by ma…
C0D3D3V Feb 7, 2025
cfd221e
Remove commented out code that I forgot to delete last commit
C0D3D3V Feb 7, 2025
00b1abf
Merge remote-tracking branch 'origin/main' into daniel-main
C0D3D3V Feb 8, 2025
7b3e544
Add removed functions to ArrayConverter, so that projects that relay …
C0D3D3V Feb 21, 2025
febc53d
Remove setRandomModification() and createRandomModification from all …
C0D3D3V Feb 24, 2025
2ff6a93
change visibility of innerToString to protected
C0D3D3V Feb 24, 2025
7da0fba
Add setModifications() methods. As suggested by @ic0ns
C0D3D3V Feb 24, 2025
a1b45fb
run formatter
C0D3D3V Feb 24, 2025
f0374cd
Rename getModification to getFirstModification.
C0D3D3V Feb 24, 2025
1ac4208
revert to use Objects.hashCode(...) in hashCode methods instead.
C0D3D3V Feb 24, 2025
b52a6e1
run formatter
C0D3D3V Feb 24, 2025
3f8d6c3
Remove getModifiedCopy()
C0D3D3V Feb 24, 2025
01ecd03
Remove now unused limit constants, because I removed getModifiedCopy
C0D3D3V Feb 24, 2025
840f698
Remove BigIntegerInteractiveModification
C0D3D3V Feb 24, 2025
922914a
Revert names of ArrayConverter methods back to the old one. And adapt…
C0D3D3V Feb 24, 2025
51401fd
Remove inspection profile, because of https://github.com/tls-attacker…
C0D3D3V Feb 26, 2025
d75be13
remove reduceToOriginalValue, see https://github.com/tls-attacker/Mod…
C0D3D3V Feb 26, 2025
deb69e2
Remove modification filter feature see: https://github.com/tls-attack…
C0D3D3V Feb 26, 2025
3c3b6a0
Use Pattern Variables where possible
C0D3D3V Feb 26, 2025
7fa7448
Remove softlySet Methods. See https://github.com/tls-attacker/Modifia…
C0D3D3V Feb 26, 2025
02b7eaa
Use @XmlAnyElement(lax = true) instead of strong typing. See https://…
C0D3D3V Feb 26, 2025
897eabe
Remove all createRandomModification() methods from all factories.
C0D3D3V Feb 26, 2025
f3957ea
Remove explicit value from file tests I forgot to delete
C0D3D3V Feb 26, 2025
012c0cf
Fix debug method in VariableModification for cases where resulting va…
C0D3D3V Feb 26, 2025
e9ba2b5
Move String valueString definition into the case.
C0D3D3V Feb 26, 2025
ea4fac4
Merge branch 'main' into daniel-main
ic0ns Feb 28, 2025
449ca21
Remove setModification(), because you can use setModifications(...). …
C0D3D3V Feb 28, 2025
3567f7b
Replace all setModification() calls with setModifications()
C0D3D3V Feb 28, 2025
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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ nbproject/
nbactions.xml.project
nbactions.xml

# IntelliJ
.idea/
### IntelliJ IDEA ###
.idea/*
*.iws
*.iml
*.ipr

# VS Code
.vscode/
Expand Down
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ The best way to present the functionality of ModifiableVariables is by means of
ModifiableInteger i = new ModifiableInteger();
i.setOriginalValue(30);
VariableModification<Integer> modifier = IntegerModificationFactory.add(20);
i.setModification(modifier);
i.setModifications(modifier);
System.out.println(i.getValue()); // 50
```

Expand All @@ -56,7 +56,7 @@ In byte arrays you can use further modifications like shuffling or inserting byt
ModifiableByteArray ba = new ModifiableByteArray();
VariableModification<byte[]> modifier = ByteArrayModificationFactory.insert(new byte[] {2, 3}, 1);
ba.setOriginalValue(new byte[]{1, 4});
ba.setModification(modifier);
ba.setModifications(modifier);
System.out.println(ArrayConverter.bytesToHexString(ba)); // 01 02 03 04
```

Expand Down Expand Up @@ -116,15 +116,17 @@ The result of the serialized modifiable byte array looks as follows:
</modifiableByteArray>
```

If you would use modification from the previous example, the result would look as follows:
If you were to use the modification from the previous example, the result would look as follows:

```xml
<modifiableByteArray>
<originalValue>01 02 03</originalValue>
<ByteArrayInsertModification>
<bytesToInsert>02 03</bytesToInsert>
<startPosition>1</startPosition>
</ByteArrayInsertModification>
<modifications>
<ByteArrayInsertModification>
<bytesToInsert>02 03</bytesToInsert>
<startPosition>1</startPosition>
</ByteArrayInsertModification>
</modifications>
</modifiableByteArray>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

public class FileConfigurationException extends RuntimeException {

public FileConfigurationException() {}
public FileConfigurationException() {
super();
}

public FileConfigurationException(Exception ex) {
super(ex);
Expand Down
238 changes: 78 additions & 160 deletions src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,201 +7,119 @@
*/
package de.rub.nds.modifiablevariable;

import de.rub.nds.modifiablevariable.biginteger.BigIntegerAddModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerExplicitValueModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerInteractiveModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerMultiplyModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftLeftModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerShiftRightModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerSubtractModification;
import de.rub.nds.modifiablevariable.biginteger.BigIntegerXorModification;
import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification;
import de.rub.nds.modifiablevariable.bool.BooleanToggleModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayDeleteModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayDuplicateModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayExplicitValueModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayInsertModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayShuffleModification;
import de.rub.nds.modifiablevariable.bytearray.ByteArrayXorModification;
import de.rub.nds.modifiablevariable.integer.IntegerAddModification;
import de.rub.nds.modifiablevariable.integer.IntegerExplicitValueModification;
import de.rub.nds.modifiablevariable.integer.IntegerShiftLeftModification;
import de.rub.nds.modifiablevariable.integer.IntegerShiftRightModification;
import de.rub.nds.modifiablevariable.integer.IntegerSubtractModification;
import de.rub.nds.modifiablevariable.integer.IntegerXorModification;
import de.rub.nds.modifiablevariable.longint.LongAddModification;
import de.rub.nds.modifiablevariable.longint.LongExplicitValueModification;
import de.rub.nds.modifiablevariable.longint.LongSubtractModification;
import de.rub.nds.modifiablevariable.longint.LongXorModification;
import de.rub.nds.modifiablevariable.singlebyte.ByteAddModification;
import de.rub.nds.modifiablevariable.singlebyte.ByteExplicitValueModification;
import de.rub.nds.modifiablevariable.singlebyte.ByteSubtractModification;
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.StringPrependValueModification;
import jakarta.xml.bind.annotation.XmlAccessType;
import jakarta.xml.bind.annotation.XmlAccessorType;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlElements;
import jakarta.xml.bind.annotation.XmlRootElement;
import jakarta.xml.bind.annotation.XmlTransient;
import jakarta.xml.bind.annotation.*;
import java.io.Serializable;
import java.util.Objects;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
* The base abstract class for modifiable variables, including the getValue function.The class needs
* to be defined transient to allow propOrder definition in subclasses, see:
* http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html
* The base abstract class for modifiable variables, including the getValue function. The class
* needs to be defined transient to allow propOrder definition in subclasses, see: <a
* href="http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html">docs</a>
*
* @param <E>
*/
@XmlRootElement
@XmlTransient
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class ModifiableVariable<E> implements Serializable {

@XmlElements(
value = {
@XmlElement(
type = BigIntegerXorModification.class,
name = "BigIntegerXorModification"),
@XmlElement(
type = BigIntegerSubtractModification.class,
name = "BigIntegerSubtractModification"),
@XmlElement(
type = BigIntegerShiftRightModification.class,
name = "BigIntegerShiftRightModification"),
@XmlElement(
type = BigIntegerShiftLeftModification.class,
name = "BigIntegerShiftLeftModification"),
@XmlElement(
type = BigIntegerExplicitValueModification.class,
name = "BigIntegerExplicitValueModification"),
@XmlElement(
type = BigIntegerAddModification.class,
name = "BigIntegerAddModification"),
@XmlElement(
type = BigIntegerInteractiveModification.class,
name = "BigIntegerInteractiveModification"),
@XmlElement(
type = BigIntegerMultiplyModification.class,
name = "BigIntegerMultiplyModification"),
@XmlElement(
type = BooleanToggleModification.class,
name = "BooleanToggleModification"),
@XmlElement(
type = BooleanExplicitValueModification.class,
name = "BooleanExplicitValueModification"),
@XmlElement(
type = ByteArrayXorModification.class,
name = "ByteArrayXorModification"),
@XmlElement(
type = ByteArrayShuffleModification.class,
name = "ByteArrayShuffleModification"),
@XmlElement(
type = ByteArrayInsertModification.class,
name = "ByteArrayInsertModification"),
@XmlElement(
type = ByteArrayExplicitValueModification.class,
name = "ByteArrayExplicitValueModification"),
@XmlElement(
type = ByteArrayDuplicateModification.class,
name = "ByteArrayDuplicateModification"),
@XmlElement(
type = ByteArrayDeleteModification.class,
name = "ByteArrayDeleteModification"),
@XmlElement(type = IntegerXorModification.class, name = "IntegerXorModification"),
@XmlElement(
type = IntegerSubtractModification.class,
name = "IntegerSubtractModification"),
@XmlElement(
type = IntegerShiftRightModification.class,
name = "IntegerShiftRightModification"),
@XmlElement(
type = IntegerShiftLeftModification.class,
name = "IntegerShiftLeftModification"),
@XmlElement(
type = IntegerExplicitValueModification.class,
name = "IntegerExplicitValueModification"),
@XmlElement(type = IntegerAddModification.class, name = "IntegerAddModification"),
@XmlElement(type = LongXorModification.class, name = "LongXorModification"),
@XmlElement(
type = LongSubtractModification.class,
name = "LongSubtractModification"),
@XmlElement(
type = LongExplicitValueModification.class,
name = "LongExplicitValueModification"),
@XmlElement(type = LongAddModification.class, name = "LongAddModification"),
@XmlElement(type = ByteXorModification.class, name = "ByteXorModification"),
@XmlElement(
type = ByteSubtractModification.class,
name = "ByteSubtractModification"),
@XmlElement(type = ByteAddModification.class, name = "ByteAddModification"),
@XmlElement(
type = ByteExplicitValueModification.class,
name = "ByteExplicitValueModification"),
@XmlElement(
type = StringPrependValueModification.class,
name = "StringPrependValueModification"),
@XmlElement(
type = StringAppendValueModification.class,
name = "StringAppendValueModification"),
@XmlElement(
type = StringExplicitValueModification.class,
name = "StringExplicitValueModification")
})
private VariableModification<E> modification = null;

private Boolean createRandomModification;
@XmlElementWrapper
@XmlAnyElement(lax = true)
private LinkedList<VariableModification<E>> modifications;

protected E assertEquals;

public ModifiableVariable() {}
protected ModifiableVariable() {
super();
}

public void setModification(VariableModification<E> modification) {
this.modification = modification;
protected ModifiableVariable(ModifiableVariable<E> other) {
super();
if (other.modifications != null) {
modifications = new LinkedList<>();
for (VariableModification<E> item : other.modifications) {
modifications.add(item != null ? item.createCopy() : null);
}
}
// Warning: Make sure to copy assertEquals in subclass correctly
assertEquals = other.assertEquals;
}

@XmlTransient
public VariableModification<E> getModification() {
return modification;
/** Sets multiple modifications, all previously set modifications are removed */
public void setModifications(List<VariableModification<E>> modifications) {
this.modifications = new LinkedList<>(modifications);
}

public E getValue() {
if (Objects.equals(createRandomModification, Boolean.TRUE)) {
createRandomModification();
createRandomModification = false;
}
/** Sets multiple modifications, all previously set modifications are removed */
@SafeVarargs
public final void setModifications(VariableModification<E>... modifications) {
this.modifications = new LinkedList<>(List.of(modifications));
}

/** Removes all modifications */
public void clearModifications() {
modifications = null;
}

/** Adds a modification to this modifiable variable */
public void addModification(VariableModification<E> modification) {
if (modification != null) {
return modification.modify(getOriginalValue());
if (modifications == null) {
modifications = new LinkedList<>();
}
modifications.add(modification);
}
}

/** Returns all modifications that are set for this modifiable variable */
public LinkedList<VariableModification<E>> getModifications() {
return modifications;
}

public E getValue() {
return getModifiedValue();
}

private E getModifiedValue() {
E resultValue = getOriginalValue();
if (modifications != null) {
for (VariableModification<E> modification : modifications) {
resultValue = modification.modify(resultValue);
}
}
return getOriginalValue();
return resultValue;
}

public abstract E getOriginalValue();

public abstract void setOriginalValue(E originalValue);

protected abstract void createRandomModification();

public void createRandomModificationAtRuntime() {
createRandomModification = true;
}
public abstract ModifiableVariable<E> createCopy();

public abstract boolean isOriginalValueModified();

public abstract boolean validateAssertions();

public boolean containsAssertion() {
return (assertEquals != null);
return assertEquals != null;
}

public Boolean isCreateRandomModification() {
if (createRandomModification == null) {
return false;
protected String innerToString() {
StringBuilder result = new StringBuilder();
if (modifications != null) {
result.append(", modifications=[")
.append(
modifications.stream()
.map(Object::toString)
.collect(Collectors.joining(", ")))
.append("]");
}
return createRandomModification;

if (assertEquals != null) {
result.append(", assertEquals=").append(assertEquals);
}

return result.toString();
}
}
Loading