From a1cb9cc999451a810f2a2f4d853794becff32e58 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Sat, 12 Oct 2024 16:13:50 +0200 Subject: [PATCH 01/50] Simplify all return statements in the equal() methods of the Modification classes. Also simplify some conditions in validateAssertions() and modify() methods. --- .../de/rub/nds/modifiablevariable/VariableModification.java | 2 +- .../biginteger/BigIntegerAddModification.java | 5 +---- .../biginteger/BigIntegerExplicitValueModification.java | 5 +---- .../biginteger/BigIntegerMultiplyModification.java | 5 +---- .../biginteger/BigIntegerShiftLeftModification.java | 5 +---- .../biginteger/BigIntegerShiftRightModification.java | 5 +---- .../biginteger/BigIntegerSubtractModification.java | 5 +---- .../biginteger/BigIntegerXorModification.java | 5 +---- .../modifiablevariable/biginteger/ModifiableBigInteger.java | 4 +--- .../bool/BooleanExplicitValueModification.java | 5 +---- .../modifiablevariable/bool/BooleanToggleModification.java | 5 +---- .../rub/nds/modifiablevariable/bool/ModifiableBoolean.java | 4 +--- .../bytearray/ByteArrayDeleteModification.java | 5 +---- .../bytearray/ByteArrayDuplicateModification.java | 5 +---- .../bytearray/ByteArrayExplicitValueModification.java | 5 +---- .../bytearray/ByteArrayInsertModification.java | 5 +---- .../bytearray/ByteArrayShuffleModification.java | 5 +---- .../bytearray/ByteArrayXorModification.java | 5 +---- .../modifiablevariable/integer/IntegerAddModification.java | 5 +---- .../integer/IntegerExplicitValueModification.java | 5 +---- .../integer/IntegerShiftLeftModification.java | 5 +---- .../integer/IntegerShiftRightModification.java | 5 +---- .../integer/IntegerSubtractModification.java | 5 +---- .../modifiablevariable/integer/IntegerXorModification.java | 5 +---- .../nds/modifiablevariable/longint/LongAddModification.java | 5 +---- .../longint/LongExplicitValueModification.java | 5 +---- .../modifiablevariable/longint/LongSubtractModification.java | 5 +---- .../nds/modifiablevariable/longint/LongXorModification.java | 5 +---- .../modifiablevariable/singlebyte/ByteAddModification.java | 5 +---- .../singlebyte/ByteExplicitValueModification.java | 5 +---- .../singlebyte/ByteSubtractModification.java | 5 +---- .../modifiablevariable/singlebyte/ByteXorModification.java | 5 +---- .../string/StringExplicitValueModification.java | 5 +---- .../rub/nds/modifiablevariable/util/ComparableByteArray.java | 5 +---- 34 files changed, 34 insertions(+), 131 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java index 04e81ef..56ceadf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java @@ -41,7 +41,7 @@ public abstract class VariableModification { 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 { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index 012555c..d546790 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index 8f59ad9..6593141 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 3faeb0c..4ffe0ca 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index f07cddd..0c058b3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -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; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index 78443aa..9d30b4b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -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; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index 11fa670..96e7819 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index 064f6f8..035c0f7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index c9ab1e8..03b4697 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -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; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index d253c44..407e045 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java index aee2138..3f9da99 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java @@ -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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index 9dc3fc2..058e8f5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -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; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index c2e96da..9550325 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -132,10 +132,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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java index 697837d..32f1ebb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java @@ -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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index 85c5d8e..c7c29ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java index 660d6e0..2bbd281 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java @@ -133,10 +133,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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 379a735..56680a0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -93,10 +93,7 @@ public boolean equals(Object obj) { return false; } final ByteArrayShuffleModification other = (ByteArrayShuffleModification) obj; - if (!Arrays.equals(this.shuffle, other.shuffle)) { - return false; - } - return true; + return Arrays.equals(this.shuffle, other.shuffle); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index 9845db5..ac47705 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -129,10 +129,7 @@ public boolean equals(Object obj) { if (this.startPosition != other.startPosition) { return false; } - if (!Arrays.equals(this.xor, other.xor)) { - return false; - } - return true; + return Arrays.equals(this.xor, other.xor); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index eb466c9..8ad6d9a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -64,9 +64,6 @@ public boolean equals(Object obj) { return false; } final IntegerAddModification other = (IntegerAddModification) obj; - if (!Objects.equals(this.summand, other.summand)) { - return false; - } - return true; + return Objects.equals(this.summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 5b5e4db..792f05a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -71,9 +71,6 @@ public boolean equals(Object obj) { return false; } final IntegerExplicitValueModification other = (IntegerExplicitValueModification) obj; - if (!Objects.equals(this.explicitValue, other.explicitValue)) { - return false; - } - return true; + return Objects.equals(this.explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index 3647542..dcb56cc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -75,9 +75,6 @@ public boolean equals(Object obj) { return false; } final IntegerShiftLeftModification other = (IntegerShiftLeftModification) obj; - if (this.shift != other.shift) { - return false; - } - return true; + return this.shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index f0cfb2e..2969a13 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -75,9 +75,6 @@ public boolean equals(Object obj) { return false; } final IntegerShiftRightModification other = (IntegerShiftRightModification) obj; - if (this.shift != other.shift) { - return false; - } - return true; + return this.shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index 12c4343..c527713 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -65,9 +65,6 @@ public boolean equals(Object obj) { return false; } final IntegerSubtractModification other = (IntegerSubtractModification) obj; - if (!Objects.equals(this.subtrahend, other.subtrahend)) { - return false; - } - return true; + return Objects.equals(this.subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index b91a6e1..dda4a30 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -69,9 +69,6 @@ public boolean equals(Object obj) { return false; } final IntegerXorModification other = (IntegerXorModification) obj; - if (!Objects.equals(this.xor, other.xor)) { - return false; - } - return true; + return Objects.equals(this.xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index 6f89d67..637297f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -64,9 +64,6 @@ public boolean equals(Object obj) { return false; } final LongAddModification other = (LongAddModification) obj; - if (!Objects.equals(this.summand, other.summand)) { - return false; - } - return true; + return Objects.equals(this.summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index d813677..8b4ae29 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -71,9 +71,6 @@ public boolean equals(Object obj) { return false; } final LongExplicitValueModification other = (LongExplicitValueModification) obj; - if (!Objects.equals(this.explicitValue, other.explicitValue)) { - return false; - } - return true; + return Objects.equals(this.explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index ba2f488..e1cde29 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -65,9 +65,6 @@ public boolean equals(Object obj) { return false; } final LongSubtractModification other = (LongSubtractModification) obj; - if (!Objects.equals(this.subtrahend, other.subtrahend)) { - return false; - } - return true; + return Objects.equals(this.subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index c975578..50afc21 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -69,9 +69,6 @@ public boolean equals(Object obj) { return false; } final LongXorModification other = (LongXorModification) obj; - if (!Objects.equals(this.xor, other.xor)) { - return false; - } - return true; + return Objects.equals(this.xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index 08d6994..6cfcc7e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -67,9 +67,6 @@ public boolean equals(Object obj) { return false; } final ByteAddModification other = (ByteAddModification) obj; - if (!Objects.equals(this.summand, other.summand)) { - return false; - } - return true; + return Objects.equals(this.summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 4950545..0297cf8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -71,9 +71,6 @@ public boolean equals(Object obj) { return false; } final ByteExplicitValueModification other = (ByteExplicitValueModification) obj; - if (!Objects.equals(this.explicitValue, other.explicitValue)) { - return false; - } - return true; + return Objects.equals(this.explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index f5ccdde..85c22ba 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -68,9 +68,6 @@ public boolean equals(Object obj) { return false; } final ByteSubtractModification other = (ByteSubtractModification) obj; - if (!Objects.equals(this.subtrahend, other.subtrahend)) { - return false; - } - return true; + return Objects.equals(this.subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index 4cdce5d..21cad46 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -73,9 +73,6 @@ public boolean equals(Object obj) { return false; } final ByteXorModification other = (ByteXorModification) obj; - if (!Objects.equals(this.xor, other.xor)) { - return false; - } - return true; + return Objects.equals(this.xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index c328c81..dd2b8ee 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -65,9 +65,6 @@ public boolean equals(Object obj) { return false; } final StringExplicitValueModification other = (StringExplicitValueModification) obj; - if (!Objects.equals(this.explicitValue, other.explicitValue)) { - return false; - } - return true; + return Objects.equals(this.explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java index 4c67566..9382c05 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java @@ -44,9 +44,6 @@ public boolean equals(Object obj) { return false; } final ComparableByteArray other = (ComparableByteArray) obj; - if (!Arrays.equals(this.array, other.array)) { - return false; - } - return true; + return Arrays.equals(this.array, other.array); } } From 7f3fb2f0741426b1a7cc97aeec2d95f22ef996a2 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Sat, 12 Oct 2024 16:19:58 +0200 Subject: [PATCH 02/50] Replace constant string concatenations that are used as arguments to logging methods with parameterized log messages --- .../bytearray/ByteArrayDeleteModification.java | 11 +++-------- .../bytearray/ByteArrayInsertModification.java | 10 ++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 9550325..ed3152d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -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); diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java index 2bbd281..64c4ab5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java @@ -49,18 +49,12 @@ 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); + LOGGER.debug("Trying to insert behind the Array. ArraySize:{} Insert Position:{}", input.length, startPosition); return input; } byte[] ret1 = Arrays.copyOf(input, start); From 4ee5dd0dec1c7444d79df8781f07213d268b6b2b Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Oct 2024 11:37:41 +0200 Subject: [PATCH 03/50] Fix getModifiedCopy() of ByteArrayShuffleModification. Before the Modification was not modified, just copied. --- .../bytearray/ByteArrayShuffleModification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 56680a0..7b89915 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -71,7 +71,7 @@ public VariableModification getModifiedCopy() { int index = r.nextInt(shuffle.length); byte[] newValue = Arrays.copyOf(shuffle, shuffle.length); newValue[index] = (byte) r.nextInt(MAX_MODIFIER_VALUE); - return new ByteArrayShuffleModification(shuffle); + return new ByteArrayShuffleModification(newValue); } @Override From 24750a56e410fc8379910dea3efff86ce344c815 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Oct 2024 13:12:53 +0200 Subject: [PATCH 04/50] Fix getModifiedCopy() of StringModifications, so that the methods actually return modified copies and not only the same modification. --- .../string/StringAppendValueModification.java | 10 +++++++++- .../string/StringExplicitValueModification.java | 13 ++++++++++++- .../string/StringPrependValueModification.java | 10 +++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index ce8e1eb..a81d708 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -13,12 +13,15 @@ import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Objects; +import java.util.Random; /** Modification that appends a string to the original value. */ @XmlRootElement @XmlType(propOrder = {"appendValue", "modificationFilter"}) public class StringAppendValueModification extends VariableModification { + private static final int MAX_EXPLICIT_VALUE = 256; + @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String appendValue; @@ -43,7 +46,12 @@ public void setAppendValue(final String appendValue) { @Override public VariableModification getModifiedCopy() { - return new StringAppendValueModification(appendValue); + Random r = new Random(); + int index = r.nextInt(appendValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + StringBuilder modifiedString = new StringBuilder(appendValue); + modifiedString.setCharAt(index, randomChar); + return new StringAppendValueModification(modifiedString.toString()); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index dd2b8ee..26c7fa6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -13,12 +13,15 @@ import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Objects; +import java.util.Random; /** */ @XmlRootElement @XmlType(propOrder = {"explicitValue", "modificationFilter"}) public class StringExplicitValueModification extends VariableModification { + private static final int MAX_EXPLICIT_VALUE = 256; + @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String explicitValue; @@ -43,7 +46,15 @@ public void setExplicitValue(String explicitValue) { @Override public VariableModification getModifiedCopy() { - return new StringExplicitValueModification(explicitValue); + if (explicitValue.isEmpty()) { + return this; + } + Random r = new Random(); + int index = r.nextInt(explicitValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + StringBuilder modifiedString = new StringBuilder(explicitValue); + modifiedString.setCharAt(index, randomChar); + return new StringExplicitValueModification(modifiedString.toString()); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index ea4112f..2fdaeee 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -13,12 +13,15 @@ import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import java.util.Objects; +import java.util.Random; /** Modification that prepends a string to the original value. */ @XmlRootElement @XmlType(propOrder = {"prependValue", "modificationFilter"}) public class StringPrependValueModification extends VariableModification { + private static final int MAX_EXPLICIT_VALUE = 256; + @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String prependValue; @@ -43,7 +46,12 @@ public void setPrependValue(final String prependValue) { @Override public VariableModification getModifiedCopy() { - return new StringPrependValueModification(prependValue); + Random r = new Random(); + int index = r.nextInt(prependValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + StringBuilder modifiedString = new StringBuilder(prependValue); + modifiedString.setCharAt(index, randomChar); + return new StringPrependValueModification(modifiedString.toString()); } @Override From 31bfb2f6061d9203502589400eebc5e40a150738 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Oct 2024 13:15:34 +0200 Subject: [PATCH 05/50] Make createRandomModification() more readable by using Enums for the modification types instead of constant integers. This also unifies the method in all factories. Also remove unnecessary semicolons from previous commit. --- .../BigIntegerModificationFactory.java | 53 +++++++------- .../bool/BooleanModificationFactory.java | 16 +++-- .../ByteArrayModificationFactory.java | 69 +++++++------------ .../integer/IntegerModificationFactory.java | 47 ++++++------- .../longint/LongModificationFactory.java | 37 +++++----- .../singlebyte/ByteModificationFactory.java | 45 +++++------- .../string/StringAppendValueModification.java | 2 +- .../StringExplicitValueModification.java | 2 +- .../string/StringModificationFactory.java | 44 ++++++++++-- .../StringPrependValueModification.java | 2 +- 10 files changed, 157 insertions(+), 160 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index 3d316c9..0470bbd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -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; @@ -133,7 +137,7 @@ public static synchronized List> modificationsF String line; while ((line = br.readLine()) != null) { String value = line.trim().split(" ")[0]; - if (!value.equals("")) { + if (!value.isEmpty()) { modificationsFromFile.add(explicitValue(value)); } } @@ -147,35 +151,26 @@ public static synchronized List> modificationsF public static VariableModification 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 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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java index 0a3c2a9..66c009a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java @@ -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 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); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java index ce26299..c87c5e5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java @@ -21,21 +21,10 @@ public class ByteArrayModificationFactory { - private static final int BYTE_ARRAY_SHUFFLE_MODIFICATION = 6; - - private static final int BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION_FROM_FILE = 5; - - private static final int BYTE_ARRAY_DUPLICATE_MODIFICATION = 4; - - private static final int BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION = 3; - - private static final int BYTE_ARRAY_DELETE_MODIFICATION = 2; - - private static final int BYTE_ARRAY_INSERT_MODIFICATION = 1; - - private static final int BYTE_ARRAY_XOR_MODIFICATION = 0; - - private static final int MODIFICATION_COUNT = 7; + private enum ModificationType { + XOR, INSERT, DELETE, EXPLICIT, DUPLICATE, EXPLICIT_FROM_FILE, SHUFFLE + } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_CONFIG_PARAMETER = 200; @@ -131,29 +120,29 @@ public static synchronized List> modificationsFromF public static VariableModification createRandomModification(byte[] originalValue) { Random random = RandomHelper.getRandom(); - int r = random.nextInt(MODIFICATION_COUNT); - VariableModification vm = null; + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; int modifiedArrayLength; + int modificationArrayLength; + int startPosition; if (originalValue == null) { modifiedArrayLength = MODIFIED_ARRAY_LENGTH_ESTIMATION; } else { modifiedArrayLength = originalValue.length; if (originalValue.length == 0 || originalValue.length == 1) { - r = BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION; + randomType = ModificationType.EXPLICIT; } } - switch (r) { - case BYTE_ARRAY_XOR_MODIFICATION: - int modificationArrayLength = random.nextInt(modifiedArrayLength); + switch (randomType) { + case XOR: + modificationArrayLength = random.nextInt(modifiedArrayLength); if (modificationArrayLength == 0) { modificationArrayLength++; } byte[] xor = new byte[modificationArrayLength]; random.nextBytes(xor); - int startPosition = random.nextInt(modifiedArrayLength - modificationArrayLength); - vm = new ByteArrayXorModification(xor, startPosition); - return vm; - case BYTE_ARRAY_INSERT_MODIFICATION: + startPosition = random.nextInt(modifiedArrayLength - modificationArrayLength); + return new ByteArrayXorModification(xor, startPosition); + case INSERT: modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER); if (modificationArrayLength == 0) { modificationArrayLength++; @@ -161,37 +150,31 @@ public static VariableModification createRandomModification(byte[] origi byte[] bytesToInsert = new byte[modificationArrayLength]; random.nextBytes(bytesToInsert); int insertPosition = random.nextInt(modifiedArrayLength); - vm = new ByteArrayInsertModification(bytesToInsert, insertPosition); - return vm; - case BYTE_ARRAY_DELETE_MODIFICATION: + return new ByteArrayInsertModification(bytesToInsert, insertPosition); + case DELETE: startPosition = random.nextInt(modifiedArrayLength - 1); int count = random.nextInt(modifiedArrayLength - startPosition); count++; - vm = new ByteArrayDeleteModification(startPosition, count); - return vm; - case BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION: + return new ByteArrayDeleteModification(startPosition, count); + case EXPLICIT: modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER); if (modificationArrayLength == 0) { modificationArrayLength++; } byte[] explicitValue = new byte[modificationArrayLength]; random.nextBytes(explicitValue); - vm = new ByteArrayExplicitValueModification(explicitValue); - return vm; - case BYTE_ARRAY_DUPLICATE_MODIFICATION: - vm = new ByteArrayDuplicateModification(); - return vm; - case BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION_FROM_FILE: - vm = explicitValueFromFile(random.nextInt(EXPLICIT_VALUE_RANDOM)); - return vm; - case BYTE_ARRAY_SHUFFLE_MODIFICATION: + return new ByteArrayExplicitValueModification(explicitValue); + case DUPLICATE: + return new ByteArrayDuplicateModification(); + case EXPLICIT_FROM_FILE: + return explicitValueFromFile(random.nextInt(EXPLICIT_VALUE_RANDOM)); + case SHUFFLE: int shuffleSize = random.nextInt(MAX_CONFIG_PARAMETER); byte[] shuffle = new byte[shuffleSize]; random.nextBytes(shuffle); - vm = shuffle(shuffle); - return vm; + return new ByteArrayShuffleModification(shuffle); default: - return vm; + throw new IllegalStateException("Unexpected modification type: " + randomType); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java index 824f9f8..7b65d62 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java @@ -20,7 +20,10 @@ public class IntegerModificationFactory { - 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 = 32000; @@ -106,34 +109,26 @@ public static synchronized List> modificationsFrom public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); - int r = random.nextInt(MODIFICATION_COUNT); + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; int modification = random.nextInt(MAX_MODIFICATION_VALUE); int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE); - VariableModification vm = null; - switch (r) { - case 0: - vm = new IntegerAddModification(modification); - return vm; - case 1: - vm = new IntegerSubtractModification(modification); - return vm; - case 2: - vm = new IntegerXorModification(modification); - return vm; - case 3: - vm = new IntegerExplicitValueModification(modification); - return vm; - case 4: - vm = new IntegerShiftLeftModification(shiftModification); - return vm; - case 5: - vm = new IntegerShiftRightModification(shiftModification); - return vm; - case 6: - vm = explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); - return vm; + switch (randomType) { + case ADD: + return new IntegerAddModification(modification); + case SUBTRACT: + return new IntegerSubtractModification(modification); + case XOR: + return new IntegerXorModification(modification); + case EXPLICIT: + return new IntegerExplicitValueModification(modification); + case SHIFT_LEFT: + return new IntegerShiftLeftModification(shiftModification); + case SHIFT_RIGHT: + return new IntegerShiftRightModification(shiftModification); + case EXPLICIT_FROM_FILE: + return explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); default: - return vm; + throw new IllegalStateException("Unexpected modification type: " + randomType); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index bbfd4f0..ca97a66 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -21,7 +21,10 @@ public class LongModificationFactory { - private static final int MODIFICATION_COUNT = 5; + private enum ModificationType { + ADD, SUBTRACT, XOR, EXPLICIT, EXPLICIT_FROM_FILE + } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_MODIFICATION_VALUE = 32000; @@ -88,27 +91,21 @@ public static synchronized List> modificationsFromFil public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); - int r = random.nextInt(MODIFICATION_COUNT); + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; long modification = random.nextInt(MAX_MODIFICATION_VALUE); - VariableModification vm = null; - switch (r) { - case 0: - vm = new LongAddModification(modification); - return vm; - case 1: - vm = new LongSubtractModification(modification); - return vm; - case 2: - vm = new LongXorModification(modification); - return vm; - case 3: - vm = new LongExplicitValueModification(modification); - return vm; - case 4: - vm = explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); - return vm; + switch (randomType) { + case ADD: + return new LongAddModification(modification); + case SUBTRACT: + return new LongSubtractModification(modification); + case XOR: + return new LongXorModification(modification); + case EXPLICIT: + return new LongExplicitValueModification(modification); + case EXPLICIT_FROM_FILE: + return explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); default: - return vm; + throw new IllegalStateException("Unexpected modification type: " + randomType); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java index 7b999e7..20e4d84 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java @@ -20,15 +20,10 @@ public class ByteModificationFactory { - private static final int BYTE_EXPLICIT_VALUE_MODIFICATION = 3; - - private static final int BYTE_XOR_MODIFICATION = 2; - - private static final int BYTE_SUBTRACT_MODIFICATION = 1; - - private static final int BYTE_ADD_MODIFICATION = 0; - - private static final int MODIFICATION_COUNT = 5; + private enum ModificationType { + ADD, SUBTRACT, XOR, EXPLICIT, EXPLICIT_FROM_FILE + } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static List> modificationsFromFile; @@ -94,27 +89,21 @@ public static synchronized List> modificationsFromFil public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); - int r = random.nextInt(MODIFICATION_COUNT); + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; byte modification = (byte) random.nextInt(Byte.MAX_VALUE); - VariableModification vm = null; - switch (r) { - case BYTE_ADD_MODIFICATION: - vm = new ByteAddModification(modification); - return vm; - case BYTE_SUBTRACT_MODIFICATION: - vm = new ByteSubtractModification(modification); - return vm; - case BYTE_XOR_MODIFICATION: - vm = new ByteXorModification(modification); - return vm; - case BYTE_EXPLICIT_VALUE_MODIFICATION: - vm = new ByteExplicitValueModification(modification); - return vm; - case 4: - vm = explicitValueFromFile(random.nextInt(Byte.MAX_VALUE)); - return vm; + switch (randomType) { + case ADD: + return new ByteAddModification(modification); + case SUBTRACT: + return new ByteSubtractModification(modification); + case XOR: + return new ByteXorModification(modification); + case EXPLICIT: + return new ByteExplicitValueModification(modification); + case EXPLICIT_FROM_FILE: + return explicitValueFromFile(random.nextInt(Byte.MAX_VALUE)); default: - return vm; + throw new IllegalStateException("Unexpected modification type: " + randomType); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index a81d708..0c352c3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -48,7 +48,7 @@ public void setAppendValue(final String appendValue) { public VariableModification getModifiedCopy() { Random r = new Random(); int index = r.nextInt(appendValue.length()); - char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); StringBuilder modifiedString = new StringBuilder(appendValue); modifiedString.setCharAt(index, randomChar); return new StringAppendValueModification(modifiedString.toString()); diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index 26c7fa6..0e48fb0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -51,7 +51,7 @@ public VariableModification getModifiedCopy() { } Random r = new Random(); int index = r.nextInt(explicitValue.length()); - char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); StringBuilder modifiedString = new StringBuilder(explicitValue); modifiedString.setCharAt(index, randomChar); return new StringExplicitValueModification(modifiedString.toString()); diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java index c6c9571..77455d2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -10,10 +10,20 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.RandomHelper; +import java.util.Random; + /** */ public class StringModificationFactory { - private static final int MAX_BYTE_LENGTH = 1000; + private enum ModificationType { + APPEND, PREPEND, EXPLICIT + } + private static final int MODIFICATION_COUNT = ModificationType.values().length; + + private static final int MAX_BYTE_LENGTH_INSERT = 200; + + private static final int MAX_BYTE_LENGTH_EXPLICIT = 1000; + public static VariableModification prependValue(final String value) { return new StringPrependValueModification(value); @@ -28,9 +38,33 @@ public static VariableModification explicitValue(final String value) { } public static VariableModification createRandomModification() { - int i = RandomHelper.getRandom().nextInt(MAX_BYTE_LENGTH); - byte[] randomBytes = new byte[i]; - RandomHelper.getRandom().nextBytes(randomBytes); - return explicitValue(new String(randomBytes)); + Random random = RandomHelper.getRandom(); + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; + int modificationArrayLength; + switch (randomType) { + case APPEND: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToAppend = new byte[modificationArrayLength]; + random.nextBytes(bytesToAppend); + return new StringAppendValueModification(new String(bytesToAppend)); + case PREPEND: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToPrepend = new byte[modificationArrayLength]; + random.nextBytes(bytesToPrepend); + return new StringPrependValueModification(new String(bytesToPrepend)); + case EXPLICIT: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_EXPLICIT); + byte[] explicitValue = new byte[modificationArrayLength]; + random.nextBytes(explicitValue); + return new StringExplicitValueModification(new String(explicitValue)); + default: + throw new IllegalStateException("Unexpected modification type: " + randomType); + } } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index 2fdaeee..09cfb16 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -48,7 +48,7 @@ public void setPrependValue(final String prependValue) { public VariableModification getModifiedCopy() { Random r = new Random(); int index = r.nextInt(prependValue.length()); - char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE);; + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); StringBuilder modifiedString = new StringBuilder(prependValue); modifiedString.setCharAt(index, randomChar); return new StringPrependValueModification(modifiedString.toString()); From 753cf1be014b0db8cca7470f2ea8a86e21e6e67d Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Oct 2024 14:48:58 +0200 Subject: [PATCH 06/50] Create StingInsertValueModification class. Very similar to the ByteArrayInsertModification class. To make the String modifiable variable more complete. Naming it InsertValue to keep it consistent with append and prepend, though the other Modification classes put "value" only behind Explicit Modifications. --- .../ModifiableVariable.java | 6 +- .../ByteArrayInsertModification.java | 4 +- .../string/StringInsertValueModification.java | 122 ++++++++++++++++++ .../string/StringModificationFactory.java | 28 +++- .../modifiablevariable/util/Modifiable.java | 4 + 5 files changed, 159 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index fe196ed..1e7349b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -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; @@ -149,7 +150,10 @@ public abstract class ModifiableVariable implements Serializable { name = "StringAppendValueModification"), @XmlElement( type = StringExplicitValueModification.class, - name = "StringExplicitValueModification") + name = "StringExplicitValueModification"), + @XmlElement( + type = StringInsertValueModification.class, + name = "StringInsertValueModification") }) private VariableModification modification = null; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java index 64c4ab5..53f43bb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java @@ -53,13 +53,13 @@ protected byte[] modifyImplementationHook(byte[] input) { return input; } } - if (startPosition > input.length) { + 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); diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java new file mode 100644 index 0000000..f18e84f --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -0,0 +1,122 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.string; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import java.util.Objects; +import java.util.Random; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"insertValue", "modificationFilter"}) +public class StringInsertValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + private static final int MAX_INSERT_MODIFIER = 32; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String insertValue; + + private int startPosition; + + public StringInsertValueModification() {} + + public StringInsertValueModification(final String insertValue, int startPosition) { + this.insertValue = insertValue; + this.startPosition = startPosition; + } + + @Override + protected String modifyImplementationHook(final String input) { + int start = startPosition; + if (start < 0) { + start += input.length(); + if (start < 0) { + LOGGER.debug("Trying to insert from too negative start position. start = {}", startPosition); + return input; + } + } + if (start > input.length()) { + LOGGER.debug("Trying to insert behind the string. String Length:{} Insert Position:{}", input.length(), startPosition); + return input; + } + + return new StringBuilder(input).insert(start, insertValue).toString(); + } + + public String getinsertValue() { + return this.insertValue; + } + + public void setinsertValue(final String insertValue) { + this.insertValue = insertValue; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int index = r.nextInt(insertValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); + StringBuilder modifiedString = new StringBuilder(insertValue); + modifiedString.setCharAt(index, randomChar); + return new StringInsertValueModification(modifiedString.toString(), startPosition); + } else { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new StringInsertValueModification(insertValue, modifier); + } + } + + @Override + public int hashCode() { + int hash = 4; + hash = 83 * hash + Objects.hashCode(this.insertValue); + hash = 83 * hash + this.startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final StringInsertValueModification other = (StringInsertValueModification) obj; + if (this.startPosition != other.startPosition) { + return false; + } + return Objects.equals(this.insertValue, other.getinsertValue()); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java index 77455d2..f7fdea6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -16,7 +16,7 @@ public class StringModificationFactory { private enum ModificationType { - APPEND, PREPEND, EXPLICIT + APPEND, PREPEND, EXPLICIT, INSERT } private static final int MODIFICATION_COUNT = ModificationType.values().length; @@ -24,6 +24,8 @@ private enum ModificationType { private static final int MAX_BYTE_LENGTH_EXPLICIT = 1000; + private static final int MODIFIED_STRING_LENGTH_ESTIMATION = 50; + public static VariableModification prependValue(final String value) { return new StringPrependValueModification(value); @@ -37,10 +39,23 @@ public static VariableModification explicitValue(final String value) { return new StringExplicitValueModification(value); } - public static VariableModification createRandomModification() { + public static VariableModification insertValue(final String value, final int position) { + return new StringInsertValueModification(value, position); + } + + public static VariableModification createRandomModification(String originalValue) { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; int modificationArrayLength; + int modifiedArrayLength; + if (originalValue == null) { + modifiedArrayLength = MODIFIED_STRING_LENGTH_ESTIMATION; + } else { + modifiedArrayLength = originalValue.length(); + if (modifiedArrayLength == 0 || modifiedArrayLength == 1) { + randomType = ModificationType.EXPLICIT; + } + } switch (randomType) { case APPEND: modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); @@ -63,6 +78,15 @@ public static VariableModification createRandomModification() { byte[] explicitValue = new byte[modificationArrayLength]; random.nextBytes(explicitValue); return new StringExplicitValueModification(new String(explicitValue)); + case INSERT: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToInsert = new byte[modificationArrayLength]; + random.nextBytes(bytesToInsert); + int insertPosition = random.nextInt(modifiedArrayLength); + return new StringInsertValueModification(new String(bytesToInsert), insertPosition); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index 80c0d8f..d87dd42 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -114,6 +114,10 @@ public static ModifiableBoolean explicit(Boolean b) { public static ModifiableString explicit(String s) { return getModifiableStringWithModification(StringModificationFactory.explicitValue(s)); } + public static ModifiableString insert(String s, int position) { + return getModifiableStringWithModification(StringModificationFactory.insertValue(s, position)); + } + public static ModifiableByteArray xor(byte[] b, int position) { return getModifiableByteArrayWithModification( From 457a67b4b2244489282c313a608efce3b08b3d04 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 14 Oct 2024 14:55:12 +0200 Subject: [PATCH 07/50] Fix Typo getinsertValue to getInsertValue --- .../string/StringInsertValueModification.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index f18e84f..2cd29a1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -55,11 +55,11 @@ protected String modifyImplementationHook(final String input) { return new StringBuilder(input).insert(start, insertValue).toString(); } - public String getinsertValue() { + public String getInsertValue() { return this.insertValue; } - public void setinsertValue(final String insertValue) { + public void setInsertValue(final String insertValue) { this.insertValue = insertValue; } @@ -117,6 +117,6 @@ public boolean equals(Object obj) { if (this.startPosition != other.startPosition) { return false; } - return Objects.equals(this.insertValue, other.getinsertValue()); + return Objects.equals(this.insertValue, other.getInsertValue()); } } From fc9d71b4c567e37f512fdcf9a7ac4b519ba5b8a1 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Tue, 12 Nov 2024 11:31:17 +0100 Subject: [PATCH 08/50] fix bytesToLong --- .../de/rub/nds/modifiablevariable/util/ArrayConverter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java index 4ad6398..5449b1e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java @@ -119,10 +119,10 @@ public static int bytesToInt(byte[] value) { * @return long */ public static long bytesToLong(byte[] value) { - int result = 0; + long result = 0; int shift = 0; for (int i = value.length - 1; i >= 0; i--) { - result += (value[i] & 0xFF) << shift; + result += ((long) (value[i] & 0xFF)) << shift; shift += 8; } return result; @@ -188,8 +188,7 @@ public static String bytesToHexString( */ public static String bytesToRawHexString(byte[] array) { StringBuilder result = new StringBuilder(); - for (int i = 0; i < array.length; i++) { - byte b = array[i]; + for (byte b : array) { result.append(String.format("%02X", b)); } return result.toString(); From 8599859f89d3bfe4c057e6500ed55af125880b6e Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 20 Nov 2024 14:48:14 +0100 Subject: [PATCH 09/50] Change the hashCode() function of all Modifications, so they have a bit more semantic. There is no real reason for this change. Now the magic numbers, are a little bit less magic (just counting up the different modifications) --- .../biginteger/BigIntegerAddModification.java | 2 +- .../biginteger/BigIntegerExplicitValueModification.java | 4 ++-- .../biginteger/BigIntegerMultiplyModification.java | 4 ++-- .../biginteger/BigIntegerShiftLeftModification.java | 2 +- .../biginteger/BigIntegerShiftRightModification.java | 2 +- .../biginteger/BigIntegerSubtractModification.java | 4 ++-- .../biginteger/BigIntegerXorModification.java | 2 +- .../bool/BooleanExplicitValueModification.java | 2 +- .../bytearray/ByteArrayDeleteModification.java | 4 ++-- .../bytearray/ByteArrayExplicitValueModification.java | 4 ++-- .../bytearray/ByteArrayInsertModification.java | 4 ++-- .../bytearray/ByteArrayShuffleModification.java | 4 ++-- .../bytearray/ByteArrayXorModification.java | 4 ++-- .../modifiablevariable/integer/IntegerAddModification.java | 4 ++-- .../integer/IntegerExplicitValueModification.java | 2 +- .../integer/IntegerShiftLeftModification.java | 2 +- .../integer/IntegerShiftRightModification.java | 4 ++-- .../integer/IntegerSubtractModification.java | 2 +- .../modifiablevariable/integer/IntegerXorModification.java | 4 ++-- .../nds/modifiablevariable/longint/LongAddModification.java | 2 +- .../longint/LongExplicitValueModification.java | 4 ++-- .../longint/LongSubtractModification.java | 2 +- .../nds/modifiablevariable/longint/LongXorModification.java | 4 ++-- .../modifiablevariable/singlebyte/ByteAddModification.java | 4 ++-- .../singlebyte/ByteExplicitValueModification.java | 2 +- .../singlebyte/ByteSubtractModification.java | 4 ++-- .../modifiablevariable/singlebyte/ByteXorModification.java | 2 +- .../string/StringAppendValueModification.java | 4 ++-- .../string/StringExplicitValueModification.java | 4 ++-- .../string/StringInsertValueModification.java | 6 +++--- .../string/StringPrependValueModification.java | 4 ++-- 31 files changed, 51 insertions(+), 51 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index d546790..06f69e7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 41 * hash + Objects.hashCode(this.summand); + hash = 51 * hash + Objects.hashCode(this.summand); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index 6593141..780d0b3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -58,8 +58,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 41 * hash + Objects.hashCode(this.explicitValue); + int hash = 7; + hash = 52 * hash + Objects.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 4ffe0ca..97376ea 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -55,8 +55,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 61 * hash + Objects.hashCode(this.factor); + int hash = 7; + hash = 53 * hash + Objects.hashCode(this.factor); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index 0c058b3..b40fef8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -54,7 +54,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + this.shift; + hash = 54 * hash + this.shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index 9d30b4b..623c7ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -54,7 +54,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + this.shift; + hash = 55 * hash + this.shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index 96e7819..9e57ec1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -55,8 +55,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 61 * hash + Objects.hashCode(this.subtrahend); + int hash = 7; + hash = 56 * hash + Objects.hashCode(this.subtrahend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index 035c0f7..d820ddf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + Objects.hashCode(this.xor); + hash = 57 * hash + Objects.hashCode(this.xor); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index 407e045..19dc3dc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -44,7 +44,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 29 * hash + (this.explicitValue ? 1 : 0); + hash = 21 * hash + (this.explicitValue ? 1 : 0); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index ed3152d..0c4964b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -107,8 +107,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 89 * hash + this.count; - hash = 89 * hash + this.startPosition; + hash = 81 * hash + this.count; + hash = 81 * hash + this.startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index c7c29ae..4bb3123 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -69,8 +69,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 53 * hash + Arrays.hashCode(this.explicitValue); + int hash = 7; + hash = 82 * hash + Arrays.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java index 53f43bb..c98b92e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java @@ -107,8 +107,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 59 * hash + Arrays.hashCode(this.bytesToInsert); - hash = 59 * hash + this.startPosition; + hash = 83 * hash + Arrays.hashCode(this.bytesToInsert); + hash = 83 * hash + this.startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 7b89915..d270ba2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -76,8 +76,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 71 * hash + Arrays.hashCode(this.shuffle); + int hash = 7; + hash = 84 * hash + Arrays.hashCode(this.shuffle); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index ac47705..1bc070b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -109,8 +109,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + Arrays.hashCode(this.xor); - hash = 97 * hash + this.startPosition; + hash = 85 * hash + Arrays.hashCode(this.xor); + hash = 85 * hash + this.startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index 8ad6d9a..1b4a9c4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -47,8 +47,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 23 * hash + Objects.hashCode(this.summand); + int hash = 7; + hash = 31 * hash + Objects.hashCode(this.summand); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 792f05a..32affca 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 53 * hash + Objects.hashCode(this.explicitValue); + hash = 32 * hash + Objects.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index dcb56cc..31332f5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -59,7 +59,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 73 * hash + this.shift; + hash = 33 * hash + this.shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index 2969a13..4d0467f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -58,8 +58,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 59 * hash + this.shift; + int hash = 7; + hash = 34 * hash + this.shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index c527713..0d23a33 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -49,7 +49,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 23 * hash + Objects.hashCode(this.subtrahend); + hash = 35 * hash + Objects.hashCode(this.subtrahend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index dda4a30..07338a8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -52,8 +52,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 97 * hash + Objects.hashCode(this.xor); + int hash = 7; + hash = 36 * hash + Objects.hashCode(this.xor); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index 637297f..afde233 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -48,7 +48,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 43 * hash + Objects.hashCode(this.summand); + hash = 41 * hash + Objects.hashCode(this.summand); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index 8b4ae29..b7422ad 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -54,8 +54,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 43 * hash + Objects.hashCode(this.explicitValue); + int hash = 7; + hash = 42 * hash + Objects.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index e1cde29..7b554e0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -49,7 +49,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 97 * hash + Objects.hashCode(this.subtrahend); + hash = 43 * hash + Objects.hashCode(this.subtrahend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index 50afc21..fd73e4d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -52,8 +52,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 59 * hash + Objects.hashCode(this.xor); + int hash = 7; + hash = 44 * hash + Objects.hashCode(this.xor); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index 6cfcc7e..7850d34 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -50,8 +50,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 17 * hash + Objects.hashCode(this.summand); + int hash = 7; + hash = 11 * hash + Objects.hashCode(this.summand); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 0297cf8..d1f32c0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 79 * hash + Objects.hashCode(this.explicitValue); + hash = 12 * hash + Objects.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index 85c22ba..ebe1ca8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -51,8 +51,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 71 * hash + Objects.hashCode(this.subtrahend); + int hash = 7; + hash = 13 * hash + Objects.hashCode(this.subtrahend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index 21cad46..1b968a0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -57,7 +57,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 89 * hash + Objects.hashCode(this.xor); + hash = 14 * hash + Objects.hashCode(this.xor); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index 0c352c3..3d06002 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -56,8 +56,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 4; - hash = 83 * hash + Objects.hashCode(this.appendValue); + int hash = 7; + hash = 61 * hash + Objects.hashCode(this.appendValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index 0e48fb0..243c87c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -59,8 +59,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 3; - hash = 83 * hash + Objects.hashCode(this.explicitValue); + int hash = 7; + hash = 62 * hash + Objects.hashCode(this.explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index 2cd29a1..8fae6a1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -96,9 +96,9 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 4; - hash = 83 * hash + Objects.hashCode(this.insertValue); - hash = 83 * hash + this.startPosition; + int hash = 7; + hash = 63 * hash + Objects.hashCode(this.insertValue); + hash = 63 * hash + this.startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index 09cfb16..99164c3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -56,8 +56,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { - int hash = 5; - hash = 83 * hash + Objects.hashCode(this.prependValue); + int hash = 7; + hash = 64 * hash + Objects.hashCode(this.prependValue); return hash; } From 9789ee73f48139338f58d9f5ec85af7d5fce3337 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 09:26:37 +0100 Subject: [PATCH 10/50] Move the Moodifications from SSH-Fuzzer to ModifiableVaraible. SSH-Fuzzer hat defined some modificiations using the explicitValueModificationGenerator() method. It makes not much sense for me to define them not well structured in the SSH-Fuzzer (and abusing explicit modifications for this). The Mutations that got moved over are: - Append - Insert - Prepend for Integer, BigInteger, ByteArray and Long These Modifications do currently produce no usefull values for negative parameters, but if someone needs this, he should revise this. For our work, we mostly need only positiv values. I also added the missing modifications for long, since SFTP uses longs. And also added multiply modifiaction to integer. --- .../ModifiableVariable.java | 77 +++++++---- .../BigIntegerAppendValueModification.java | 76 +++++++++++ .../BigIntegerInsertValueModification.java | 120 ++++++++++++++++++ .../BigIntegerModificationFactory.java | 51 +++++++- .../BigIntegerMultiplyModification.java | 5 +- .../BigIntegerPrependValueModification.java | 76 +++++++++++ .../ByteArrayAppendValueModification.java | 91 +++++++++++++ ... => ByteArrayInsertValueModification.java} | 22 ++-- .../ByteArrayModificationFactory.java | 50 ++++---- .../ByteArrayPrependValueModification.java | 91 +++++++++++++ .../integer/IntegerAddModification.java | 4 +- .../IntegerAppendValueModification.java | 73 +++++++++++ .../IntegerExplicitValueModification.java | 4 +- .../IntegerInsertValueModification.java | 117 +++++++++++++++++ .../integer/IntegerModificationFactory.java | 52 +++++++- .../integer/IntegerMultiplyModification.java | 72 +++++++++++ .../IntegerPrependValueModification.java | 74 +++++++++++ .../integer/IntegerShiftLeftModification.java | 2 +- .../IntegerShiftRightModification.java | 2 +- .../integer/IntegerSubtractModification.java | 4 +- .../integer/IntegerXorModification.java | 4 +- .../longint/LongAddModification.java | 4 +- .../longint/LongAppendValueModification.java | 72 +++++++++++ .../LongExplicitValueModification.java | 4 +- .../longint/LongInsertValueModification.java | 113 +++++++++++++++++ .../longint/LongModificationFactory.java | 62 ++++++++- .../longint/LongMultiplyModification.java | 69 ++++++++++ .../longint/LongPrependValueModification.java | 72 +++++++++++ .../longint/LongShiftLeftModification.java | 82 ++++++++++++ .../longint/LongShiftRightModification.java | 82 ++++++++++++ .../longint/LongSubtractModification.java | 4 +- .../longint/LongXorModification.java | 8 +- .../string/ModifiableString.java | 2 +- .../modifiablevariable/util/Modifiable.java | 78 +++++++++++- .../nds/modifiablevariable/explicit/long.vec | 31 +++++ .../bytearray/ModifiableByteArrayTest.java | 10 +- .../ByteArraySerializationTest.java | 4 +- 37 files changed, 1660 insertions(+), 104 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java rename src/main/java/de/rub/nds/modifiablevariable/bytearray/{ByteArrayInsertModification.java => ByteArrayInsertValueModification.java} (81%) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java create mode 100644 src/main/resources/de/rub/nds/modifiablevariable/explicit/long.vec diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 1e7349b..d9334ec 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -7,32 +7,12 @@ */ 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.biginteger.*; 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.bytearray.*; +import de.rub.nds.modifiablevariable.integer.*; +import de.rub.nds.modifiablevariable.longint.*; import de.rub.nds.modifiablevariable.singlebyte.ByteAddModification; import de.rub.nds.modifiablevariable.singlebyte.ByteExplicitValueModification; import de.rub.nds.modifiablevariable.singlebyte.ByteSubtractModification; @@ -88,6 +68,15 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = BigIntegerMultiplyModification.class, name = "BigIntegerMultiplyModification"), + @XmlElement( + type = BigIntegerAppendValueModification.class, + name = "BigIntegerAppendValueModification"), + @XmlElement( + type = BigIntegerInsertValueModification.class, + name = "BigIntegerInsertValueModification"), + @XmlElement( + type = BigIntegerPrependValueModification.class, + name = "BigIntegerPrependValueModification"), @XmlElement( type = BooleanToggleModification.class, name = "BooleanToggleModification"), @@ -101,8 +90,14 @@ public abstract class ModifiableVariable implements Serializable { type = ByteArrayShuffleModification.class, name = "ByteArrayShuffleModification"), @XmlElement( - type = ByteArrayInsertModification.class, - name = "ByteArrayInsertModification"), + type = ByteArrayAppendValueModification.class, + name = "ByteArrayAppendValueModification"), + @XmlElement( + type = ByteArrayInsertValueModification.class, + name = "ByteArrayInsertValueModification"), + @XmlElement( + type = ByteArrayPrependValueModification.class, + name = "ByteArrayPrependValueModification"), @XmlElement( type = ByteArrayExplicitValueModification.class, name = "ByteArrayExplicitValueModification"), @@ -116,6 +111,9 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = IntegerSubtractModification.class, name = "IntegerSubtractModification"), + @XmlElement( + type = IntegerMultiplyModification.class, + name = "IntegerMultiplyModification"), @XmlElement( type = IntegerShiftRightModification.class, name = "IntegerShiftRightModification"), @@ -126,6 +124,15 @@ public abstract class ModifiableVariable implements Serializable { type = IntegerExplicitValueModification.class, name = "IntegerExplicitValueModification"), @XmlElement(type = IntegerAddModification.class, name = "IntegerAddModification"), + @XmlElement( + type = IntegerAppendValueModification.class, + name = "IntegerAppendValueModification"), + @XmlElement( + type = IntegerInsertValueModification.class, + name = "IntegerInsertValueModification"), + @XmlElement( + type = IntegerPrependValueModification.class, + name = "IntegerPrependValueModification"), @XmlElement(type = LongXorModification.class, name = "LongXorModification"), @XmlElement( type = LongSubtractModification.class, @@ -133,6 +140,24 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = LongExplicitValueModification.class, name = "LongExplicitValueModification"), + @XmlElement( + type = LongAppendValueModification.class, + name = "LongAppendValueModification"), + @XmlElement( + type = LongInsertValueModification.class, + name = "LongInsertValueModification"), + @XmlElement( + type = LongPrependValueModification.class, + name = "LongPrependValueModification"), + @XmlElement( + type = LongMultiplyModification.class, + name = "LongMultiplyModification"), + @XmlElement( + type = LongShiftLeftModification.class, + name = "LongShiftLeftModification"), + @XmlElement( + type = LongShiftRightModification.class, + name = "LongShiftRightModification"), @XmlElement(type = LongAddModification.class, name = "LongAddModification"), @XmlElement(type = ByteXorModification.class, name = "ByteXorModification"), @XmlElement( diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java new file mode 100644 index 0000000..5b1c385 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -0,0 +1,76 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.biginteger; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.math.BigInteger; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"appendValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class BigIntegerAppendValueModification extends VariableModification { + + private static final int MAX_APPEND_LENGTH = 8; + + private BigInteger appendValue; + + public BigIntegerAppendValueModification() {} + + public BigIntegerAppendValueModification(BigInteger bi) { + this.appendValue = bi; + } + + @Override + protected BigInteger modifyImplementationHook(BigInteger input) { + if (input == null) { + input = BigInteger.ZERO; + } + return input.shiftLeft(appendValue.bitLength()).add(appendValue); + } + + public BigInteger getAppendValue() { + return appendValue; + } + + public void setAppendValue(BigInteger appendValue) { + this.appendValue = appendValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new BigIntegerAppendValueModification(appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 59 * hash + Objects.hashCode(this.appendValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj; + return Objects.equals(this.appendValue, other.appendValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java new file mode 100644 index 0000000..9fa713b --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -0,0 +1,120 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.biginteger; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.math.BigInteger; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class BigIntegerInsertValueModification extends VariableModification { + + private static final int MAX_INSERT_LENGTH = 8; + private static final int MAX_POSITION_MODIFIER = 32; + + private BigInteger insertValue; + private int startPosition; + + public BigIntegerInsertValueModification() {} + + public BigIntegerInsertValueModification(BigInteger bi, int startPosition) { + this.insertValue = bi; + this.startPosition = startPosition; + } + + @Override + protected BigInteger modifyImplementationHook(BigInteger input) { + if (input == null) { + input = BigInteger.ZERO; + } + int originalValueLength = input.bitLength(); + int insertValueLength = insertValue.bitLength(); + int insertPosition = startPosition; + if (startPosition > originalValueLength) { + insertPosition = originalValueLength; + } else if (startPosition < 0) { + insertPosition = 0; + } + BigInteger mask = BigInteger.valueOf((1L << insertPosition) - 1); + + return input.shiftRight(insertPosition) + .shiftLeft(insertValueLength) + .and(insertValue) + .shiftLeft(insertPosition) + .add(mask.and(input)); + } + + public BigInteger getInsertValue() { + return insertValue; + } + + public void setInsertValue(BigInteger insertValue) { + this.insertValue = insertValue; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + return new BigIntegerInsertValueModification( + insertValue.add(new BigInteger(MAX_INSERT_LENGTH, r)), startPosition); + } else { + int modifier = r.nextInt(MAX_POSITION_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new BigIntegerInsertValueModification(insertValue, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 58 * hash + Objects.hashCode(this.insertValue); + hash = 58 * hash + Objects.hashCode(this.startPosition); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final BigIntegerInsertValueModification other = (BigIntegerInsertValueModification) obj; + if (this.startPosition != other.startPosition) { + return false; + } + return Objects.equals(this.insertValue, other.insertValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index 75158ce..ebb2c1e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -11,6 +11,7 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; import de.rub.nds.modifiablevariable.integer.IntegerModificationFactory; +import de.rub.nds.modifiablevariable.longint.LongModificationFactory; import de.rub.nds.modifiablevariable.util.RandomHelper; import java.io.BufferedReader; import java.io.IOException; @@ -25,15 +26,33 @@ public class BigIntegerModificationFactory { private enum ModificationType { - ADD, SUBTRACT, XOR, EXPLICIT, SHIFT_LEFT, SHIFT_RIGHT, EXPLICIT_FROM_FILE + ADD, + SUBTRACT, + MULTIPLY, + XOR, + EXPLICIT, + SHIFT_LEFT, + SHIFT_RIGHT, + EXPLICIT_FROM_FILE, + APPEND, + INSERT, + PREPEND } private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_MODIFICATION_VALUE = 320000; + private static final int MAX_FILE_ENTRIES = 200; + private static final int MAX_MODIFICATION_SHIFT_VALUE = 50; + private static final int MAX_MODIFICATION_MULTIPLY_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_POSITION_VALUE = 50; + private static List> modificationsFromFile; public static BigIntegerAddModification add(final String summand) { @@ -94,6 +113,19 @@ public static VariableModification explicitValueFromFile(int value) return modifications.get(pos); } + public static VariableModification appendValue(final BigInteger value) { + return new BigIntegerAppendValueModification(value); + } + + public static VariableModification insertValue( + final BigInteger value, final int startPosition) { + return new BigIntegerInsertValueModification(value, startPosition); + } + + public static VariableModification prependValue(final BigInteger value) { + return new BigIntegerPrependValueModification(value); + } + /* * Interactive modification */ @@ -137,7 +169,7 @@ public static synchronized List> modificationsF modificationsFromFile = new LinkedList<>(); ClassLoader classLoader = ByteArrayModificationFactory.class.getClassLoader(); InputStream is = - classLoader.getResourceAsStream(IntegerModificationFactory.FILE_NAME); + classLoader.getResourceAsStream(LongModificationFactory.FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { @@ -158,12 +190,17 @@ public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; BigInteger modification = BigInteger.valueOf(random.nextInt(MAX_MODIFICATION_VALUE)); + BigInteger insert_modification = + BigInteger.valueOf(random.nextInt(MAX_MODIFICATION_INSERT_VALUE)); int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE); switch (randomType) { case ADD: return new BigIntegerAddModification(modification); case SUBTRACT: return new BigIntegerSubtractModification(modification); + case MULTIPLY: + return new BigIntegerMultiplyModification( + BigInteger.valueOf(random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE))); case XOR: return new BigIntegerXorModification(modification); case EXPLICIT: @@ -173,7 +210,15 @@ public static VariableModification createRandomModification() { case SHIFT_RIGHT: return new BigIntegerShiftRightModification(shiftModification); case EXPLICIT_FROM_FILE: - return explicitValueFromFile(MAX_MODIFICATION_VALUE); + return explicitValueFromFile(MAX_FILE_ENTRIES); + case APPEND: + return new BigIntegerAppendValueModification(insert_modification); + case INSERT: + return new BigIntegerInsertValueModification( + insert_modification, + random.nextInt(MAX_MODIFICATION_INSERT_POSITION_VALUE)); + case PREPEND: + return new BigIntegerPrependValueModification(insert_modification); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 97376ea..2f68fcb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -33,10 +33,7 @@ public BigIntegerMultiplyModification(BigInteger bi) { @Override protected BigInteger modifyImplementationHook(BigInteger input) { - if (input == null) { - input = BigInteger.ZERO; - } - return input.multiply(factor); + return (input == null) ? BigInteger.ZERO: input.multiply(factor); } public BigInteger getFactor() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java new file mode 100644 index 0000000..92f7f77 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -0,0 +1,76 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.biginteger; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.math.BigInteger; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"prependValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class BigIntegerPrependValueModification extends VariableModification { + + private static final int MAX_PREPEND_LENGTH = 8; + + private BigInteger prependValue; + + public BigIntegerPrependValueModification() {} + + public BigIntegerPrependValueModification(BigInteger bi) { + this.prependValue = bi; + } + + @Override + protected BigInteger modifyImplementationHook(BigInteger input) { + if (input == null) { + input = BigInteger.ZERO; + } + return prependValue.shiftLeft(input.bitLength()).add(input); + } + + public BigInteger getPrependValue() { + return prependValue; + } + + public void setPrependValue(BigInteger prependValue) { + this.prependValue = prependValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new BigIntegerPrependValueModification(prependValue.add(new BigInteger(MAX_PREPEND_LENGTH, new Random()))); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 60 * hash + Objects.hashCode(this.prependValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final BigIntegerPrependValueModification other = (BigIntegerPrependValueModification) obj; + return Objects.equals(this.prependValue, other.prependValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java new file mode 100644 index 0000000..e80a5bb --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -0,0 +1,91 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.bytearray; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.ArrayConverter; +import de.rub.nds.modifiablevariable.util.UnformattedByteArrayAdapter; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Arrays; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"bytesToAppend", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteArrayAppendValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) + private byte[] bytesToAppend; + + public ByteArrayAppendValueModification() {} + + public ByteArrayAppendValueModification(byte[] bytesToAppend) { + this.bytesToAppend = bytesToAppend; + } + + @Override + protected byte[] modifyImplementationHook(byte[] input) { + if (input == null) { + input = new byte[0]; + } + + return ArrayConverter.concatenate(input, bytesToAppend); + } + + public byte[] getBytesToAppend() { + return bytesToAppend; + } + + public void setBytesToAppend(byte[] bytesToAppend) { + this.bytesToAppend = bytesToAppend; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + int index = r.nextInt(bytesToAppend.length); + byte[] newValue = Arrays.copyOf(bytesToAppend, bytesToAppend.length); + newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE); + return new ByteArrayAppendValueModification(newValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 86 * hash + Arrays.hashCode(this.bytesToAppend); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ByteArrayAppendValueModification other = (ByteArrayAppendValueModification) obj; + return Arrays.equals(this.bytesToAppend, other.bytesToAppend); + } + + @Override + public String toString() { + return String.format("ByteArrayInsertModification{bytesToAppend=%s}", + ArrayConverter.bytesToHexString(bytesToAppend)); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java similarity index 81% rename from src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java rename to src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index c98b92e..2a87162 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -21,20 +21,20 @@ @XmlRootElement @XmlType(propOrder = {"bytesToInsert", "startPosition", "modificationFilter"}) @XmlAccessorType(XmlAccessType.FIELD) -public class ByteArrayInsertModification extends VariableModification { +public class ByteArrayInsertValueModification extends VariableModification { private static final int MAX_EXPLICIT_VALUE = 256; - private static final int MAX_INSERT_MODIFIER = 32; + private static final int MAX_POSITION_MODIFIER = 32; @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) private byte[] bytesToInsert; private int startPosition; - public ByteArrayInsertModification() {} + public ByteArrayInsertValueModification() {} - public ByteArrayInsertModification(byte[] bytesToInsert, int startPosition) { + public ByteArrayInsertValueModification(byte[] bytesToInsert, int startPosition) { this.bytesToInsert = bytesToInsert; this.startPosition = startPosition; } @@ -49,13 +49,11 @@ 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); - return input; + start = 0; } } if (start > input.length) { - LOGGER.debug("Trying to insert behind the Array. ArraySize:{} Insert Position:{}", input.length, startPosition); - return input; + start = input.length; } byte[] ret1 = Arrays.copyOf(input, start); byte[] ret3 = null; @@ -89,10 +87,10 @@ public VariableModification getModifiedCopy() { int index = r.nextInt(bytesToInsert.length); byte[] newValue = Arrays.copyOf(bytesToInsert, bytesToInsert.length); newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE); - return new ByteArrayInsertModification(newValue, startPosition); + return new ByteArrayInsertValueModification(newValue, startPosition); } else { byte[] newValue = Arrays.copyOf(bytesToInsert, bytesToInsert.length); - int modifier = r.nextInt(MAX_INSERT_MODIFIER); + int modifier = r.nextInt(MAX_POSITION_MODIFIER); if (r.nextBoolean()) { modifier *= -1; } @@ -100,7 +98,7 @@ public VariableModification getModifiedCopy() { if (modifier <= 0) { modifier = 1; } - return new ByteArrayInsertModification(newValue, modifier); + return new ByteArrayInsertValueModification(newValue, modifier); } } @@ -123,7 +121,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayInsertModification other = (ByteArrayInsertModification) obj; + final ByteArrayInsertValueModification other = (ByteArrayInsertValueModification) obj; if (this.startPosition != other.startPosition) { return false; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java index c87c5e5..f32e415 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java @@ -22,13 +22,13 @@ public class ByteArrayModificationFactory { private enum ModificationType { - XOR, INSERT, DELETE, EXPLICIT, DUPLICATE, EXPLICIT_FROM_FILE, SHUFFLE + XOR, APPEND, INSERT, PREPEND, DELETE, EXPLICIT, DUPLICATE, EXPLICIT_FROM_FILE, SHUFFLE } private static final int MODIFICATION_COUNT = ModificationType.values().length; - private static final int MAX_CONFIG_PARAMETER = 200; + private static final int MAX_BYTE_ARRAY_LENGTH = 200; - private static final int EXPLICIT_VALUE_RANDOM = 1000; + private static final int MAX_FILE_ENTRIES = 1000; private static final int MODIFIED_ARRAY_LENGTH_ESTIMATION = 50; @@ -48,13 +48,23 @@ public static VariableModification xor(final byte[] xor, final int start /** * * * - * @param bytesToInsert bytes to xor + * @param bytesToInsert bytes to insert * @param startPosition negative numbers mean that the position is taken from the end * @return variable modification */ - public static VariableModification insert( + public static VariableModification insertValue( final byte[] bytesToInsert, final int startPosition) { - return new ByteArrayInsertModification(bytesToInsert, startPosition); + return new ByteArrayInsertValueModification(bytesToInsert, startPosition); + } + + public static VariableModification appendValue( + final byte[] bytesToAppend) { + return new ByteArrayAppendValueModification(bytesToAppend); + } + + public static VariableModification prependValue( + final byte[] bytesToPrepend) { + return new ByteArrayPrependValueModification(bytesToPrepend); } /** @@ -132,44 +142,40 @@ public static VariableModification createRandomModification(byte[] origi randomType = ModificationType.EXPLICIT; } } + modificationArrayLength = random.nextInt(MAX_BYTE_ARRAY_LENGTH - 1) + 1; switch (randomType) { case XOR: - modificationArrayLength = random.nextInt(modifiedArrayLength); - if (modificationArrayLength == 0) { - modificationArrayLength++; - } byte[] xor = new byte[modificationArrayLength]; random.nextBytes(xor); startPosition = random.nextInt(modifiedArrayLength - modificationArrayLength); return new ByteArrayXorModification(xor, startPosition); + case APPEND: + byte[] bytesToAppend = new byte[modificationArrayLength]; + random.nextBytes(bytesToAppend); + return new ByteArrayAppendValueModification(bytesToAppend); case INSERT: - modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER); - if (modificationArrayLength == 0) { - modificationArrayLength++; - } byte[] bytesToInsert = new byte[modificationArrayLength]; random.nextBytes(bytesToInsert); - int insertPosition = random.nextInt(modifiedArrayLength); - return new ByteArrayInsertModification(bytesToInsert, insertPosition); + return new ByteArrayInsertValueModification(bytesToInsert, random.nextInt(modifiedArrayLength)); + case PREPEND: + byte[] bytesToPrepend = new byte[modificationArrayLength]; + random.nextBytes(bytesToPrepend); + return new ByteArrayPrependValueModification(bytesToPrepend); case DELETE: startPosition = random.nextInt(modifiedArrayLength - 1); int count = random.nextInt(modifiedArrayLength - startPosition); count++; return new ByteArrayDeleteModification(startPosition, count); case EXPLICIT: - modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER); - if (modificationArrayLength == 0) { - modificationArrayLength++; - } byte[] explicitValue = new byte[modificationArrayLength]; random.nextBytes(explicitValue); return new ByteArrayExplicitValueModification(explicitValue); case DUPLICATE: return new ByteArrayDuplicateModification(); case EXPLICIT_FROM_FILE: - return explicitValueFromFile(random.nextInt(EXPLICIT_VALUE_RANDOM)); + return explicitValueFromFile(random.nextInt(MAX_FILE_ENTRIES)); case SHUFFLE: - int shuffleSize = random.nextInt(MAX_CONFIG_PARAMETER); + int shuffleSize = random.nextInt(MAX_BYTE_ARRAY_LENGTH); byte[] shuffle = new byte[shuffleSize]; random.nextBytes(shuffle); return new ByteArrayShuffleModification(shuffle); diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java new file mode 100644 index 0000000..f1bfc26 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -0,0 +1,91 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.bytearray; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.ArrayConverter; +import de.rub.nds.modifiablevariable.util.UnformattedByteArrayAdapter; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Arrays; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"bytesToPrepend", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteArrayPrependValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) + private byte[] bytesToPrepend; + + public ByteArrayPrependValueModification() {} + + public ByteArrayPrependValueModification(byte[] bytesToPrepend) { + this.bytesToPrepend = bytesToPrepend; + } + + @Override + protected byte[] modifyImplementationHook(byte[] input) { + if (input == null) { + input = new byte[0]; + } + + return ArrayConverter.concatenate(bytesToPrepend, input); + } + + public byte[] getBytesToPrepend() { + return bytesToPrepend; + } + + public void setBytesToPrepend(byte[] bytesToPrepend) { + this.bytesToPrepend = bytesToPrepend; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + int index = r.nextInt(bytesToPrepend.length); + byte[] newValue = Arrays.copyOf(bytesToPrepend, bytesToPrepend.length); + newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE); + return new ByteArrayPrependValueModification(newValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 87 * hash + Arrays.hashCode(this.bytesToPrepend); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final ByteArrayPrependValueModification other = (ByteArrayPrependValueModification) obj; + return Arrays.equals(this.bytesToPrepend, other.bytesToPrepend); + } + + @Override + public String toString() { + return String.format("ByteArrayInsertModification{bytesToPrepend=%s}", + ArrayConverter.bytesToHexString(bytesToPrepend)); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index 1b4a9c4..a44ed33 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -23,8 +23,8 @@ public class IntegerAddModification extends VariableModification { public IntegerAddModification() {} - public IntegerAddModification(Integer bi) { - this.summand = bi; + public IntegerAddModification(Integer summand) { + this.summand = summand; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java new file mode 100644 index 0000000..067410f --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -0,0 +1,73 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"appendValue", "modificationFilter"}) +public class IntegerAppendValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + + private Integer appendValue; + + public IntegerAppendValueModification() {} + + public IntegerAppendValueModification(Integer appendValue) { + this.appendValue = appendValue; + } + + @Override + protected Integer modifyImplementationHook(Integer input) { + if (input == null) { + input = 0; + } + return (input << (Integer.SIZE - Integer.numberOfLeadingZeros((appendValue)))) + appendValue; + } + + public Integer getAppendValue() { + return appendValue; + } + + public void setAppendValue(Integer appendValue) { + this.appendValue = appendValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new IntegerAppendValueModification( + appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 38 * hash + Objects.hashCode(this.appendValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntegerAppendValueModification other = (IntegerAppendValueModification) obj; + return Objects.equals(this.appendValue, other.appendValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 32affca..0ad99c1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -23,8 +23,8 @@ public class IntegerExplicitValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + + private static final int MAX_POSITION_MODIFIER = 32; + + private Integer insertValue; + + private int startPosition; + + public IntegerInsertValueModification() {} + + public IntegerInsertValueModification(Integer insertValue, int startPosition) { + this.insertValue = insertValue; + this.startPosition = startPosition; + } + + @Override + protected Integer modifyImplementationHook(Integer input) { + if (input == null) { + input = 0; + } + int originalValueLength = Integer.SIZE - Integer.numberOfLeadingZeros((input)); + int insertValueLength = Integer.SIZE - Integer.numberOfLeadingZeros((insertValue)); + int insertPosition = startPosition; + if (startPosition > originalValueLength) { + insertPosition = originalValueLength; + } else if (startPosition < 0) { + insertPosition = 0; + } + int mask = ((1 << insertPosition) - 1); + + return (((input >> insertPosition) << insertValueLength) + insertValue) << insertPosition + (mask & input); + } + + public Integer getInsertValue() { + return insertValue; + } + + public void setInsertValue(Integer insertValue) { + this.insertValue = insertValue; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + return new IntegerInsertValueModification( + insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); + } else { + int modifier = r.nextInt(MAX_POSITION_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new IntegerInsertValueModification(insertValue, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 37 * hash + Objects.hashCode(this.insertValue); + hash = 37 * hash + this.startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntegerInsertValueModification other = (IntegerInsertValueModification) obj; + if (this.startPosition != other.startPosition) { + return false; + } + return Objects.equals(this.insertValue, other.insertValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java index 7b65d62..dd596e9 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java @@ -21,14 +21,33 @@ public class IntegerModificationFactory { private enum ModificationType { - ADD, SUBTRACT, XOR, EXPLICIT, SHIFT_LEFT, SHIFT_RIGHT, EXPLICIT_FROM_FILE + ADD, + SUBTRACT, + MULTIPLY, + XOR, + EXPLICIT, + SHIFT_LEFT, + SHIFT_RIGHT, + EXPLICIT_FROM_FILE, + APPEND, + INSERT, + PREPEND } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_MODIFICATION_VALUE = 32000; + private static final int MAX_FILE_ENTRIES = 200; + private static final int MAX_MODIFICATION_SHIFT_VALUE = 20; + private static final int MAX_MODIFICATION_MULTIPLY_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_POSITION_VALUE = 32; + private static List> modificationsFromFile; public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/integer.vec"; @@ -87,6 +106,23 @@ public static VariableModification explicitValueFromFile(int value) { return modifications.get(pos); } + public static VariableModification appendValue(final Integer value) { + return new IntegerAppendValueModification(value); + } + + public static VariableModification insertValue( + final Integer value, final int position) { + return new IntegerInsertValueModification(value, position); + } + + public static VariableModification prependValue(final Integer value) { + return new IntegerPrependValueModification(value); + } + + public static VariableModification multiply(final Integer value) { + return new IntegerMultiplyModification(value); + } + public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { @@ -111,12 +147,16 @@ public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; int modification = random.nextInt(MAX_MODIFICATION_VALUE); + int insert_modification = random.nextInt(MAX_MODIFICATION_INSERT_VALUE); int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE); switch (randomType) { case ADD: return new IntegerAddModification(modification); case SUBTRACT: return new IntegerSubtractModification(modification); + case MULTIPLY: + return new IntegerSubtractModification( + random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); case XOR: return new IntegerXorModification(modification); case EXPLICIT: @@ -126,7 +166,15 @@ public static VariableModification createRandomModification() { case SHIFT_RIGHT: return new IntegerShiftRightModification(shiftModification); case EXPLICIT_FROM_FILE: - return explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); + return explicitValueFromFile(random.nextInt(MAX_FILE_ENTRIES)); + case APPEND: + return new IntegerAppendValueModification(insert_modification); + case INSERT: + return new IntegerInsertValueModification( + insert_modification, + random.nextInt(MAX_MODIFICATION_INSERT_POSITION_VALUE)); + case PREPEND: + return new IntegerPrependValueModification(insert_modification); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java new file mode 100644 index 0000000..431b97a --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -0,0 +1,72 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"factor", "modificationFilter"}) +public class IntegerMultiplyModification extends VariableModification { + + private static final int MAX_FACTOR_MODIFIER = 256; + + private Integer factor; + + public IntegerMultiplyModification() {} + + public IntegerMultiplyModification(Integer factor) { + this.factor = factor; + } + + @Override + protected Integer modifyImplementationHook(Integer input) { + return (input == null) ? 0 : input * factor; + } + + public Integer getFactor() { + return factor; + } + + public void setFactor(Integer factor) { + this.factor = factor; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + return new IntegerMultiplyModification( + factor + r.nextInt(MAX_FACTOR_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 40 * hash + Objects.hashCode(this.factor); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntegerMultiplyModification other = (IntegerMultiplyModification) obj; + return Objects.equals(this.factor, other.factor); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java new file mode 100644 index 0000000..1061206 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -0,0 +1,74 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"prependValue", "modificationFilter"}) +public class IntegerPrependValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + + private Integer prependValue; + + public IntegerPrependValueModification() {} + + public IntegerPrependValueModification(Integer prependValue) { + this.prependValue = prependValue; + } + + @Override + protected Integer modifyImplementationHook(Integer input) { + if (input == null) { + input = 0; + } + + return (prependValue << (Integer.SIZE - Integer.numberOfLeadingZeros((input)))) + input; + } + + public Integer getPrependValue() { + return prependValue; + } + + public void setPrependValue(Integer prependValue) { + this.prependValue = prependValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new IntegerPrependValueModification( + prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 39 * hash + Objects.hashCode(this.prependValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntegerPrependValueModification other = (IntegerPrependValueModification) obj; + return Objects.equals(this.prependValue, other.prependValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index 31332f5..b422e87 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -28,7 +28,7 @@ public IntegerShiftLeftModification(int shift) { @Override protected Integer modifyImplementationHook(Integer input) { - return (input == null) ? 0 : input << shift; + return (input == null) ? 0 : input << shift % MAX_SHIFT_MODIFIER; } public int getShift() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index 4d0467f..fb503ec 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -28,7 +28,7 @@ public IntegerShiftRightModification(int shift) { @Override protected Integer modifyImplementationHook(final Integer input) { - return (input == null) ? 0 : input >> shift; + return (input == null) ? 0 : input >> shift % MAX_SHIFT_MODIFIER; } public int getShift() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index 0d23a33..b71c9ce 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -23,8 +23,8 @@ public class IntegerSubtractModification extends VariableModification { public IntegerSubtractModification() {} - public IntegerSubtractModification(Integer bi) { - this.subtrahend = bi; + public IntegerSubtractModification(Integer subtrahend) { + this.subtrahend = subtrahend; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index 07338a8..7931f10 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -23,8 +23,8 @@ public class IntegerXorModification extends VariableModification { public IntegerXorModification() {} - public IntegerXorModification(Integer bi) { - this.xor = bi; + public IntegerXorModification(Integer xor) { + this.xor = xor; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index afde233..781d17c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -23,8 +23,8 @@ public class LongAddModification extends VariableModification { public LongAddModification() {} - public LongAddModification(Long bi) { - this.summand = bi; + public LongAddModification(Long summand) { + this.summand = summand; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java new file mode 100644 index 0000000..cf163e9 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -0,0 +1,72 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"appendValue", "modificationFilter"}) +public class LongAppendValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + + private Long appendValue; + + public LongAppendValueModification() {} + + public LongAppendValueModification(Long appendValue) { + this.appendValue = appendValue; + } + + @Override + protected Long modifyImplementationHook(Long input) { + if (input == null) { + input = 0L; + } + return (input << (Long.SIZE - Long.numberOfLeadingZeros((appendValue)))) + appendValue; + } + + public Long getAppendValue() { + return appendValue; + } + + public void setAppendValue(Long appendValue) { + this.appendValue = appendValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new LongAppendValueModification(appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 45 * hash + Objects.hashCode(this.appendValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongAppendValueModification other = (LongAppendValueModification) obj; + return Objects.equals(this.appendValue, other.appendValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index b7422ad..765476b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -23,8 +23,8 @@ public class LongExplicitValueModification extends VariableModification { public LongExplicitValueModification() {} - public LongExplicitValueModification(Long bi) { - this.explicitValue = bi; + public LongExplicitValueModification(Long explicitValue) { + this.explicitValue = explicitValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java new file mode 100644 index 0000000..524f661 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -0,0 +1,113 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.integer.IntegerInsertValueModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) +public class LongInsertValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + private static final int MAX_POSITION_MODIFIER = 32; + + private Long insertValue; + private int startPosition; + + public LongInsertValueModification() {} + + public LongInsertValueModification(Long insertValue, int startPosition) { + this.insertValue = insertValue; + this.startPosition = startPosition; + } + + @Override + protected Long modifyImplementationHook(Long input) { + if (input == null) { + input = 0L; + } + int originalValueLength = Long.SIZE - Long.numberOfLeadingZeros((input)); + int insertValueLength = Long.SIZE - Long.numberOfLeadingZeros((insertValue)); + int insertPosition = startPosition; + if (startPosition > originalValueLength) { + insertPosition = originalValueLength; + } else if (startPosition < 0) { + insertPosition = 0; + } + long mask = ((1L << insertPosition) - 1); + + return (((input >> insertPosition) << insertValueLength) + insertValue) << insertPosition + (mask & input); + } + + public Long getInsertValue() { + return insertValue; + } + + public void setInsertValue(Long insertValue) { + this.insertValue = insertValue; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + return new LongInsertValueModification( + insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); + } else { + int modifier = r.nextInt(MAX_POSITION_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new LongInsertValueModification(insertValue, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 47 * hash + Objects.hashCode(this.insertValue); + hash = 47 * hash + Objects.hashCode(this.startPosition); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongInsertValueModification other = (LongInsertValueModification) obj; + if (this.startPosition != other.startPosition) { + return false; + } + return Objects.equals(this.insertValue, other.insertValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index ca97a66..afc6322 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -22,14 +22,31 @@ public class LongModificationFactory { private enum ModificationType { - ADD, SUBTRACT, XOR, EXPLICIT, EXPLICIT_FROM_FILE + ADD, SUBTRACT, MULTIPLY, XOR, EXPLICIT, + SHIFT_LEFT, + SHIFT_RIGHT, EXPLICIT_FROM_FILE, + APPEND, + INSERT, + PREPEND } private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_MODIFICATION_VALUE = 32000; + private static final int MAX_FILE_ENTRIES = 200; + + private static final int MAX_MODIFICATION_SHIFT_VALUE = 40; + + private static final int MAX_MODIFICATION_MULTIPLY_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_VALUE = 256; + + private static final int MAX_MODIFICATION_INSERT_POSITION_VALUE = 64; + private static List> modificationsFromFile; + public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/long.vec"; + public static LongAddModification add(final String summand) { return add(Long.parseLong(summand)); } @@ -68,13 +85,38 @@ public static VariableModification explicitValueFromFile(int value) { return modifications.get(pos); } + public static VariableModification appendValue(final Long value) { + return new LongAppendValueModification(value); + } + + public static VariableModification insertValue(final Long value, final int position) { + return new LongInsertValueModification(value, position); + } + + public static VariableModification prependValue(final Long value) { + return new LongPrependValueModification(value); + } + + public static VariableModification multiply(final Long factor) { + return new LongMultiplyModification(factor); + } + + public static VariableModification shiftLeft(final int shift) { + return new LongShiftLeftModification(shift); + } + + public static VariableModification shiftRight(final int shift) { + return new LongShiftRightModification(shift); + } + + public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { modificationsFromFile = new LinkedList<>(); ClassLoader classLoader = IntegerModificationFactory.class.getClassLoader(); InputStream is = - classLoader.getResourceAsStream(IntegerModificationFactory.FILE_NAME); + classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { @@ -93,17 +135,31 @@ public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; long modification = random.nextInt(MAX_MODIFICATION_VALUE); + long insert_modification = random.nextInt( MAX_MODIFICATION_INSERT_VALUE); + int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE); switch (randomType) { case ADD: return new LongAddModification(modification); case SUBTRACT: return new LongSubtractModification(modification); + case MULTIPLY: + return new LongMultiplyModification((long)random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); case XOR: return new LongXorModification(modification); case EXPLICIT: return new LongExplicitValueModification(modification); + case SHIFT_LEFT: + return new LongShiftLeftModification(shiftModification); + case SHIFT_RIGHT: + return new LongShiftRightModification(shiftModification); case EXPLICIT_FROM_FILE: - return explicitValueFromFile(random.nextInt(MAX_MODIFICATION_VALUE)); + return explicitValueFromFile(random.nextInt(MAX_FILE_ENTRIES)); + case APPEND: + return new LongAppendValueModification(insert_modification); + case INSERT: + return new LongInsertValueModification(insert_modification, random.nextInt(MAX_MODIFICATION_INSERT_POSITION_VALUE)); + case PREPEND: + return new LongPrependValueModification(insert_modification); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java new file mode 100644 index 0000000..1c9388e --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java @@ -0,0 +1,69 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"factor", "modificationFilter"}) +public class LongMultiplyModification extends VariableModification { + + private static final int MAX_FACTOR_MODIFIER = 256; + + private Long factor; + + public LongMultiplyModification() {} + + public LongMultiplyModification(Long factor) { + this.factor = factor; + } + + @Override + protected Long modifyImplementationHook(final Long input) { + return (input == null) ? 0L : input * factor; + } + + public Long getFactor() { + return factor; + } + + public void setFactor(Long factor) { + this.factor = factor; + } + + @Override + public VariableModification getModifiedCopy() { + return new LongMultiplyModification(factor + new Random().nextInt(MAX_FACTOR_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 48 * hash + Objects.hashCode(this.factor); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongMultiplyModification other = (LongMultiplyModification) obj; + return Objects.equals(this.factor, other.factor); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java new file mode 100644 index 0000000..1d035dc --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -0,0 +1,72 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"prependValue", "modificationFilter"}) +public class LongPrependValueModification extends VariableModification { + + private static final int MAX_VALUE_MODIFIER = 256; + + private Long prependValue; + + public LongPrependValueModification() {} + + public LongPrependValueModification(Long prependValue) { + this.prependValue = prependValue; + } + + @Override + protected Long modifyImplementationHook(Long input) { + if (input == null) { + input = 0L; + } + return (prependValue << (Long.SIZE - Long.numberOfLeadingZeros((input)))) + input; + } + + public Long getPrependValue() { + return prependValue; + } + + public void setPrependValue(Long prependValue) { + this.prependValue = prependValue; + } + + @Override + public VariableModification getModifiedCopy() { + return new LongPrependValueModification(prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 46 * hash + Objects.hashCode(this.prependValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongPrependValueModification other = (LongPrependValueModification) obj; + return Objects.equals(this.prependValue, other.prependValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java new file mode 100644 index 0000000..2cb6988 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java @@ -0,0 +1,82 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"shift", "modificationFilter"}) +public class LongShiftLeftModification extends VariableModification { + + private static final int MAX_SHIFT_MODIFIER = 64; + + private int shift; + + public LongShiftLeftModification() {} + + public LongShiftLeftModification(int shift) { + this.shift = shift; + } + + @Override + protected Long modifyImplementationHook(final Long input) { + return (input == null) ? 0L : input << shift % MAX_SHIFT_MODIFIER; + } + + public int getShift() { + return shift; + } + + public void setShift(int shift) { + this.shift = shift; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + int newShift; + if (r.nextBoolean()) { + newShift = shift + r.nextInt(MAX_SHIFT_MODIFIER); + } else { + newShift = shift - r.nextInt(MAX_SHIFT_MODIFIER); + } + if (newShift < 0) { + newShift = MAX_SHIFT_MODIFIER - 1; + } else if (newShift > MAX_SHIFT_MODIFIER - 1) { + newShift = 0; + } + + return new LongShiftLeftModification(newShift); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 49 * hash + Objects.hashCode(this.shift); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongShiftLeftModification other = (LongShiftLeftModification) obj; + return Objects.equals(this.shift, other.shift); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java new file mode 100644 index 0000000..1b2b9a0 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java @@ -0,0 +1,82 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"shift", "modificationFilter"}) +public class LongShiftRightModification extends VariableModification { + + private static final int MAX_SHIFT_MODIFIER = 64; + + private int shift; + + public LongShiftRightModification() {} + + public LongShiftRightModification(int shift) { + this.shift = shift; + } + + @Override + protected Long modifyImplementationHook(final Long input) { + return (input == null) ? 0L : input >> shift % MAX_SHIFT_MODIFIER; + } + + public int getShift() { + return shift; + } + + public void setShift(int shift) { + this.shift = shift; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + int newShift; + if (r.nextBoolean()) { + newShift = shift + r.nextInt(MAX_SHIFT_MODIFIER); + } else { + newShift = shift - r.nextInt(MAX_SHIFT_MODIFIER); + } + if (newShift < 0) { + newShift = MAX_SHIFT_MODIFIER - 1; + } else if (newShift > MAX_SHIFT_MODIFIER - 1) { + newShift = 0; + } + + return new LongShiftRightModification(newShift); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 50 * hash + Objects.hashCode(this.shift); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final LongShiftRightModification other = (LongShiftRightModification) obj; + return Objects.equals(this.shift, other.shift); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index 7b554e0..6c61701 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -23,8 +23,8 @@ public class LongSubtractModification extends VariableModification { public LongSubtractModification() {} - public LongSubtractModification(Long bi) { - this.subtrahend = bi; + public LongSubtractModification(Long subtrahend) { + this.subtrahend = subtrahend; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index fd73e4d..0cc8b3b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -23,8 +23,8 @@ public class LongXorModification extends VariableModification { public LongXorModification() {} - public LongXorModification(Long bi) { - this.xor = bi; + public LongXorModification(Long xor) { + this.xor = xor; } @Override @@ -44,9 +44,9 @@ public void setXor(Long xor) { public VariableModification getModifiedCopy() { Random r = new Random(); if (r.nextBoolean()) { - return new LongXorModification(xor + new Random().nextInt(MAX_XOR_MODIFIER)); + return new LongXorModification(xor + r.nextInt(MAX_XOR_MODIFIER)); } else { - return new LongXorModification(xor - new Random().nextInt(MAX_XOR_MODIFIER)); + return new LongXorModification(xor - r.nextInt(MAX_XOR_MODIFIER)); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 88076b2..05dd42a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -30,7 +30,7 @@ public ModifiableString() {} @Override protected void createRandomModification() { - VariableModification vm = StringModificationFactory.createRandomModification(); + VariableModification vm = StringModificationFactory.createRandomModification(null); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index d87dd42..e261f2c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -77,10 +77,47 @@ private static ModifiableString getModifiableStringWithModification( return modifiableString; } + public static ModifiableBigInteger prepend(BigInteger i) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.prependValue(i)); + } + + public static ModifiableByteArray prepend(byte[] b) { + return getModifiableByteArrayWithModification( + ByteArrayModificationFactory.prependValue(b)); + } + + public static ModifiableInteger prepend(Integer i) { + return getModifiableIntegerWithModification(IntegerModificationFactory.prependValue(i)); + } + + public static ModifiableLong prepend(Long l) { + return getModifiableLongWithModification(LongModificationFactory.prependValue(l)); + } + public static ModifiableString prepend(final String s) { return getModifiableStringWithModification(StringModificationFactory.prependValue(s)); } + + public static ModifiableBigInteger append(BigInteger i) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.appendValue(i)); + } + + public static ModifiableByteArray append(byte[] b) { + return getModifiableByteArrayWithModification( + ByteArrayModificationFactory.appendValue(b)); + } + + public static ModifiableInteger append(Integer i) { + return getModifiableIntegerWithModification(IntegerModificationFactory.appendValue(i)); + } + + public static ModifiableLong append(Long l) { + return getModifiableLongWithModification(LongModificationFactory.appendValue(l)); + } + public static ModifiableString append(final String s) { return getModifiableStringWithModification(StringModificationFactory.appendValue(s)); } @@ -114,6 +151,26 @@ public static ModifiableBoolean explicit(Boolean b) { public static ModifiableString explicit(String s) { return getModifiableStringWithModification(StringModificationFactory.explicitValue(s)); } + + + public static ModifiableBigInteger insert(BigInteger i, int position) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.insertValue(i, position)); + } + + public static ModifiableByteArray insert(byte[] b, int position) { + return getModifiableByteArrayWithModification( + ByteArrayModificationFactory.insertValue(b, position)); + } + + public static ModifiableInteger insert(Integer i, int position) { + return getModifiableIntegerWithModification(IntegerModificationFactory.insertValue(i, position)); + } + + public static ModifiableLong insert(Long l, int position) { + return getModifiableLongWithModification(LongModificationFactory.insertValue(l, position)); + } + public static ModifiableString insert(String s, int position) { return getModifiableStringWithModification(StringModificationFactory.insertValue(s, position)); } @@ -172,10 +229,6 @@ public static ModifiableLong sub(Long l) { return getModifiableLongWithModification(LongModificationFactory.sub(l)); } - public static ModifiableByteArray insert(byte[] b, int position) { - return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.insert(b, position)); - } public static ModifiableByteArray delete(int startPosition, int count) { return getModifiableByteArrayWithModification( @@ -203,6 +256,10 @@ public static ModifiableInteger shiftLeft(Integer i) { return getModifiableIntegerWithModification(IntegerModificationFactory.shiftLeft(i)); } + public static ModifiableLong shiftLeftLong(Integer i) { + return getModifiableLongWithModification(LongModificationFactory.shiftLeft(i)); + } + public static ModifiableBigInteger shiftRightBigInteger(Integer i) { return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.shiftRight(i)); } @@ -211,7 +268,20 @@ public static ModifiableBigInteger multiplyBigInteger(BigInteger i) { return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.multiply(i)); } + + public static ModifiableInteger multiply(Integer i) { + return getModifiableIntegerWithModification(IntegerModificationFactory.multiply(i)); + } + + public static ModifiableLong multiply(Long l) { + return getModifiableLongWithModification(LongModificationFactory.multiply(l)); + } + public static ModifiableInteger shiftRight(Integer i) { return getModifiableIntegerWithModification(IntegerModificationFactory.shiftRight(i)); } + + public static ModifiableLong shiftRightLong(Integer i) { + return getModifiableLongWithModification(LongModificationFactory.shiftRight(i)); + } } diff --git a/src/main/resources/de/rub/nds/modifiablevariable/explicit/long.vec b/src/main/resources/de/rub/nds/modifiablevariable/explicit/long.vec new file mode 100644 index 0000000..da14a61 --- /dev/null +++ b/src/main/resources/de/rub/nds/modifiablevariable/explicit/long.vec @@ -0,0 +1,31 @@ +-128 /* Overflow signed 8-bit when decremented */ +-1 /* */ +0 /* */ +1 /* */ +16 /* One-off with common buffer size */ +32 /* One-off with common buffer size */ +64 /* One-off with common buffer size */ +100 /* One-off with common buffer size */ +127 /* Overflow signed 8-bit when incremented */ +-32768 /* Overflow signed 16-bit when decremented */ +-129 /* Overflow signed 8-bit */ +128 /* Overflow signed 8-bit */ +255 /* Overflow unsig 8-bit when incremented */ +256 /* Overflow unsig 8-bit */ +512 /* One-off with common buffer size */ +1000 /* One-off with common buffer size */ +1024 /* One-off with common buffer size */ +4096 /* One-off with common buffer size */ +32767 /* Overflow signed 16-bit when incremented */ +-2147483648 /* Overflow signed 32-bit when decremented */ +-9223372036854775808 /* Overflow signed 64-bit when decremented */ +-100663046 /* Large negative number (endian-agnostic) */ +-32769 /* Overflow signed 16-bit */ +32768 /* Overflow signed 16-bit */ +65535 /* Overflow unsig 16-bit when incremented */ +65536 /* Overflow unsig 16 bit */ +100663045 /* Large positive number (endian-agnostic) */ +2147483647 /* Overflow signed 32-bit when incremented */ +9223372036854775807 /* Overflow signed 64-bit when incremented */ +4294967295 /* Overflow unsig 32-bit when incremented */ +4294967296 /* Overflow unsig 32-bit */ \ No newline at end of file diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index c030522..00961cf 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -123,7 +123,7 @@ public void testPrependBytes() { } VariableModification modifier = - ByteArrayModificationFactory.insert(modification1, 0); + ByteArrayModificationFactory.insertValue(modification1, 0); start.setModification(modifier); LOGGER.debug("Expected: {}", expResult); @@ -146,7 +146,7 @@ public void testAppendBytes() { } VariableModification modifier = - ByteArrayModificationFactory.insert(modification1, originalValue.length); + ByteArrayModificationFactory.insertValue(modification1, originalValue.length); start.setModification(modifier); LOGGER.debug("Expected: {}", expResult); @@ -246,21 +246,21 @@ public void testInsertBytes() { assumeTrue(modification1.length < originalValue.length); LOGGER.debug("Inserting negative Position"); VariableModification modifier = - ByteArrayModificationFactory.insert(modification1, -2 * originalValue.length); + ByteArrayModificationFactory.insertValue(modification1, -2 * originalValue.length); start.setModification(modifier); assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting empty Array"); byte[] emptyArray = new byte[0]; - modifier = ByteArrayModificationFactory.insert(emptyArray, 0); + modifier = ByteArrayModificationFactory.insertValue(emptyArray, 0); start.setModification(modifier); assertArrayEquals(originalValue, start.getValue()); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting to big Start position"); - modifier = ByteArrayModificationFactory.insert(modification1, originalValue.length * 2); + modifier = ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); start.setModification(modifier); assertArrayEquals(originalValue, start.getValue()); } diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java index 47e58ca..9aeba5c 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java @@ -54,7 +54,7 @@ public void setUp() throws JAXBException { ModifiableByteArray.class, ByteArrayDeleteModification.class, ByteArrayExplicitValueModification.class, - ByteArrayInsertModification.class, + ByteArrayInsertValueModification.class, ByteArrayXorModification.class); m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); @@ -81,7 +81,7 @@ public void testSerializeDeserializeSimple() throws Exception { @Test public void testSerializeDeserializeWithModification() throws Exception { VariableModification modifier = - ByteArrayModificationFactory.insert(new byte[] {1, 2}, 0); + ByteArrayModificationFactory.insertValue(new byte[] {1, 2}, 0); start.setModification(modifier); m.marshal(start, writer); From 413d6d4185d63cde4847131b80e52b043a5a8fc6 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 10:04:59 +0100 Subject: [PATCH 11/50] fix tests --- .../bytearray/ByteArrayInsertValueModification.java | 5 +---- .../string/StringInsertValueModification.java | 2 +- .../biginteger/BigIntegerModificationTest.java | 2 +- .../bytearray/ModifiableByteArrayTest.java | 9 ++++++--- .../modifiablevariable/mlong/LongModificationTest.java | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index 2a87162..77b8ece 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -47,10 +47,7 @@ protected byte[] modifyImplementationHook(byte[] input) { int start = startPosition; if (start < 0) { - start += input.length; - if (start < 0) { - start = 0; - } + start = 0; } if (start > input.length) { start = input.length; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index 8fae6a1..aae65f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -18,7 +18,7 @@ /** Modification that appends a string to the original value. */ @XmlRootElement -@XmlType(propOrder = {"insertValue", "modificationFilter"}) +@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) public class StringInsertValueModification extends VariableModification { private static final int MAX_EXPLICIT_VALUE = 256; diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java index d089dfa..d712e84 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java @@ -131,7 +131,7 @@ public void testExplicitValueFromFile() { result = start.getValue(); assertEquals(expectedResult, result); - modifier = BigIntegerModificationFactory.explicitValueFromFile(26); + modifier = BigIntegerModificationFactory.explicitValueFromFile(27); start.setModification(modifier); expectedResult = BigInteger.valueOf(2147483647); result = start.getValue(); diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 00961cf..738ca47 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -242,13 +242,14 @@ public void testDeleteBytes() { @Test public void testInsertBytes() { LOGGER.info("testInsertBytes"); - // Insert negative position, insert 0 bytes, insert too far + // Insert at too negative position, prepend bytes assumeTrue(modification1.length < originalValue.length); LOGGER.debug("Inserting negative Position"); VariableModification modifier = ByteArrayModificationFactory.insertValue(modification1, -2 * originalValue.length); start.setModification(modifier); - assertArrayEquals(start.getValue(), originalValue); + byte[] expResult = ArrayConverter.concatenate(modification1, originalValue); + assertArrayEquals(start.getValue(), expResult); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting empty Array"); @@ -257,12 +258,14 @@ public void testInsertBytes() { start.setModification(modifier); assertArrayEquals(originalValue, start.getValue()); + // Insert at too positive position, append bytes start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting to big Start position"); modifier = ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); start.setModification(modifier); - assertArrayEquals(originalValue, start.getValue()); + expResult = ArrayConverter.concatenate(originalValue, modification1); + assertArrayEquals(expResult, start.getValue()); } /** Test of add method, of class BigIntegerModificationFactory. */ diff --git a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java index 8de77de..1a9fe96 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java @@ -86,7 +86,7 @@ public void testExplicitValueFromFile() { result = start.getValue(); assertEquals(expectedResult, result); - modifier = LongModificationFactory.explicitValueFromFile(26); + modifier = LongModificationFactory.explicitValueFromFile(27); start.setModification(modifier); expectedResult = 2147483647L; result = start.getValue(); From ca69bbf15841061ba7a1225d67118a33d6c2bd85 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 11:11:58 +0100 Subject: [PATCH 12/50] Change the Insert Prepend and Append Modifications of Integer, BigInteger and Long, so that they actually make sense. Before the calculations where copied form SSH-Fuzzer, but they do not really produce values that makes any sense. Because the values were shifted and then a new value were added, but adding a value to a binary integer, does not produce the expected insertion. Now we insert the values bitwise, I see a use-case for this. e.g. in mask fields. Also let the insert position wrap around in all insert modifications. For int and long it wraps around the bit size. --- .../BigIntegerAppendValueModification.java | 2 +- .../BigIntegerInsertValueModification.java | 16 +++++++------- .../BigIntegerPrependValueModification.java | 2 +- .../ByteArrayInsertValueModification.java | 17 +++++++-------- .../IntegerAppendValueModification.java | 2 +- .../IntegerInsertValueModification.java | 21 +++++++++---------- .../IntegerPrependValueModification.java | 2 +- .../longint/LongAppendValueModification.java | 2 +- .../longint/LongInsertValueModification.java | 15 ++++++------- .../longint/LongPrependValueModification.java | 2 +- .../string/StringInsertValueModification.java | 17 +++++---------- .../bytearray/ModifiableByteArrayTest.java | 13 ++++++------ .../integer/IntegerModificationTest.java | 12 +++++++++++ 13 files changed, 65 insertions(+), 58 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index 5b1c385..36886ac 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -36,7 +36,7 @@ protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { input = BigInteger.ZERO; } - return input.shiftLeft(appendValue.bitLength()).add(appendValue); + return input.shiftLeft(appendValue.bitLength()).or(appendValue); } public BigInteger getAppendValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java index 9fa713b..9065dda 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -39,21 +39,23 @@ protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { input = BigInteger.ZERO; } + int originalValueLength = input.bitLength(); int insertValueLength = insertValue.bitLength(); - int insertPosition = startPosition; - if (startPosition > originalValueLength) { - insertPosition = originalValueLength; - } else if (startPosition < 0) { - insertPosition = 0; + + // Wrap around and also allow to insert at the end of the original value + int insertPosition = startPosition % (originalValueLength + 1); + if (startPosition < 0) { + insertPosition += originalValueLength; } + BigInteger mask = BigInteger.valueOf((1L << insertPosition) - 1); return input.shiftRight(insertPosition) .shiftLeft(insertValueLength) - .and(insertValue) + .or(insertValue) .shiftLeft(insertPosition) - .add(mask.and(input)); + .or(mask.and(input)); } public BigInteger getInsertValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 92f7f77..24d75d3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -36,7 +36,7 @@ protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { input = BigInteger.ZERO; } - return prependValue.shiftLeft(input.bitLength()).add(input); + return prependValue.shiftLeft(input.bitLength()).or(input); } public BigInteger getPrependValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index 77b8ece..7117b16 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -45,17 +45,16 @@ protected byte[] modifyImplementationHook(byte[] input) { input = new byte[0]; } - int start = startPosition; - if (start < 0) { - start = 0; + // Wrap around and also allow to insert at the end of the original value + int insertPosition = startPosition % (input.length + 1); + if (startPosition < 0) { + insertPosition += input.length; } - if (start > input.length) { - start = input.length; - } - byte[] ret1 = Arrays.copyOf(input, start); + + byte[] ret1 = Arrays.copyOf(input, insertPosition); byte[] ret3 = null; - if (start < input.length) { - ret3 = Arrays.copyOfRange(input, start, input.length); + if (insertPosition < input.length) { + ret3 = Arrays.copyOfRange(input, insertPosition, input.length); } return ArrayConverter.concatenate(ret1, bytesToInsert, ret3); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index 067410f..9448b59 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -32,7 +32,7 @@ protected Integer modifyImplementationHook(Integer input) { if (input == null) { input = 0; } - return (input << (Integer.SIZE - Integer.numberOfLeadingZeros((appendValue)))) + appendValue; + return (input << (Integer.SIZE - Integer.numberOfLeadingZeros((appendValue)))) | appendValue; } public Integer getAppendValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index ca51361..7c6ab01 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -8,11 +8,8 @@ package de.rub.nds.modifiablevariable.integer; import de.rub.nds.modifiablevariable.VariableModification; -import de.rub.nds.modifiablevariable.bytearray.ByteArrayInsertValueModification; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; -import java.math.BigInteger; -import java.util.Arrays; import java.util.Objects; import java.util.Random; @@ -40,17 +37,19 @@ protected Integer modifyImplementationHook(Integer input) { if (input == null) { input = 0; } - int originalValueLength = Integer.SIZE - Integer.numberOfLeadingZeros((input)); + int insertValueLength = Integer.SIZE - Integer.numberOfLeadingZeros((insertValue)); - int insertPosition = startPosition; - if (startPosition > originalValueLength) { - insertPosition = originalValueLength; - } else if (startPosition < 0) { - insertPosition = 0; + + // Wrap around integer size + int insertPosition = startPosition % Integer.SIZE; + if (startPosition < 0) { + insertPosition += Integer.SIZE - 1; } + int mask = ((1 << insertPosition) - 1); - return (((input >> insertPosition) << insertValueLength) + insertValue) << insertPosition + (mask & input); + return (((input >> insertPosition) << insertValueLength) | insertValue) + << insertPosition | (mask & input); } public Integer getInsertValue() { @@ -75,7 +74,7 @@ public VariableModification getModifiedCopy() { if (r.nextBoolean()) { return new IntegerInsertValueModification( - insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); + insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); } else { int modifier = r.nextInt(MAX_POSITION_MODIFIER); if (r.nextBoolean()) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index 1061206..975949e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -33,7 +33,7 @@ protected Integer modifyImplementationHook(Integer input) { input = 0; } - return (prependValue << (Integer.SIZE - Integer.numberOfLeadingZeros((input)))) + input; + return (prependValue << (Integer.SIZE - Integer.numberOfLeadingZeros((input)))) | input; } public Integer getPrependValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index cf163e9..05eb5ec 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -32,7 +32,7 @@ protected Long modifyImplementationHook(Long input) { if (input == null) { input = 0L; } - return (input << (Long.SIZE - Long.numberOfLeadingZeros((appendValue)))) + appendValue; + return (input << (Long.SIZE - Long.numberOfLeadingZeros((appendValue)))) | appendValue; } public Long getAppendValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index 524f661..9ffa355 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -36,17 +36,18 @@ protected Long modifyImplementationHook(Long input) { if (input == null) { input = 0L; } - int originalValueLength = Long.SIZE - Long.numberOfLeadingZeros((input)); + int insertValueLength = Long.SIZE - Long.numberOfLeadingZeros((insertValue)); - int insertPosition = startPosition; - if (startPosition > originalValueLength) { - insertPosition = originalValueLength; - } else if (startPosition < 0) { - insertPosition = 0; + + // Wrap around long size + int insertPosition = startPosition % Long.SIZE; + if (startPosition < 0) { + insertPosition += Long.SIZE - 1; } + long mask = ((1L << insertPosition) - 1); - return (((input >> insertPosition) << insertValueLength) + insertValue) << insertPosition + (mask & input); + return (((input >> insertPosition) << insertValueLength) | insertValue) << insertPosition | (mask & input); } public Long getInsertValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index 1d035dc..5dd6baf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -32,7 +32,7 @@ protected Long modifyImplementationHook(Long input) { if (input == null) { input = 0L; } - return (prependValue << (Long.SIZE - Long.numberOfLeadingZeros((input)))) + input; + return (prependValue << (Long.SIZE - Long.numberOfLeadingZeros((input)))) | input; } public Long getPrependValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index aae65f1..5a85f47 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -39,20 +39,13 @@ public StringInsertValueModification(final String insertValue, int startPosition @Override protected String modifyImplementationHook(final String input) { - int start = startPosition; - if (start < 0) { - start += input.length(); - if (start < 0) { - LOGGER.debug("Trying to insert from too negative start position. start = {}", startPosition); - return input; - } - } - if (start > input.length()) { - LOGGER.debug("Trying to insert behind the string. String Length:{} Insert Position:{}", input.length(), startPosition); - return input; + // Wrap around and also allow to insert at the end of the original value + int insertPosition = startPosition % (input.length() + 1); + if (startPosition < 0) { + insertPosition += input.length(); } - return new StringBuilder(input).insert(start, insertValue).toString(); + return new StringBuilder(input).insert(insertPosition, insertValue).toString(); } public String getInsertValue() { diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 738ca47..9578169 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -17,6 +17,7 @@ import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.Arrays; public class ModifiableByteArrayTest { @@ -242,13 +243,13 @@ public void testDeleteBytes() { @Test public void testInsertBytes() { LOGGER.info("testInsertBytes"); - // Insert at too negative position, prepend bytes + // Insert at negative position -> wrap around assumeTrue(modification1.length < originalValue.length); - LOGGER.debug("Inserting negative Position"); + LOGGER.debug("Inserting negative at position"); VariableModification modifier = ByteArrayModificationFactory.insertValue(modification1, -2 * originalValue.length); start.setModification(modifier); - byte[] expResult = ArrayConverter.concatenate(modification1, originalValue); + byte[] expResult = ArrayConverter.concatenate(Arrays.copyOf(originalValue, 1), modification1, Arrays.copyOfRange(originalValue, 1, originalValue.length)); assertArrayEquals(start.getValue(), expResult); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); @@ -258,13 +259,13 @@ public void testInsertBytes() { start.setModification(modifier); assertArrayEquals(originalValue, start.getValue()); - // Insert at too positive position, append bytes + // Insert at too positive position -> wrap around start = new ModifiableByteArray(); start.setOriginalValue(originalValue); - LOGGER.debug("Inserting to big Start position"); + LOGGER.debug("Inserting at too large position"); modifier = ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); start.setModification(modifier); - expResult = ArrayConverter.concatenate(originalValue, modification1); + expResult = ArrayConverter.concatenate(Arrays.copyOf(originalValue, originalValue.length - 1), modification1, Arrays.copyOfRange(originalValue, originalValue.length -1, originalValue.length)); assertArrayEquals(expResult, start.getValue()); } diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java index 05a7c21..127c422 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/IntegerModificationTest.java @@ -71,6 +71,18 @@ public void testExplicitValue() { assertEquals(Integer.valueOf(10), start.getOriginalValue()); } + @Test + public void testInsertValue() { + // expect: ...xx111xxxxxxxxxx + VariableModification modifier = IntegerModificationFactory.insertValue(7, 10); + start.setModification(modifier); + int mask = ((1 << 3) - 1) << 10; + expectedResult = 7; + result = (start.getValue() & mask) >> 10; + assertEquals(expectedResult, result); + assertEquals(Integer.valueOf(10), start.getOriginalValue()); + } + @Test public void testShiftLeft() { VariableModification modifier = IntegerModificationFactory.shiftLeft(2); From 3337cba12a4cdc42f4a92ed3b4971b2b0df80adb Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 11:12:42 +0100 Subject: [PATCH 13/50] run formatter --- .../BigIntegerAppendValueModification.java | 3 ++- .../BigIntegerModificationFactory.java | 4 +-- .../BigIntegerMultiplyModification.java | 2 +- .../BigIntegerPrependValueModification.java | 3 ++- .../bool/BooleanModificationFactory.java | 5 +++- .../ByteArrayAppendValueModification.java | 5 ++-- .../ByteArrayDeleteModification.java | 11 ++++++-- .../ByteArrayModificationFactory.java | 20 ++++++++++----- .../ByteArrayPrependValueModification.java | 5 ++-- .../IntegerAppendValueModification.java | 5 ++-- .../IntegerInsertValueModification.java | 4 +-- .../integer/IntegerMultiplyModification.java | 3 +-- .../IntegerPrependValueModification.java | 2 +- .../longint/LongAppendValueModification.java | 3 ++- .../longint/LongInsertValueModification.java | 6 ++--- .../longint/LongModificationFactory.java | 23 +++++++++++------ .../longint/LongPrependValueModification.java | 3 ++- .../singlebyte/ByteModificationFactory.java | 7 +++++- .../string/StringInsertValueModification.java | 3 +-- .../string/StringModificationFactory.java | 8 +++--- .../modifiablevariable/util/Modifiable.java | 25 ++++++++----------- .../bytearray/ModifiableByteArrayTest.java | 18 ++++++++++--- 22 files changed, 104 insertions(+), 64 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index 36886ac..6e47b20 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -49,7 +49,8 @@ public void setAppendValue(BigInteger appendValue) { @Override public VariableModification getModifiedCopy() { - return new BigIntegerAppendValueModification(appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); + return new BigIntegerAppendValueModification( + appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index ebb2c1e..0b04f0d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -10,7 +10,6 @@ import de.rub.nds.modifiablevariable.FileConfigurationException; import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; -import de.rub.nds.modifiablevariable.integer.IntegerModificationFactory; import de.rub.nds.modifiablevariable.longint.LongModificationFactory; import de.rub.nds.modifiablevariable.util.RandomHelper; import java.io.BufferedReader; @@ -168,8 +167,7 @@ public static synchronized List> modificationsF if (modificationsFromFile == null) { modificationsFromFile = new LinkedList<>(); ClassLoader classLoader = ByteArrayModificationFactory.class.getClassLoader(); - InputStream is = - classLoader.getResourceAsStream(LongModificationFactory.FILE_NAME); + InputStream is = classLoader.getResourceAsStream(LongModificationFactory.FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 2f68fcb..ffe8975 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -33,7 +33,7 @@ public BigIntegerMultiplyModification(BigInteger bi) { @Override protected BigInteger modifyImplementationHook(BigInteger input) { - return (input == null) ? BigInteger.ZERO: input.multiply(factor); + return (input == null) ? BigInteger.ZERO : input.multiply(factor); } public BigInteger getFactor() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 24d75d3..4e765eb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -49,7 +49,8 @@ public void setPrependValue(BigInteger prependValue) { @Override public VariableModification getModifiedCopy() { - return new BigIntegerPrependValueModification(prependValue.add(new BigInteger(MAX_PREPEND_LENGTH, new Random()))); + return new BigIntegerPrependValueModification( + prependValue.add(new BigInteger(MAX_PREPEND_LENGTH, new Random()))); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java index 66c009a..6ef65e1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java @@ -14,8 +14,11 @@ public class BooleanModificationFactory { private enum ModificationType { - EXPLICIT_TRUE, EXPLICIT_FALSE, TOGGLE + EXPLICIT_TRUE, + EXPLICIT_FALSE, + TOGGLE } + private static final int MODIFICATION_COUNT = ModificationType.values().length; public static VariableModification createRandomModification() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index e80a5bb..bcbb93f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -85,7 +85,8 @@ public boolean equals(Object obj) { @Override public String toString() { - return String.format("ByteArrayInsertModification{bytesToAppend=%s}", - ArrayConverter.bytesToHexString(bytesToAppend)); + return String.format( + "ByteArrayInsertModification{bytesToAppend=%s}", + ArrayConverter.bytesToHexString(bytesToAppend)); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 0c4964b..f3408d8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -45,13 +45,20 @@ 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("Bytes {}..{} cannot be deleted from {{}} of length {}", 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) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java index f32e415..0b2579a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java @@ -22,8 +22,17 @@ public class ByteArrayModificationFactory { private enum ModificationType { - XOR, APPEND, INSERT, PREPEND, DELETE, EXPLICIT, DUPLICATE, EXPLICIT_FROM_FILE, SHUFFLE + XOR, + APPEND, + INSERT, + PREPEND, + DELETE, + EXPLICIT, + DUPLICATE, + EXPLICIT_FROM_FILE, + SHUFFLE } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_BYTE_ARRAY_LENGTH = 200; @@ -57,13 +66,11 @@ public static VariableModification insertValue( return new ByteArrayInsertValueModification(bytesToInsert, startPosition); } - public static VariableModification appendValue( - final byte[] bytesToAppend) { + public static VariableModification appendValue(final byte[] bytesToAppend) { return new ByteArrayAppendValueModification(bytesToAppend); } - public static VariableModification prependValue( - final byte[] bytesToPrepend) { + public static VariableModification prependValue(final byte[] bytesToPrepend) { return new ByteArrayPrependValueModification(bytesToPrepend); } @@ -156,7 +163,8 @@ public static VariableModification createRandomModification(byte[] origi case INSERT: byte[] bytesToInsert = new byte[modificationArrayLength]; random.nextBytes(bytesToInsert); - return new ByteArrayInsertValueModification(bytesToInsert, random.nextInt(modifiedArrayLength)); + return new ByteArrayInsertValueModification( + bytesToInsert, random.nextInt(modifiedArrayLength)); case PREPEND: byte[] bytesToPrepend = new byte[modificationArrayLength]; random.nextBytes(bytesToPrepend); diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index f1bfc26..26b87eb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -85,7 +85,8 @@ public boolean equals(Object obj) { @Override public String toString() { - return String.format("ByteArrayInsertModification{bytesToPrepend=%s}", - ArrayConverter.bytesToHexString(bytesToPrepend)); + return String.format( + "ByteArrayInsertModification{bytesToPrepend=%s}", + ArrayConverter.bytesToHexString(bytesToPrepend)); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index 9448b59..10fadef 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -32,7 +32,8 @@ protected Integer modifyImplementationHook(Integer input) { if (input == null) { input = 0; } - return (input << (Integer.SIZE - Integer.numberOfLeadingZeros((appendValue)))) | appendValue; + return (input << (Integer.SIZE - Integer.numberOfLeadingZeros((appendValue)))) + | appendValue; } public Integer getAppendValue() { @@ -46,7 +47,7 @@ public void setAppendValue(Integer appendValue) { @Override public VariableModification getModifiedCopy() { return new IntegerAppendValueModification( - appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index 7c6ab01..4c273ab 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -48,8 +48,8 @@ protected Integer modifyImplementationHook(Integer input) { int mask = ((1 << insertPosition) - 1); - return (((input >> insertPosition) << insertValueLength) | insertValue) - << insertPosition | (mask & input); + return (((input >> insertPosition) << insertValueLength) | insertValue) << insertPosition + | (mask & input); } public Integer getInsertValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index 431b97a..e3c6c82 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -44,8 +44,7 @@ public void setFactor(Integer factor) { public VariableModification getModifiedCopy() { Random r = new Random(); - return new IntegerMultiplyModification( - factor + r.nextInt(MAX_FACTOR_MODIFIER)); + return new IntegerMultiplyModification(factor + r.nextInt(MAX_FACTOR_MODIFIER)); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index 975949e..f03775c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -47,7 +47,7 @@ public void setPrependValue(Integer prependValue) { @Override public VariableModification getModifiedCopy() { return new IntegerPrependValueModification( - prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index 05eb5ec..25c205f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -45,7 +45,8 @@ public void setAppendValue(Long appendValue) { @Override public VariableModification getModifiedCopy() { - return new LongAppendValueModification(appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + return new LongAppendValueModification( + appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index 9ffa355..cc793da 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -8,7 +8,6 @@ package de.rub.nds.modifiablevariable.longint; import de.rub.nds.modifiablevariable.VariableModification; -import de.rub.nds.modifiablevariable.integer.IntegerInsertValueModification; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; import java.util.Objects; @@ -47,7 +46,8 @@ protected Long modifyImplementationHook(Long input) { long mask = ((1L << insertPosition) - 1); - return (((input >> insertPosition) << insertValueLength) | insertValue) << insertPosition | (mask & input); + return (((input >> insertPosition) << insertValueLength) | insertValue) << insertPosition + | (mask & input); } public Long getInsertValue() { @@ -72,7 +72,7 @@ public VariableModification getModifiedCopy() { if (r.nextBoolean()) { return new LongInsertValueModification( - insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); + insertValue + r.nextInt(MAX_VALUE_MODIFIER), startPosition); } else { int modifier = r.nextInt(MAX_POSITION_MODIFIER); if (r.nextBoolean()) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index afc6322..549b135 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -22,13 +22,19 @@ public class LongModificationFactory { private enum ModificationType { - ADD, SUBTRACT, MULTIPLY, XOR, EXPLICIT, + ADD, + SUBTRACT, + MULTIPLY, + XOR, + EXPLICIT, SHIFT_LEFT, - SHIFT_RIGHT, EXPLICIT_FROM_FILE, + SHIFT_RIGHT, + EXPLICIT_FROM_FILE, APPEND, INSERT, PREPEND } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_MODIFICATION_VALUE = 32000; @@ -109,14 +115,12 @@ public static VariableModification shiftRight(final int shift) { return new LongShiftRightModification(shift); } - public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { modificationsFromFile = new LinkedList<>(); ClassLoader classLoader = IntegerModificationFactory.class.getClassLoader(); - InputStream is = - classLoader.getResourceAsStream(FILE_NAME); + InputStream is = classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { @@ -135,7 +139,7 @@ public static VariableModification createRandomModification() { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; long modification = random.nextInt(MAX_MODIFICATION_VALUE); - long insert_modification = random.nextInt( MAX_MODIFICATION_INSERT_VALUE); + long insert_modification = random.nextInt(MAX_MODIFICATION_INSERT_VALUE); int shiftModification = random.nextInt(MAX_MODIFICATION_SHIFT_VALUE); switch (randomType) { case ADD: @@ -143,7 +147,8 @@ public static VariableModification createRandomModification() { case SUBTRACT: return new LongSubtractModification(modification); case MULTIPLY: - return new LongMultiplyModification((long)random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); + return new LongMultiplyModification( + (long) random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); case XOR: return new LongXorModification(modification); case EXPLICIT: @@ -157,7 +162,9 @@ public static VariableModification createRandomModification() { case APPEND: return new LongAppendValueModification(insert_modification); case INSERT: - return new LongInsertValueModification(insert_modification, random.nextInt(MAX_MODIFICATION_INSERT_POSITION_VALUE)); + return new LongInsertValueModification( + insert_modification, + random.nextInt(MAX_MODIFICATION_INSERT_POSITION_VALUE)); case PREPEND: return new LongPrependValueModification(insert_modification); default: diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index 5dd6baf..61d7431 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -45,7 +45,8 @@ public void setPrependValue(Long prependValue) { @Override public VariableModification getModifiedCopy() { - return new LongPrependValueModification(prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); + return new LongPrependValueModification( + prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java index 20e4d84..200925e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java @@ -21,8 +21,13 @@ public class ByteModificationFactory { private enum ModificationType { - ADD, SUBTRACT, XOR, EXPLICIT, EXPLICIT_FROM_FILE + ADD, + SUBTRACT, + XOR, + EXPLICIT, + EXPLICIT_FROM_FILE } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static List> modificationsFromFile; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index 5a85f47..eb4e1dd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -12,7 +12,6 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - import java.util.Objects; import java.util.Random; @@ -40,7 +39,7 @@ public StringInsertValueModification(final String insertValue, int startPosition @Override protected String modifyImplementationHook(final String input) { // Wrap around and also allow to insert at the end of the original value - int insertPosition = startPosition % (input.length() + 1); + int insertPosition = startPosition % (input.length() + 1); if (startPosition < 0) { insertPosition += input.length(); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java index f7fdea6..56f4c65 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -9,15 +9,18 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.RandomHelper; - import java.util.Random; /** */ public class StringModificationFactory { private enum ModificationType { - APPEND, PREPEND, EXPLICIT, INSERT + APPEND, + PREPEND, + EXPLICIT, + INSERT } + private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_BYTE_LENGTH_INSERT = 200; @@ -26,7 +29,6 @@ private enum ModificationType { private static final int MODIFIED_STRING_LENGTH_ESTIMATION = 50; - public static VariableModification prependValue(final String value) { return new StringPrependValueModification(value); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index e261f2c..769b1ab 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -79,12 +79,11 @@ private static ModifiableString getModifiableStringWithModification( public static ModifiableBigInteger prepend(BigInteger i) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.prependValue(i)); + BigIntegerModificationFactory.prependValue(i)); } public static ModifiableByteArray prepend(byte[] b) { - return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.prependValue(b)); + return getModifiableByteArrayWithModification(ByteArrayModificationFactory.prependValue(b)); } public static ModifiableInteger prepend(Integer i) { @@ -99,15 +98,13 @@ public static ModifiableString prepend(final String s) { return getModifiableStringWithModification(StringModificationFactory.prependValue(s)); } - public static ModifiableBigInteger append(BigInteger i) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.appendValue(i)); + BigIntegerModificationFactory.appendValue(i)); } public static ModifiableByteArray append(byte[] b) { - return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.appendValue(b)); + return getModifiableByteArrayWithModification(ByteArrayModificationFactory.appendValue(b)); } public static ModifiableInteger append(Integer i) { @@ -152,19 +149,19 @@ public static ModifiableString explicit(String s) { return getModifiableStringWithModification(StringModificationFactory.explicitValue(s)); } - public static ModifiableBigInteger insert(BigInteger i, int position) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.insertValue(i, position)); + BigIntegerModificationFactory.insertValue(i, position)); } public static ModifiableByteArray insert(byte[] b, int position) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.insertValue(b, position)); + ByteArrayModificationFactory.insertValue(b, position)); } public static ModifiableInteger insert(Integer i, int position) { - return getModifiableIntegerWithModification(IntegerModificationFactory.insertValue(i, position)); + return getModifiableIntegerWithModification( + IntegerModificationFactory.insertValue(i, position)); } public static ModifiableLong insert(Long l, int position) { @@ -172,10 +169,10 @@ public static ModifiableLong insert(Long l, int position) { } public static ModifiableString insert(String s, int position) { - return getModifiableStringWithModification(StringModificationFactory.insertValue(s, position)); + return getModifiableStringWithModification( + StringModificationFactory.insertValue(s, position)); } - public static ModifiableByteArray xor(byte[] b, int position) { return getModifiableByteArrayWithModification( ByteArrayModificationFactory.xor(b, position)); @@ -229,7 +226,6 @@ public static ModifiableLong sub(Long l) { return getModifiableLongWithModification(LongModificationFactory.sub(l)); } - public static ModifiableByteArray delete(int startPosition, int count) { return getModifiableByteArrayWithModification( ByteArrayModificationFactory.delete(startPosition, count)); @@ -268,7 +264,6 @@ public static ModifiableBigInteger multiplyBigInteger(BigInteger i) { return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.multiply(i)); } - public static ModifiableInteger multiply(Integer i) { return getModifiableIntegerWithModification(IntegerModificationFactory.multiply(i)); } diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 9578169..26b643f 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -13,11 +13,11 @@ import de.rub.nds.modifiablevariable.ModifiableVariableFactory; import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.ArrayConverter; +import java.util.Arrays; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Arrays; public class ModifiableByteArrayTest { @@ -249,7 +249,11 @@ public void testInsertBytes() { VariableModification modifier = ByteArrayModificationFactory.insertValue(modification1, -2 * originalValue.length); start.setModification(modifier); - byte[] expResult = ArrayConverter.concatenate(Arrays.copyOf(originalValue, 1), modification1, Arrays.copyOfRange(originalValue, 1, originalValue.length)); + byte[] expResult = + ArrayConverter.concatenate( + Arrays.copyOf(originalValue, 1), + modification1, + Arrays.copyOfRange(originalValue, 1, originalValue.length)); assertArrayEquals(start.getValue(), expResult); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); @@ -263,9 +267,15 @@ public void testInsertBytes() { start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting at too large position"); - modifier = ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); + modifier = + ByteArrayModificationFactory.insertValue(modification1, originalValue.length * 2); start.setModification(modifier); - expResult = ArrayConverter.concatenate(Arrays.copyOf(originalValue, originalValue.length - 1), modification1, Arrays.copyOfRange(originalValue, originalValue.length -1, originalValue.length)); + expResult = + ArrayConverter.concatenate( + Arrays.copyOf(originalValue, originalValue.length - 1), + modification1, + Arrays.copyOfRange( + originalValue, originalValue.length - 1, originalValue.length)); assertArrayEquals(expResult, start.getValue()); } From 0e71c4c4632aa19cd9821e89d44e7f8e25c9b74d Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 11:34:44 +0100 Subject: [PATCH 14/50] Add simple insertion test for long and BigInteger --- .../BigIntegerModificationTest.java | 21 +++++++++++++++++++ .../mlong/LongModificationTest.java | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java index d712e84..4076156 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationTest.java @@ -80,6 +80,27 @@ public void testExplicitValue() { assertEquals(BigInteger.TEN, start.getOriginalValue()); } + @Test + public void testInsertValue() { + // expect: 111xxxx + VariableModification modifier = + BigIntegerModificationFactory.insertValue(BigInteger.valueOf(7), 4); + start.setModification(modifier); + BigInteger mask = BigInteger.valueOf((1L << 3) - 1).shiftLeft(4); + expectedResult = BigInteger.valueOf(7); + result = start.getValue().and(mask).shiftRight(4); + assertEquals(expectedResult, result); + assertEquals(BigInteger.valueOf(10), start.getOriginalValue()); + + // expect: x111xxx + modifier = BigIntegerModificationFactory.insertValue(BigInteger.valueOf(7), 3); + start.setModification(modifier); + mask = BigInteger.valueOf((1L << 3) - 1).shiftLeft(3); + expectedResult = BigInteger.valueOf(7); + result = start.getValue().and(mask).shiftRight(3); + assertEquals(expectedResult, result); + } + /** Test of add method, of class BigIntegerModificationFactory. */ @Test public void testIsOriginalValueModified() { diff --git a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java index 1a9fe96..4b29ce1 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/mlong/LongModificationTest.java @@ -71,6 +71,18 @@ public void testExplicitValue() { assertEquals(Long.valueOf(10L), start.getOriginalValue()); } + @Test + public void testInsertValue() { + // expect: ...xx111xxxxxxxxxxxx + VariableModification modifier = LongModificationFactory.insertValue(7L, 12); + start.setModification(modifier); + int mask = ((1 << 3) - 1) << 12; + expectedResult = 7L; + result = (start.getValue() & mask) >> 12; + assertEquals(expectedResult, result); + assertEquals(Long.valueOf(10), start.getOriginalValue()); + } + /** Test of explicitValue from file method */ @Test public void testExplicitValueFromFile() { From 8c67bff2ae685e15dbbdfbff730b49cc6b8ab468 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 21 Nov 2024 13:11:02 +0100 Subject: [PATCH 15/50] Actually remove magic values from hashCode() method of all modifications and use standard prime number instead. --- .../rub/nds/modifiablevariable/ModifiableVariableHolder.java | 2 +- .../nds/modifiablevariable/ModifiableVariableProperty.java | 4 ++-- .../biginteger/BigIntegerAddModification.java | 2 +- .../biginteger/BigIntegerAppendValueModification.java | 2 +- .../biginteger/BigIntegerExplicitValueModification.java | 2 +- .../biginteger/BigIntegerInsertValueModification.java | 4 ++-- .../biginteger/BigIntegerMultiplyModification.java | 2 +- .../biginteger/BigIntegerPrependValueModification.java | 2 +- .../biginteger/BigIntegerShiftLeftModification.java | 2 +- .../biginteger/BigIntegerShiftRightModification.java | 2 +- .../biginteger/BigIntegerSubtractModification.java | 2 +- .../biginteger/BigIntegerXorModification.java | 2 +- .../bool/BooleanExplicitValueModification.java | 2 +- .../bytearray/ByteArrayAppendValueModification.java | 2 +- .../bytearray/ByteArrayDeleteModification.java | 4 ++-- .../bytearray/ByteArrayExplicitValueModification.java | 2 +- .../bytearray/ByteArrayInsertValueModification.java | 4 ++-- .../bytearray/ByteArrayPrependValueModification.java | 2 +- .../bytearray/ByteArrayShuffleModification.java | 2 +- .../bytearray/ByteArrayXorModification.java | 4 ++-- .../modifiablevariable/integer/IntegerAddModification.java | 2 +- .../integer/IntegerAppendValueModification.java | 2 +- .../integer/IntegerExplicitValueModification.java | 2 +- .../integer/IntegerInsertValueModification.java | 4 ++-- .../integer/IntegerMultiplyModification.java | 2 +- .../integer/IntegerPrependValueModification.java | 2 +- .../integer/IntegerShiftLeftModification.java | 2 +- .../integer/IntegerShiftRightModification.java | 2 +- .../integer/IntegerSubtractModification.java | 2 +- .../modifiablevariable/integer/IntegerXorModification.java | 2 +- .../nds/modifiablevariable/longint/LongAddModification.java | 2 +- .../longint/LongAppendValueModification.java | 2 +- .../longint/LongExplicitValueModification.java | 2 +- .../longint/LongInsertValueModification.java | 4 ++-- .../modifiablevariable/longint/LongMultiplyModification.java | 2 +- .../longint/LongPrependValueModification.java | 2 +- .../modifiablevariable/longint/LongShiftLeftModification.java | 2 +- .../longint/LongShiftRightModification.java | 2 +- .../modifiablevariable/longint/LongSubtractModification.java | 2 +- .../nds/modifiablevariable/longint/LongXorModification.java | 2 +- .../modifiablevariable/singlebyte/ByteAddModification.java | 2 +- .../singlebyte/ByteExplicitValueModification.java | 2 +- .../singlebyte/ByteSubtractModification.java | 2 +- .../modifiablevariable/singlebyte/ByteXorModification.java | 2 +- .../string/StringAppendValueModification.java | 2 +- .../string/StringExplicitValueModification.java | 2 +- .../string/StringInsertValueModification.java | 4 ++-- .../string/StringPrependValueModification.java | 2 +- 48 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java index 137fc7b..01286f0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java @@ -150,7 +150,7 @@ protected String getExtendedString(int depth) { } stringBuilder.append(field.getName()); stringBuilder.append(": "); - stringBuilder.append(tempObject.toString()); + stringBuilder.append(tempObject); stringBuilder.append("\n"); } } else { diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableProperty.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableProperty.java index e80a3d6..affcc4d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableProperty.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableProperty.java @@ -17,7 +17,7 @@ @Retention(RetentionPolicy.RUNTIME) public @interface ModifiableVariableProperty { - public enum Type { + enum Type { LENGTH, COUNT, PADDING, @@ -38,7 +38,7 @@ public enum Type { BEHAVIOR_SWITCH } - public enum Format { + enum Format { ASN1, PKCS1, NONE diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index 06f69e7..905c8e5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 51 * hash + Objects.hashCode(this.summand); + hash = 31 * hash + summand.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index 6e47b20..97f3f88 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -56,7 +56,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 59 * hash + Objects.hashCode(this.appendValue); + hash = 31 * hash + appendValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index 780d0b3..e4ea8dd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -59,7 +59,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 52 * hash + Objects.hashCode(this.explicitValue); + hash = 31 * hash + explicitValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java index 9065dda..cf7d7ef 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -97,8 +97,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 58 * hash + Objects.hashCode(this.insertValue); - hash = 58 * hash + Objects.hashCode(this.startPosition); + hash = 31 * hash + insertValue.hashCode(); + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index ffe8975..52975ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 53 * hash + Objects.hashCode(this.factor); + hash = 31 * hash + factor.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 4e765eb..5a813b7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -56,7 +56,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 60 * hash + Objects.hashCode(this.prependValue); + hash = 31 * hash + prependValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index b40fef8..6e42525 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -54,7 +54,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 54 * hash + this.shift; + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index 623c7ae..27470f7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -54,7 +54,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 55 * hash + this.shift; + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index 9e57ec1..d77d0f3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -56,7 +56,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 56 * hash + Objects.hashCode(this.subtrahend); + hash = 31 * hash + subtrahend.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index d820ddf..b416ff0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 57 * hash + Objects.hashCode(this.xor); + hash = 31 * hash + xor.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index 19dc3dc..5ca6a23 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -44,7 +44,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 21 * hash + (this.explicitValue ? 1 : 0); + hash = 31 * hash + (explicitValue ? 1231 : 1237); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index bcbb93f..95e2f2e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -64,7 +64,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 86 * hash + Arrays.hashCode(this.bytesToAppend); + hash = 31 * hash + Arrays.hashCode(bytesToAppend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index f3408d8..6000870 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -114,8 +114,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 81 * hash + this.count; - hash = 81 * hash + this.startPosition; + hash = 31 * hash + count; + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index 4bb3123..173a97e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -70,7 +70,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 82 * hash + Arrays.hashCode(this.explicitValue); + hash = 31 * hash + Arrays.hashCode(explicitValue); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index 7117b16..d1523e7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -101,8 +101,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 83 * hash + Arrays.hashCode(this.bytesToInsert); - hash = 83 * hash + this.startPosition; + hash = 31 * hash + Arrays.hashCode(bytesToInsert); + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 26b87eb..7358543 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -64,7 +64,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 87 * hash + Arrays.hashCode(this.bytesToPrepend); + hash = 31 * hash + Arrays.hashCode(bytesToPrepend); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index d270ba2..862bcb7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -77,7 +77,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 84 * hash + Arrays.hashCode(this.shuffle); + hash = 31 * hash + Arrays.hashCode(shuffle); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index 1bc070b..d8b19a4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -109,8 +109,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 85 * hash + Arrays.hashCode(this.xor); - hash = 85 * hash + this.startPosition; + hash = 31 * hash + Arrays.hashCode(xor); + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index a44ed33..fb1e15e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -48,7 +48,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 31 * hash + Objects.hashCode(this.summand); + hash = 31 * hash + summand; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index 10fadef..b2a1f4d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 38 * hash + Objects.hashCode(this.appendValue); + hash = 31 * hash + appendValue; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 0ad99c1..1f207cf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 32 * hash + Objects.hashCode(this.explicitValue); + hash = 31 * hash + explicitValue; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index 4c273ab..c5cf070 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -91,8 +91,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 37 * hash + Objects.hashCode(this.insertValue); - hash = 37 * hash + this.startPosition; + hash = 31 * hash + insertValue; + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index e3c6c82..5c2fced 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -50,7 +50,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 40 * hash + Objects.hashCode(this.factor); + hash = 31 * hash + factor; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index f03775c..67ff5ff 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 39 * hash + Objects.hashCode(this.prependValue); + hash = 31 * hash + prependValue; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index b422e87..f99cdfa 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -59,7 +59,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 33 * hash + this.shift; + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index fb503ec..367e16d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -59,7 +59,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 34 * hash + this.shift; + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index b71c9ce..0691607 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -49,7 +49,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 35 * hash + Objects.hashCode(this.subtrahend); + hash = 31 * hash + subtrahend; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index 7931f10..a91e8fb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 36 * hash + Objects.hashCode(this.xor); + hash = 31 * hash + xor; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index 781d17c..f37fbc2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -48,7 +48,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 41 * hash + Objects.hashCode(this.summand); + hash = 31 * hash + summand.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index 25c205f..b7177fd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -52,7 +52,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 45 * hash + Objects.hashCode(this.appendValue); + hash = 31 * hash + appendValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index 765476b..bfdc1b8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 42 * hash + Objects.hashCode(this.explicitValue); + hash = 31 * hash + explicitValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index cc793da..88a24f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -89,8 +89,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 47 * hash + Objects.hashCode(this.insertValue); - hash = 47 * hash + Objects.hashCode(this.startPosition); + hash = 31 * hash + insertValue.hashCode(); + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java index 1c9388e..0c1a9f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java @@ -48,7 +48,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 48 * hash + Objects.hashCode(this.factor); + hash = 31 * hash + factor.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index 61d7431..b803d6c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -52,7 +52,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 46 * hash + Objects.hashCode(this.prependValue); + hash = 31 * hash + prependValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java index 2cb6988..02cfbc3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java @@ -61,7 +61,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 49 * hash + Objects.hashCode(this.shift); + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java index 1b2b9a0..511eaf7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java @@ -61,7 +61,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 50 * hash + Objects.hashCode(this.shift); + hash = 31 * hash + shift; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index 6c61701..b43b0a8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -49,7 +49,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 43 * hash + Objects.hashCode(this.subtrahend); + hash = 31 * hash + subtrahend.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index 0cc8b3b..07bd614 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -53,7 +53,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 44 * hash + Objects.hashCode(this.xor); + hash = 31 * hash + xor.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index 7850d34..4e4e598 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -51,7 +51,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 11 * hash + Objects.hashCode(this.summand); + hash = 31 * hash + summand; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index d1f32c0..7a428b7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -55,7 +55,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 12 * hash + Objects.hashCode(this.explicitValue); + hash = 31 * hash + explicitValue; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index ebe1ca8..1df8179 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -52,7 +52,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 13 * hash + Objects.hashCode(this.subtrahend); + hash = 31 * hash + subtrahend; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index 1b968a0..cb10612 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -57,7 +57,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 14 * hash + Objects.hashCode(this.xor); + hash = 31 * hash + xor; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index 3d06002..5cef0f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -57,7 +57,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 61 * hash + Objects.hashCode(this.appendValue); + hash = 31 * hash + appendValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index 243c87c..e370f2b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -60,7 +60,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 62 * hash + Objects.hashCode(this.explicitValue); + hash = 31 * hash + explicitValue.hashCode(); return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index eb4e1dd..b1acfc4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -89,8 +89,8 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 63 * hash + Objects.hashCode(this.insertValue); - hash = 63 * hash + this.startPosition; + hash = 31 * hash + insertValue.hashCode(); + hash = 31 * hash + startPosition; return hash; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index 99164c3..d5a9fe5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -57,7 +57,7 @@ public VariableModification getModifiedCopy() { @Override public int hashCode() { int hash = 7; - hash = 64 * hash + Objects.hashCode(this.prependValue); + hash = 31 * hash + prependValue.hashCode(); return hash; } From 5f31e085db68fdd1b372490239be516de8d8c687 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 29 Nov 2024 15:24:31 +0100 Subject: [PATCH 16/50] Add copy constructors to all modifiable variables Also some refactoring --- .../FileConfigurationException.java | 4 +- .../ModifiableVariable.java | 274 ++++++++---------- .../ModifiableVariableFactory.java | 6 +- .../ModifiableVariableHolder.java | 39 +-- .../ModificationFilter.java | 2 +- .../VariableModification.java | 16 +- .../biginteger/BigIntegerAddModification.java | 20 +- .../BigIntegerAppendValueModification.java | 18 +- .../BigIntegerExplicitValueModification.java | 20 +- .../BigIntegerInsertValueModification.java | 20 +- .../BigIntegerInteractiveModification.java | 18 +- .../BigIntegerModificationFactory.java | 43 ++- .../BigIntegerMultiplyModification.java | 20 +- .../BigIntegerPrependValueModification.java | 18 +- .../BigIntegerShiftLeftModification.java | 14 +- .../BigIntegerShiftRightModification.java | 14 +- .../BigIntegerSubtractModification.java | 18 +- .../biginteger/BigIntegerXorModification.java | 18 +- .../biginteger/ModifiableBigInteger.java | 26 +- .../BooleanExplicitValueModification.java | 16 +- .../bool/BooleanModificationFactory.java | 8 +- .../bool/BooleanToggleModification.java | 14 +- .../bool/ModifiableBoolean.java | 27 +- .../ByteArrayAppendValueModification.java | 15 +- .../ByteArrayDeleteModification.java | 22 +- .../ByteArrayDuplicateModification.java | 14 +- .../ByteArrayExplicitValueModification.java | 17 +- .../ByteArrayInsertValueModification.java | 17 +- .../ByteArrayModificationFactory.java | 20 +- .../ByteArrayPrependValueModification.java | 15 +- .../ByteArrayShuffleModification.java | 16 +- .../bytearray/ByteArrayXorModification.java | 18 +- .../bytearray/ModifiableByteArray.java | 34 ++- .../filter/AccessModificationFilter.java | 6 +- .../filter/ModificationFilterFactory.java | 8 +- .../integer/IntegerAddModification.java | 16 +- .../IntegerAppendValueModification.java | 17 +- .../IntegerExplicitValueModification.java | 16 +- .../IntegerInsertValueModification.java | 24 +- .../integer/IntegerModificationFactory.java | 39 +-- .../integer/IntegerMultiplyModification.java | 16 +- .../IntegerPrependValueModification.java | 16 +- .../integer/IntegerShiftLeftModification.java | 16 +- .../IntegerShiftRightModification.java | 18 +- .../integer/IntegerSubtractModification.java | 18 +- .../integer/IntegerXorModification.java | 22 +- .../integer/ModifiableInteger.java | 24 +- .../length/ModifiableLengthField.java | 21 +- .../logging/ExtendedPatternLayout.java | 177 ++++++----- .../longint/LongAddModification.java | 18 +- .../longint/LongAppendValueModification.java | 16 +- .../LongExplicitValueModification.java | 16 +- .../longint/LongInsertValueModification.java | 24 +- .../longint/LongModificationFactory.java | 34 ++- .../longint/LongMultiplyModification.java | 18 +- .../longint/LongPrependValueModification.java | 16 +- .../longint/LongShiftLeftModification.java | 18 +- .../longint/LongShiftRightModification.java | 18 +- .../longint/LongSubtractModification.java | 18 +- .../longint/LongXorModification.java | 18 +- .../longint/ModifiableLong.java | 24 +- .../singlebyte/ByteAddModification.java | 18 +- .../ByteExplicitValueModification.java | 20 +- .../singlebyte/ByteModificationFactory.java | 22 +- .../singlebyte/ByteSubtractModification.java | 20 +- .../singlebyte/ByteXorModification.java | 18 +- .../singlebyte/ModifiableByte.java | 24 +- .../string/ModifiableString.java | 24 +- .../string/StringAppendValueModification.java | 24 +- .../StringExplicitValueModification.java | 14 +- .../string/StringInsertValueModification.java | 24 +- .../string/StringModificationFactory.java | 14 +- .../StringPrependValueModification.java | 24 +- .../util/ArrayConverter.java | 41 +-- .../util/BadFixedRandom.java | 1 + .../modifiablevariable/util/BadRandom.java | 7 +- .../util/ComparableByteArray.java | 7 +- .../modifiablevariable/util/Modifiable.java | 10 +- .../util/ModifiableVariableAnalyzer.java | 24 +- .../util/ModifiableVariableField.java | 11 +- .../util/ModifiableVariableListHolder.java | 11 +- .../modifiablevariable/util/RandomHelper.java | 6 +- .../util/ReflectionHelper.java | 24 +- .../modifiablevariable/util/StringUtil.java | 12 +- .../BigIntegerOperationConcatenationTest.java | 16 +- 85 files changed, 1245 insertions(+), 724 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/FileConfigurationException.java b/src/main/java/de/rub/nds/modifiablevariable/FileConfigurationException.java index e1d0f70..fbc01d7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/FileConfigurationException.java +++ b/src/main/java/de/rub/nds/modifiablevariable/FileConfigurationException.java @@ -9,7 +9,9 @@ public class FileConfigurationException extends RuntimeException { - public FileConfigurationException() {} + public FileConfigurationException() { + super(); + } public FileConfigurationException(Exception ex) { super(ex); diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index d9334ec..8488ab6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -32,8 +32,8 @@ /** * 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 + * to be defined transient to allow propOrder definition in subclasses, see: ... * * @param */ @@ -42,151 +42,134 @@ @XmlAccessorType(XmlAccessType.FIELD) public abstract class ModifiableVariable 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 = BigIntegerAppendValueModification.class, - name = "BigIntegerAppendValueModification"), - @XmlElement( - type = BigIntegerInsertValueModification.class, - name = "BigIntegerInsertValueModification"), - @XmlElement( - type = BigIntegerPrependValueModification.class, - name = "BigIntegerPrependValueModification"), - @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 = ByteArrayAppendValueModification.class, - name = "ByteArrayAppendValueModification"), - @XmlElement( - type = ByteArrayInsertValueModification.class, - name = "ByteArrayInsertValueModification"), - @XmlElement( - type = ByteArrayPrependValueModification.class, - name = "ByteArrayPrependValueModification"), - @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 = IntegerMultiplyModification.class, - name = "IntegerMultiplyModification"), - @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 = IntegerAppendValueModification.class, - name = "IntegerAppendValueModification"), - @XmlElement( - type = IntegerInsertValueModification.class, - name = "IntegerInsertValueModification"), - @XmlElement( - type = IntegerPrependValueModification.class, - name = "IntegerPrependValueModification"), - @XmlElement(type = LongXorModification.class, name = "LongXorModification"), - @XmlElement( - type = LongSubtractModification.class, - name = "LongSubtractModification"), - @XmlElement( - type = LongExplicitValueModification.class, - name = "LongExplicitValueModification"), - @XmlElement( - type = LongAppendValueModification.class, - name = "LongAppendValueModification"), - @XmlElement( - type = LongInsertValueModification.class, - name = "LongInsertValueModification"), - @XmlElement( - type = LongPrependValueModification.class, - name = "LongPrependValueModification"), - @XmlElement( - type = LongMultiplyModification.class, - name = "LongMultiplyModification"), - @XmlElement( - type = LongShiftLeftModification.class, - name = "LongShiftLeftModification"), - @XmlElement( - type = LongShiftRightModification.class, - name = "LongShiftRightModification"), - @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"), - @XmlElement( - type = StringInsertValueModification.class, - name = "StringInsertValueModification") - }) + @XmlElements({ + @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 = BigIntegerAppendValueModification.class, + name = "BigIntegerAppendValueModification"), + @XmlElement( + type = BigIntegerInsertValueModification.class, + name = "BigIntegerInsertValueModification"), + @XmlElement( + type = BigIntegerPrependValueModification.class, + name = "BigIntegerPrependValueModification"), + @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 = ByteArrayAppendValueModification.class, + name = "ByteArrayAppendValueModification"), + @XmlElement( + type = ByteArrayInsertValueModification.class, + name = "ByteArrayInsertValueModification"), + @XmlElement( + type = ByteArrayPrependValueModification.class, + name = "ByteArrayPrependValueModification"), + @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 = IntegerMultiplyModification.class, name = "IntegerMultiplyModification"), + @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 = IntegerAppendValueModification.class, + name = "IntegerAppendValueModification"), + @XmlElement( + type = IntegerInsertValueModification.class, + name = "IntegerInsertValueModification"), + @XmlElement( + type = IntegerPrependValueModification.class, + name = "IntegerPrependValueModification"), + @XmlElement(type = LongXorModification.class, name = "LongXorModification"), + @XmlElement(type = LongSubtractModification.class, name = "LongSubtractModification"), + @XmlElement( + type = LongExplicitValueModification.class, + name = "LongExplicitValueModification"), + @XmlElement(type = LongAppendValueModification.class, name = "LongAppendValueModification"), + @XmlElement(type = LongInsertValueModification.class, name = "LongInsertValueModification"), + @XmlElement( + type = LongPrependValueModification.class, + name = "LongPrependValueModification"), + @XmlElement(type = LongMultiplyModification.class, name = "LongMultiplyModification"), + @XmlElement(type = LongShiftLeftModification.class, name = "LongShiftLeftModification"), + @XmlElement(type = LongShiftRightModification.class, name = "LongShiftRightModification"), + @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"), + @XmlElement( + type = StringInsertValueModification.class, + name = "StringInsertValueModification") + }) private VariableModification modification = null; private Boolean createRandomModification; protected E assertEquals; - public ModifiableVariable() {} + protected ModifiableVariable() { + super(); + } + + protected ModifiableVariable(ModifiableVariable other) { + super(); + if (other != null) { + createRandomModification = other.createRandomModification; + modification = other.modification != null ? other.modification.createCopy() : null; + // Warning: Make sure to copy assertEquals in subclass correctly + assertEquals = other.assertEquals; + } + } public void setModification(VariableModification modification) { this.modification = modification; @@ -215,6 +198,8 @@ public E getValue() { protected abstract void createRandomModification(); + protected abstract ModifiableVariable createCopy(); + public void createRandomModificationAtRuntime() { createRandomModification = true; } @@ -224,13 +209,10 @@ public void createRandomModificationAtRuntime() { public abstract boolean validateAssertions(); public boolean containsAssertion() { - return (assertEquals != null); + return assertEquals != null; } public Boolean isCreateRandomModification() { - if (createRandomModification == null) { - return false; - } - return createRandomModification; + return Objects.requireNonNullElse(createRandomModification, false); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java index 19b9a22..4e3e3e9 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java @@ -16,7 +16,7 @@ import de.rub.nds.modifiablevariable.string.ModifiableString; import java.math.BigInteger; -public class ModifiableVariableFactory { +public final class ModifiableVariableFactory { public static ModifiableBigInteger createBigIntegerModifiableVariable() { return new ModifiableBigInteger(); @@ -94,5 +94,7 @@ public static ModifiableBoolean safelySetValue(ModifiableBoolean mv, Boolean val return mv; } - private ModifiableVariableFactory() {} + private ModifiableVariableFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java index 01286f0..073365f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java @@ -30,7 +30,7 @@ public abstract class ModifiableVariableHolder implements Serializable { * @return List of all modifiableVariables declared in this class */ public List getAllModifiableVariableFields() { - return ReflectionHelper.getFieldsUpTo(this.getClass(), null, ModifiableVariable.class); + return ReflectionHelper.getFieldsUpTo(getClass(), null, ModifiableVariable.class); } /** @@ -70,12 +70,12 @@ public ModifiableVariableHolder getRandomModifiableVariableHolder(Random random) public void reset() { List fields = getAllModifiableVariableFields(); - for (Field f : fields) { - f.setAccessible(true); + for (Field field : fields) { + field.setAccessible(true); ModifiableVariable mv = null; try { - mv = (ModifiableVariable) f.get(this); + mv = (ModifiableVariable) field.get(this); } catch (IllegalArgumentException | IllegalAccessException ex) { LOGGER.warn("Could not retrieve ModifiableVariables"); LOGGER.debug(ex); @@ -85,7 +85,7 @@ public void reset() { mv.setOriginalValue(null); } else { try { - f.set(this, null); + field.set(this, null); } catch (IllegalArgumentException | IllegalAccessException ex) { LOGGER.warn("Could not strip ModifiableVariable without Modification"); } @@ -95,17 +95,12 @@ public void reset() { } public String getExtendedString() { - StringBuilder sb = new StringBuilder(); - sb.append(getClass().getSimpleName()); - sb.append("{\n"); - sb.append(getExtendedString(1)); - sb.append("}\n"); - return sb.toString(); + return String.format("%s{\n%s}\n", getClass().getSimpleName(), getExtendedString(1)); } protected String getExtendedString(int depth) { StringBuilder stringBuilder = new StringBuilder(); - List fields = ReflectionHelper.getFieldsUpTo(this.getClass(), null, null); + List fields = ReflectionHelper.getFieldsUpTo(getClass(), null, null); for (Field field : fields) { field.setAccessible(true); // skip static @@ -122,41 +117,31 @@ protected String getExtendedString(int depth) { if (tempObject != null) { if (tempObject instanceof byte[]) { byte[] temp = (byte[]) tempObject; - for (int i = 0; i < depth; i++) { - stringBuilder.append("\t"); - } + stringBuilder.append("\t".repeat(Math.max(0, depth))); stringBuilder.append(field.getName()); stringBuilder.append(": "); stringBuilder.append(ArrayConverter.bytesToHexString(temp)); stringBuilder.append("\n"); } if (tempObject instanceof ModifiableVariableHolder) { - for (int i = 0; i < depth; i++) { - stringBuilder.append("\t"); - } + stringBuilder.append("\t".repeat(Math.max(0, depth))); stringBuilder.append(field.getName()); stringBuilder.append(":"); stringBuilder.append(tempObject.getClass().getSimpleName()); stringBuilder.append("{\n"); stringBuilder.append( ((ModifiableVariableHolder) tempObject).getExtendedString(depth + 1)); - for (int i = 0; i < depth; i++) { - stringBuilder.append("\t"); - } + stringBuilder.append("\t".repeat(Math.max(0, depth))); stringBuilder.append("}\n"); } else { - for (int i = 0; i < depth; i++) { - stringBuilder.append("\t"); - } + stringBuilder.append("\t".repeat(Math.max(0, depth))); stringBuilder.append(field.getName()); stringBuilder.append(": "); stringBuilder.append(tempObject); stringBuilder.append("\n"); } } else { - for (int i = 0; i < depth; i++) { - stringBuilder.append("\t"); - } + stringBuilder.append("\t".repeat(Math.max(0, depth))); stringBuilder.append(field.getName()); stringBuilder.append(": null\n"); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java b/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java index f7967f1..94f19f0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java @@ -15,7 +15,7 @@ * data. For example, only the first data access returns a modified value. This can be achieved * using a ModificationFilter object. */ -@XmlSeeAlso({AccessModificationFilter.class}) +@XmlSeeAlso(AccessModificationFilter.class) public abstract class ModificationFilter { public abstract boolean filterModification(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java index 56ceadf..6558dcd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java @@ -32,16 +32,12 @@ public abstract class VariableModification { * ModificationFilter is responsible for validating if the modification can be executed. */ @XmlElements( - value = { - @XmlElement( - type = AccessModificationFilter.class, - name = "AccessModificationFilter") - }) - private ModificationFilter modificationFilter = null; + @XmlElement(type = AccessModificationFilter.class, name = "AccessModificationFilter")) + private ModificationFilter modificationFilter; public E modify(E input) { E modifiedValue = modifyImplementationHook(input); - if ((modificationFilter == null) || (!modificationFilter.filterModification())) { + if (modificationFilter == null || !modificationFilter.filterModification()) { debug(modifiedValue); return modifiedValue; } else { @@ -53,8 +49,10 @@ public E modify(E input) { public abstract VariableModification getModifiedCopy(); + public abstract VariableModification createCopy(); + /** - * Debugging modified variables. Getting stack trace can be time consuming, thus we use + * Debugging modified variables. Getting stack trace can be time-consuming, thus we use * isDebugEnabled() function * * @param value variable modification that is going to be debugged @@ -78,7 +76,7 @@ protected void debug(E value) { } LOGGER.debug( "Using {} in function:\n {}\n New value: {}", - this.getClass().getSimpleName(), + getClass().getSimpleName(), stack[index], valueString); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index 905c8e5..cd55562 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -25,15 +25,18 @@ public class BigIntegerAddModification extends VariableModification private BigInteger summand; - public BigIntegerAddModification() {} + public BigIntegerAddModification() { + super(); + } - public BigIntegerAddModification(BigInteger bi) { - this.summand = bi; + public BigIntegerAddModification(BigInteger summand) { + super(); + this.summand = summand; } @Override protected BigInteger modifyImplementationHook(BigInteger input) { - return (input == null) ? summand : input.add(summand); + return input == null ? summand : input.add(summand); } public BigInteger getSummand() { @@ -50,6 +53,11 @@ public VariableModification getModifiedCopy() { summand.add(new BigInteger(MAX_ADD_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerAddModification(summand); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +76,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerAddModification other = (BigIntegerAddModification) obj; - return Objects.equals(this.summand, other.summand); + BigIntegerAddModification other = (BigIntegerAddModification) obj; + return Objects.equals(summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index 97f3f88..c894edf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -25,10 +25,13 @@ public class BigIntegerAppendValueModification extends VariableModification getModifiedCopy() { appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerAppendValueModification(appendValue); + } + @Override public int hashCode() { int hash = 7; @@ -71,7 +79,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj; - return Objects.equals(this.appendValue, other.appendValue); + BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj; + return Objects.equals(appendValue, other.appendValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index e4ea8dd..9dae5aa 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -25,14 +25,17 @@ public class BigIntegerExplicitValueModification extends VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new BigIntegerExplicitValueModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -74,7 +82,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerExplicitValueModification other = (BigIntegerExplicitValueModification) obj; - return Objects.equals(this.explicitValue, other.explicitValue); + BigIntegerExplicitValueModification other = (BigIntegerExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java index cf7d7ef..407b8bb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -27,10 +27,13 @@ public class BigIntegerInsertValueModification extends VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new BigIntegerInsertValueModification(insertValue, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -113,10 +121,10 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerInsertValueModification other = (BigIntegerInsertValueModification) obj; - if (this.startPosition != other.startPosition) { + BigIntegerInsertValueModification other = (BigIntegerInsertValueModification) obj; + if (startPosition != other.startPosition) { return false; } - return Objects.equals(this.insertValue, other.insertValue); + return Objects.equals(insertValue, other.insertValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInteractiveModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInteractiveModification.java index 0ec3fa1..6116299 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInteractiveModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInteractiveModification.java @@ -16,23 +16,25 @@ import java.math.BigInteger; @XmlRootElement -@XmlType(propOrder = {"modificationFilter"}) +@XmlType(propOrder = "modificationFilter") @XmlAccessorType(XmlAccessType.FIELD) public class BigIntegerInteractiveModification extends VariableModification { - @XmlTransient private InteractiveBigIntegerModification modification; + @XmlTransient private final InteractiveBigIntegerModification modification; protected BigIntegerInteractiveModification() { - this.modification = BigIntegerModificationFactory.getStandardInteractiveModification(); + super(); + modification = BigIntegerModificationFactory.getStandardInteractiveModification(); } protected BigIntegerInteractiveModification(InteractiveBigIntegerModification modification) { + super(); this.modification = modification; } @Override - protected BigInteger modifyImplementationHook(final BigInteger input) { - return this.modification.modify(input); + protected BigInteger modifyImplementationHook(BigInteger input) { + return modification.modify(input); } public interface InteractiveBigIntegerModification { @@ -45,4 +47,10 @@ public VariableModification getModifiedCopy() { throw new UnsupportedOperationException( "This method is not supported for interactive modifications"); } + + @Override + public VariableModification createCopy() { + throw new UnsupportedOperationException( + "This method is not supported for interactive modifications"); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index 0b04f0d..66ab8f4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -22,7 +22,7 @@ import java.util.Random; import java.util.Scanner; -public class BigIntegerModificationFactory { +public final class BigIntegerModificationFactory { private enum ModificationType { ADD, @@ -54,55 +54,55 @@ private enum ModificationType { private static List> modificationsFromFile; - public static BigIntegerAddModification add(final String summand) { + public static BigIntegerAddModification add(String summand) { return add(new BigInteger(summand)); } - public static BigIntegerAddModification add(final BigInteger summand) { + public static BigIntegerAddModification add(BigInteger summand) { return new BigIntegerAddModification(summand); } - public static BigIntegerShiftLeftModification shiftLeft(final String shift) { + public static BigIntegerShiftLeftModification shiftLeft(String shift) { return shiftLeft(Integer.parseInt(shift)); } - public static BigIntegerShiftLeftModification shiftLeft(final Integer shift) { + public static BigIntegerShiftLeftModification shiftLeft(Integer shift) { return new BigIntegerShiftLeftModification(shift); } - public static BigIntegerShiftRightModification shiftRight(final String shift) { + public static BigIntegerShiftRightModification shiftRight(String shift) { return shiftRight(Integer.parseInt(shift)); } - public static BigIntegerShiftRightModification shiftRight(final Integer shift) { + public static BigIntegerShiftRightModification shiftRight(Integer shift) { return new BigIntegerShiftRightModification(shift); } - public static BigIntegerMultiplyModification multiply(final BigInteger factor) { + public static BigIntegerMultiplyModification multiply(BigInteger factor) { return new BigIntegerMultiplyModification(factor); } - public static VariableModification sub(final String subtrahend) { + public static VariableModification sub(String subtrahend) { return sub(new BigInteger(subtrahend)); } - public static VariableModification sub(final BigInteger subtrahend) { + public static VariableModification sub(BigInteger subtrahend) { return new BigIntegerSubtractModification(subtrahend); } - public static VariableModification xor(final String xor) { + public static VariableModification xor(String xor) { return xor(new BigInteger(xor)); } - public static VariableModification xor(final BigInteger xor) { + public static VariableModification xor(BigInteger xor) { return new BigIntegerXorModification(xor); } - public static VariableModification explicitValue(final String value) { + public static VariableModification explicitValue(String value) { return explicitValue(new BigInteger(value)); } - public static VariableModification explicitValue(final BigInteger value) { + public static VariableModification explicitValue(BigInteger value) { return new BigIntegerExplicitValueModification(value); } @@ -112,16 +112,16 @@ public static VariableModification explicitValueFromFile(int value) return modifications.get(pos); } - public static VariableModification appendValue(final BigInteger value) { + public static VariableModification appendValue(BigInteger value) { return new BigIntegerAppendValueModification(value); } public static VariableModification insertValue( - final BigInteger value, final int startPosition) { + BigInteger value, int startPosition) { return new BigIntegerInsertValueModification(value, startPosition); } - public static VariableModification prependValue(final BigInteger value) { + public static VariableModification prependValue(BigInteger value) { return new BigIntegerPrependValueModification(value); } @@ -137,11 +137,8 @@ public static VariableModification prependValue(final BigInteger val public BigInteger modify(BigInteger oldVal) { if (value == null) { System.out.println("Enter new value for BigInt: "); - Scanner scanner = new Scanner(System.in); - try { + try (Scanner scanner = new Scanner(System.in)) { value = scanner.nextBigInteger(); - } finally { - scanner.close(); } } return value; @@ -222,5 +219,7 @@ public static VariableModification createRandomModification() { } } - private BigIntegerModificationFactory() {} + private BigIntegerModificationFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 52975ae..e5141c1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -25,15 +25,18 @@ public class BigIntegerMultiplyModification extends VariableModification getModifiedCopy() { factor.add(new BigInteger(MAX_FACTOR_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerMultiplyModification(factor); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +76,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj; - return Objects.equals(this.factor, other.factor); + BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj; + return Objects.equals(factor, other.factor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 5a813b7..282bf2d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -25,10 +25,13 @@ public class BigIntegerPrependValueModification extends VariableModification getModifiedCopy() { prependValue.add(new BigInteger(MAX_PREPEND_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerPrependValueModification(prependValue); + } + @Override public int hashCode() { int hash = 7; @@ -71,7 +79,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerPrependValueModification other = (BigIntegerPrependValueModification) obj; - return Objects.equals(this.prependValue, other.prependValue); + BigIntegerPrependValueModification other = (BigIntegerPrependValueModification) obj; + return Objects.equals(prependValue, other.prependValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index 6e42525..569280c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -24,9 +24,12 @@ public class BigIntegerShiftLeftModification extends VariableModification getModifiedCopy() { return new BigIntegerShiftLeftModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH)); } + @Override + public VariableModification createCopy() { + return new BigIntegerShiftLeftModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -69,7 +77,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerShiftLeftModification other = (BigIntegerShiftLeftModification) obj; - return this.shift == other.shift; + BigIntegerShiftLeftModification other = (BigIntegerShiftLeftModification) obj; + return shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index 27470f7..f103d97 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -24,9 +24,12 @@ public class BigIntegerShiftRightModification extends VariableModification getModifiedCopy() { return new BigIntegerShiftRightModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH)); } + @Override + public VariableModification createCopy() { + return new BigIntegerShiftRightModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -69,7 +77,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerShiftRightModification other = (BigIntegerShiftRightModification) obj; - return this.shift == other.shift; + BigIntegerShiftRightModification other = (BigIntegerShiftRightModification) obj; + return shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index d77d0f3..a818dc8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -25,10 +25,13 @@ public class BigIntegerSubtractModification extends VariableModification getModifiedCopy() { subtrahend.add(new BigInteger(MAX_SUBTRACT_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerSubtractModification(subtrahend); + } + @Override public int hashCode() { int hash = 7; @@ -71,7 +79,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerSubtractModification other = (BigIntegerSubtractModification) obj; - return Objects.equals(this.subtrahend, other.subtrahend); + BigIntegerSubtractModification other = (BigIntegerSubtractModification) obj; + return Objects.equals(subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index b416ff0..2c3529a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -25,10 +25,13 @@ public class BigIntegerXorModification extends VariableModification private BigInteger xor; - public BigIntegerXorModification() {} + public BigIntegerXorModification() { + super(); + } - public BigIntegerXorModification(BigInteger bi) { - this.xor = bi; + public BigIntegerXorModification(BigInteger xor) { + super(); + this.xor = xor; } @Override @@ -52,6 +55,11 @@ public VariableModification getModifiedCopy() { return new BigIntegerXorModification(xor.add(new BigInteger(MAX_XOR_LENGTH, new Random()))); } + @Override + public VariableModification createCopy() { + return new BigIntegerXorModification(xor); + } + @Override public int hashCode() { int hash = 7; @@ -70,7 +78,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BigIntegerXorModification other = (BigIntegerXorModification) obj; - return Objects.equals(this.xor, other.xor); + BigIntegerXorModification other = (BigIntegerXorModification) obj; + return Objects.equals(xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index 03b4697..d2af64c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -21,6 +21,17 @@ public class ModifiableBigInteger extends ModifiableVariable { private BigInteger originalValue; + public ModifiableBigInteger() { + super(); + } + + public ModifiableBigInteger(ModifiableBigInteger other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } + @Override protected void createRandomModification() { VariableModification vm = @@ -28,6 +39,11 @@ protected void createRandomModification() { setModification(vm); } + @Override + public ModifiableBigInteger createCopy() { + return new ModifiableBigInteger(this); + } + public BigInteger getAssertEquals() { return assertEquals; } @@ -38,7 +54,7 @@ public void setAssertEquals(BigInteger assertEquals) { @Override public boolean isOriginalValueModified() { - return getOriginalValue() != null && (getOriginalValue().compareTo(getValue()) != 0); + return originalValue != null && originalValue.compareTo(getValue()) != 0; } public byte[] getByteArray() { @@ -73,15 +89,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableBigInteger)) { + if (!(obj instanceof ModifiableBigInteger)) { return false; } - ModifiableBigInteger that = (ModifiableBigInteger) o; + ModifiableBigInteger that = (ModifiableBigInteger) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index 5ca6a23..744ba2f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -17,14 +17,17 @@ public class BooleanExplicitValueModification extends VariableModification getModifiedCopy() { return new BooleanExplicitValueModification(!explicitValue); } + @Override + public VariableModification createCopy() { + return new BooleanExplicitValueModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -59,8 +67,8 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final BooleanExplicitValueModification other = (BooleanExplicitValueModification) obj; - return this.explicitValue == other.explicitValue; + BooleanExplicitValueModification other = (BooleanExplicitValueModification) obj; + return explicitValue == other.explicitValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java index 6ef65e1..653d6dd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanModificationFactory.java @@ -11,7 +11,11 @@ import de.rub.nds.modifiablevariable.util.RandomHelper; import java.util.Random; -public class BooleanModificationFactory { +public final class BooleanModificationFactory { + + private BooleanModificationFactory() { + super(); + } private enum ModificationType { EXPLICIT_TRUE, @@ -40,7 +44,7 @@ public static VariableModification toggle() { return new BooleanToggleModification(); } - public static VariableModification explicitValue(final boolean explicitValue) { + public static VariableModification explicitValue(boolean explicitValue) { return new BooleanExplicitValueModification(explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java index 3f9da99..5d12e6a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java @@ -12,10 +12,12 @@ import jakarta.xml.bind.annotation.XmlType; @XmlRootElement -@XmlType(propOrder = {"modificationFilter"}) +@XmlType(propOrder = "modificationFilter") public class BooleanToggleModification extends VariableModification { - public BooleanToggleModification() {} + public BooleanToggleModification() { + super(); + } @Override protected Boolean modifyImplementationHook(Boolean input) { @@ -30,10 +32,14 @@ public VariableModification getModifiedCopy() { return new BooleanToggleModification(); } + @Override + public VariableModification createCopy() { + return new BooleanToggleModification(); + } + @Override public int hashCode() { - int hash = 7; - return hash; + return 7; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index 058e8f5..3cf082d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -19,12 +19,22 @@ public class ModifiableBoolean extends ModifiableVariable { private Boolean originalValue; - public ModifiableBoolean() {} + public ModifiableBoolean() { + super(); + } public ModifiableBoolean(Boolean originalValue) { + super(); this.originalValue = originalValue; } + public ModifiableBoolean(ModifiableBoolean other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } + @Override public Boolean getOriginalValue() { return originalValue; @@ -41,9 +51,14 @@ protected void createRandomModification() { setModification(vm); } + @Override + public ModifiableBoolean createCopy() { + return new ModifiableBoolean(this); + } + @Override public boolean isOriginalValueModified() { - return getOriginalValue() != null && (getOriginalValue().compareTo(getValue()) != 0); + return originalValue != null && originalValue.compareTo(getValue()) != 0; } @Override @@ -60,15 +75,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableBoolean)) { + if (!(obj instanceof ModifiableBoolean)) { return false; } - ModifiableBoolean that = (ModifiableBoolean) o; + ModifiableBoolean that = (ModifiableBoolean) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index 95e2f2e..9048b3d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -28,9 +28,12 @@ public class ByteArrayAppendValueModification extends VariableModification getModifiedCopy() { return new ByteArrayAppendValueModification(newValue); } + @Override + public VariableModification createCopy() { + return new ByteArrayAppendValueModification( + bytesToAppend != null ? bytesToAppend.clone() : null); + } + @Override public int hashCode() { int hash = 7; @@ -79,8 +88,8 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayAppendValueModification other = (ByteArrayAppendValueModification) obj; - return Arrays.equals(this.bytesToAppend, other.bytesToAppend); + ByteArrayAppendValueModification other = (ByteArrayAppendValueModification) obj; + return Arrays.equals(bytesToAppend, other.bytesToAppend); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 6000870..4838c43 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -29,9 +29,12 @@ public class ByteArrayDeleteModification extends VariableModification { private int startPosition; - public ByteArrayDeleteModification() {} + public ByteArrayDeleteModification() { + super(); + } public ByteArrayDeleteModification(int startPosition, int count) { + super(); this.startPosition = startPosition; this.count = count; } @@ -51,8 +54,8 @@ protected byte[] modifyImplementationHook(byte[] input) { return input; } } - final int endPosition = start + count; - if ((endPosition) > input.length) { + int endPosition = start + count; + if (endPosition > input.length) { LOGGER.debug( "Bytes {}..{} cannot be deleted from {{}} of length {}", start, @@ -67,7 +70,7 @@ protected byte[] modifyImplementationHook(byte[] input) { } byte[] ret1 = Arrays.copyOf(input, start); byte[] ret2 = null; - if ((endPosition) < input.length) { + if (endPosition < input.length) { ret2 = Arrays.copyOfRange(input, endPosition, input.length); } return ArrayConverter.concatenate(ret1, ret2); @@ -111,6 +114,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new ByteArrayDeleteModification(startPosition, count); + } + @Override public int hashCode() { int hash = 7; @@ -130,11 +138,11 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayDeleteModification other = (ByteArrayDeleteModification) obj; - if (this.count != other.count) { + ByteArrayDeleteModification other = (ByteArrayDeleteModification) obj; + if (count != other.count) { return false; } - return this.startPosition == other.startPosition; + return startPosition == other.startPosition; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java index 32f1ebb..55d5f3c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java @@ -15,11 +15,13 @@ import jakarta.xml.bind.annotation.XmlType; @XmlRootElement -@XmlType(propOrder = {"modificationFilter"}) +@XmlType(propOrder = "modificationFilter") @XmlAccessorType(XmlAccessType.FIELD) public class ByteArrayDuplicateModification extends VariableModification { - public ByteArrayDuplicateModification() {} + public ByteArrayDuplicateModification() { + super(); + } @Override protected byte[] modifyImplementationHook(byte[] input) { @@ -34,10 +36,14 @@ public VariableModification getModifiedCopy() { return new ByteArrayDuplicateModification(); } + @Override + public VariableModification createCopy() { + return new ByteArrayDuplicateModification(); + } + @Override public int hashCode() { - int hash = 7; - return hash; + return 7; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index 173a97e..f62d203 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -28,14 +28,17 @@ public class ByteArrayExplicitValueModification extends VariableModification getModifiedCopy() { return new ByteArrayExplicitValueModification(newValue); } + @Override + public VariableModification createCopy() { + return new ByteArrayExplicitValueModification( + explicitValue != null ? explicitValue.clone() : null); + } + @Override public int hashCode() { int hash = 7; @@ -85,7 +94,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayExplicitValueModification other = (ByteArrayExplicitValueModification) obj; - return Arrays.equals(this.explicitValue, other.explicitValue); + ByteArrayExplicitValueModification other = (ByteArrayExplicitValueModification) obj; + return Arrays.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index d1523e7..180f16b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -32,9 +32,12 @@ public class ByteArrayInsertValueModification extends VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new ByteArrayInsertValueModification( + bytesToInsert != null ? bytesToInsert.clone() : null, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -117,11 +126,11 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayInsertValueModification other = (ByteArrayInsertValueModification) obj; - if (this.startPosition != other.startPosition) { + ByteArrayInsertValueModification other = (ByteArrayInsertValueModification) obj; + if (startPosition != other.startPosition) { return false; } - return Arrays.equals(this.bytesToInsert, other.bytesToInsert); + return Arrays.equals(bytesToInsert, other.bytesToInsert); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java index 0b2579a..2dbca90 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Random; -public class ByteArrayModificationFactory { +public final class ByteArrayModificationFactory { private enum ModificationType { XOR, @@ -50,7 +50,7 @@ private enum ModificationType { * @param startPosition negative numbers mean that the position is taken from the end * @return variable modification */ - public static VariableModification xor(final byte[] xor, final int startPosition) { + public static VariableModification xor(byte[] xor, int startPosition) { return new ByteArrayXorModification(xor, startPosition); } @@ -62,15 +62,15 @@ public static VariableModification xor(final byte[] xor, final int start * @return variable modification */ public static VariableModification insertValue( - final byte[] bytesToInsert, final int startPosition) { + byte[] bytesToInsert, int startPosition) { return new ByteArrayInsertValueModification(bytesToInsert, startPosition); } - public static VariableModification appendValue(final byte[] bytesToAppend) { + public static VariableModification appendValue(byte[] bytesToAppend) { return new ByteArrayAppendValueModification(bytesToAppend); } - public static VariableModification prependValue(final byte[] bytesToPrepend) { + public static VariableModification prependValue(byte[] bytesToPrepend) { return new ByteArrayPrependValueModification(bytesToPrepend); } @@ -81,7 +81,7 @@ public static VariableModification prependValue(final byte[] bytesToPrep * @param count number of bytes to be deleted * @return variable modification */ - public static VariableModification delete(final int startPosition, final int count) { + public static VariableModification delete(int startPosition, int count) { return new ByteArrayDeleteModification(startPosition, count); } @@ -94,7 +94,7 @@ public static VariableModification duplicate() { return new ByteArrayDuplicateModification(); } - public static VariableModification explicitValue(final byte[] explicitValue) { + public static VariableModification explicitValue(byte[] explicitValue) { return new ByteArrayExplicitValueModification(explicitValue); } @@ -110,7 +110,7 @@ public static VariableModification explicitValueFromFile(int value) { * @param shuffle positions that define shuffling * @return shuffling variable modification */ - public static VariableModification shuffle(final byte[] shuffle) { + public static VariableModification shuffle(byte[] shuffle) { return new ByteArrayShuffleModification(shuffle); } @@ -192,5 +192,7 @@ public static VariableModification createRandomModification(byte[] origi } } - private ByteArrayModificationFactory() {} + private ByteArrayModificationFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 7358543..792c887 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -28,9 +28,12 @@ public class ByteArrayPrependValueModification extends VariableModification getModifiedCopy() { return new ByteArrayPrependValueModification(newValue); } + @Override + public VariableModification createCopy() { + return new ByteArrayPrependValueModification( + bytesToPrepend != null ? bytesToPrepend.clone() : null); + } + @Override public int hashCode() { int hash = 7; @@ -79,8 +88,8 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayPrependValueModification other = (ByteArrayPrependValueModification) obj; - return Arrays.equals(this.bytesToPrepend, other.bytesToPrepend); + ByteArrayPrependValueModification other = (ByteArrayPrependValueModification) obj; + return Arrays.equals(bytesToPrepend, other.bytesToPrepend); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 862bcb7..0ce87fd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -32,14 +32,17 @@ public class ByteArrayShuffleModification extends VariableModification { @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) private byte[] shuffle; - public ByteArrayShuffleModification() {} + public ByteArrayShuffleModification() { + super(); + } public ByteArrayShuffleModification(byte[] shuffle) { + super(); this.shuffle = shuffle; } @Override - protected byte[] modifyImplementationHook(final byte[] input) { + protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { return input; } @@ -74,6 +77,11 @@ public VariableModification getModifiedCopy() { return new ByteArrayShuffleModification(newValue); } + @Override + public VariableModification createCopy() { + return new ByteArrayShuffleModification(shuffle != null ? shuffle.clone() : null); + } + @Override public int hashCode() { int hash = 7; @@ -92,8 +100,8 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayShuffleModification other = (ByteArrayShuffleModification) obj; - return Arrays.equals(this.shuffle, other.shuffle); + ByteArrayShuffleModification other = (ByteArrayShuffleModification) obj; + return Arrays.equals(shuffle, other.shuffle); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index d8b19a4..9dfbb39 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -32,9 +32,12 @@ public class ByteArrayXorModification extends VariableModification { private int startPosition; - public ByteArrayXorModification() {} + public ByteArrayXorModification() { + super(); + } public ByteArrayXorModification(byte[] xor, int startPosition) { + super(); this.xor = xor; this.startPosition = startPosition; } @@ -49,7 +52,7 @@ protected byte[] modifyImplementationHook(byte[] input) { if (start < 0) { start += input.length; } - final int end = start + xor.length; + int end = start + xor.length; if (end > result.length) { // result = new byte[end]; // System.arraycopy(input, 0, result, 0, input.length); @@ -106,6 +109,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new ByteArrayXorModification(xor != null ? xor.clone() : null, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -125,11 +133,11 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteArrayXorModification other = (ByteArrayXorModification) obj; - if (this.startPosition != other.startPosition) { + ByteArrayXorModification other = (ByteArrayXorModification) obj; + if (startPosition != other.startPosition) { return false; } - return Arrays.equals(this.xor, other.xor); + return Arrays.equals(xor, other.xor); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index a0d46cb..f989cf4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -21,10 +21,21 @@ @XmlAccessorType(XmlAccessType.PROPERTY) public class ModifiableByteArray extends ModifiableVariable { - public ModifiableByteArray() {} - private byte[] originalValue; + public ModifiableByteArray() { + super(); + } + + @SuppressWarnings("IncompleteCopyConstructor") + public ModifiableByteArray(ModifiableByteArray other) { + super(other); + if (other != null) { + originalValue = other.originalValue != null ? other.originalValue.clone() : null; + assertEquals = other.assertEquals != null ? other.assertEquals.clone() : null; + } + } + @Override protected void createRandomModification() { VariableModification vm = @@ -32,6 +43,11 @@ protected void createRandomModification() { setModification(vm); } + @Override + public ModifiableByteArray createCopy() { + return new ModifiableByteArray(this); + } + @Override @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) public byte[] getOriginalValue() { @@ -71,28 +87,28 @@ public boolean validateAssertions() { @Override public String toString() { StringBuilder result = new StringBuilder(); - if (this.isOriginalValueModified()) { + if (isOriginalValueModified()) { result.append("Actual byte value is: "); result.append(ArrayConverter.bytesToHexString(this)); result.append("\nOriginal value was: "); - result.append(ArrayConverter.bytesToHexString(this.getOriginalValue())); + result.append(ArrayConverter.bytesToHexString(getOriginalValue())); } else { result.append("Original byte value is: "); - result.append(ArrayConverter.bytesToHexString(this.getOriginalValue())); + result.append(ArrayConverter.bytesToHexString(getOriginalValue())); } return result.toString(); } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableByteArray)) { + if (!(obj instanceof ModifiableByteArray)) { return false; } - ModifiableByteArray that = (ModifiableByteArray) o; + ModifiableByteArray that = (ModifiableByteArray) obj; return Arrays.equals(getValue(), that.getValue()); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java b/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java index 02daf06..54ca94c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java @@ -29,10 +29,12 @@ public class AccessModificationFilter extends ModificationFilter { private int[] accessNumbers; public AccessModificationFilter() { + super(); accessCounter = 1; } - public AccessModificationFilter(final int[] accessNumbers) { + public AccessModificationFilter(int[] accessNumbers) { + super(); accessCounter = 1; this.accessNumbers = accessNumbers; } @@ -44,7 +46,7 @@ public boolean filterModification() { return filter; } - private boolean contains(int[] numbers, int number) { + private static boolean contains(int[] numbers, int number) { for (int i : numbers) { if (i == number) { return true; diff --git a/src/main/java/de/rub/nds/modifiablevariable/filter/ModificationFilterFactory.java b/src/main/java/de/rub/nds/modifiablevariable/filter/ModificationFilterFactory.java index db70b67..66a46b0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/filter/ModificationFilterFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/filter/ModificationFilterFactory.java @@ -7,11 +7,13 @@ */ package de.rub.nds.modifiablevariable.filter; -public class ModificationFilterFactory { +public final class ModificationFilterFactory { - public static AccessModificationFilter access(final int[] accessNumbers) { + public static AccessModificationFilter access(int[] accessNumbers) { return new AccessModificationFilter(accessNumbers); } - private ModificationFilterFactory() {} + private ModificationFilterFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index fb1e15e..129906a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -21,15 +21,18 @@ public class IntegerAddModification extends VariableModification { private Integer summand; - public IntegerAddModification() {} + public IntegerAddModification() { + super(); + } public IntegerAddModification(Integer summand) { + super(); this.summand = summand; } @Override protected Integer modifyImplementationHook(Integer input) { - return (input == null) ? summand : input + summand; + return input == null ? summand : input + summand; } public Integer getSummand() { @@ -45,6 +48,11 @@ public VariableModification getModifiedCopy() { return new IntegerAddModification(summand + new Random().nextInt(MAX_ADD_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new IntegerAddModification(summand); + } + @Override public int hashCode() { int hash = 7; @@ -63,7 +71,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerAddModification other = (IntegerAddModification) obj; - return Objects.equals(this.summand, other.summand); + IntegerAddModification other = (IntegerAddModification) obj; + return Objects.equals(summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index b2a1f4d..572f659 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -21,9 +21,12 @@ public class IntegerAppendValueModification extends VariableModification getModifiedCopy() { appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new IntegerAppendValueModification(appendValue); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +75,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerAppendValueModification other = (IntegerAppendValueModification) obj; - return Objects.equals(this.appendValue, other.appendValue); + IntegerAppendValueModification other = (IntegerAppendValueModification) obj; + return Objects.equals(appendValue, other.appendValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 1f207cf..408d704 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -21,14 +21,17 @@ public class IntegerExplicitValueModification extends VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new IntegerExplicitValueModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -70,7 +78,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerExplicitValueModification other = (IntegerExplicitValueModification) obj; - return Objects.equals(this.explicitValue, other.explicitValue); + IntegerExplicitValueModification other = (IntegerExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index c5cf070..36b0c27 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -25,9 +25,12 @@ public class IntegerInsertValueModification extends VariableModification> insertPosition) << insertValueLength) | insertValue) << insertPosition - | (mask & input); + return (input >> insertPosition << insertValueLength | insertValue) << insertPosition + | mask & input; } public Integer getInsertValue() { @@ -88,6 +91,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new IntegerInsertValueModification(insertValue, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -107,10 +115,10 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerInsertValueModification other = (IntegerInsertValueModification) obj; - if (this.startPosition != other.startPosition) { + IntegerInsertValueModification other = (IntegerInsertValueModification) obj; + if (startPosition != other.startPosition) { return false; } - return Objects.equals(this.insertValue, other.insertValue); + return Objects.equals(insertValue, other.insertValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java index dd596e9..f1646c6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java @@ -18,7 +18,7 @@ import java.util.List; import java.util.Random; -public class IntegerModificationFactory { +public final class IntegerModificationFactory { private enum ModificationType { ADD, @@ -52,51 +52,51 @@ private enum ModificationType { public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/integer.vec"; - public static IntegerAddModification add(final String summand) { + public static IntegerAddModification add(String summand) { return add(Integer.parseInt(summand)); } - public static IntegerAddModification add(final Integer summand) { + public static IntegerAddModification add(Integer summand) { return new IntegerAddModification(summand); } - public static IntegerShiftLeftModification shiftLeft(final String shift) { + public static IntegerShiftLeftModification shiftLeft(String shift) { return shiftLeft(Integer.parseInt(shift)); } - public static IntegerShiftLeftModification shiftLeft(final Integer shift) { + public static IntegerShiftLeftModification shiftLeft(Integer shift) { return new IntegerShiftLeftModification(shift); } - public static IntegerShiftRightModification shiftRight(final String shift) { + public static IntegerShiftRightModification shiftRight(String shift) { return shiftRight(Integer.parseInt(shift)); } - public static IntegerShiftRightModification shiftRight(final Integer shift) { + public static IntegerShiftRightModification shiftRight(Integer shift) { return new IntegerShiftRightModification(shift); } - public static VariableModification sub(final String subtrahend) { + public static VariableModification sub(String subtrahend) { return sub(Integer.parseInt(subtrahend)); } - public static VariableModification sub(final Integer subtrahend) { + public static VariableModification sub(Integer subtrahend) { return new IntegerSubtractModification(subtrahend); } - public static VariableModification xor(final String xor) { + public static VariableModification xor(String xor) { return xor(Integer.parseInt(xor)); } - public static VariableModification xor(final Integer xor) { + public static VariableModification xor(Integer xor) { return new IntegerXorModification(xor); } - public static VariableModification explicitValue(final String value) { + public static VariableModification explicitValue(String value) { return explicitValue(Integer.parseInt(value)); } - public static VariableModification explicitValue(final Integer value) { + public static VariableModification explicitValue(Integer value) { return new IntegerExplicitValueModification(value); } @@ -106,20 +106,19 @@ public static VariableModification explicitValueFromFile(int value) { return modifications.get(pos); } - public static VariableModification appendValue(final Integer value) { + public static VariableModification appendValue(Integer value) { return new IntegerAppendValueModification(value); } - public static VariableModification insertValue( - final Integer value, final int position) { + public static VariableModification insertValue(Integer value, int position) { return new IntegerInsertValueModification(value, position); } - public static VariableModification prependValue(final Integer value) { + public static VariableModification prependValue(Integer value) { return new IntegerPrependValueModification(value); } - public static VariableModification multiply(final Integer value) { + public static VariableModification multiply(Integer value) { return new IntegerMultiplyModification(value); } @@ -180,5 +179,7 @@ public static VariableModification createRandomModification() { } } - private IntegerModificationFactory() {} + private IntegerModificationFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index 5c2fced..a978315 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -21,15 +21,18 @@ public class IntegerMultiplyModification extends VariableModification { private Integer factor; - public IntegerMultiplyModification() {} + public IntegerMultiplyModification() { + super(); + } public IntegerMultiplyModification(Integer factor) { + super(); this.factor = factor; } @Override protected Integer modifyImplementationHook(Integer input) { - return (input == null) ? 0 : input * factor; + return input == null ? 0 : input * factor; } public Integer getFactor() { @@ -47,6 +50,11 @@ public VariableModification getModifiedCopy() { return new IntegerMultiplyModification(factor + r.nextInt(MAX_FACTOR_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new IntegerMultiplyModification(factor); + } + @Override public int hashCode() { int hash = 7; @@ -65,7 +73,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerMultiplyModification other = (IntegerMultiplyModification) obj; - return Objects.equals(this.factor, other.factor); + IntegerMultiplyModification other = (IntegerMultiplyModification) obj; + return Objects.equals(factor, other.factor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index 67ff5ff..67c970a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -21,9 +21,12 @@ public class IntegerPrependValueModification extends VariableModification getModifiedCopy() { prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new IntegerPrependValueModification(prependValue); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +76,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerPrependValueModification other = (IntegerPrependValueModification) obj; - return Objects.equals(this.prependValue, other.prependValue); + IntegerPrependValueModification other = (IntegerPrependValueModification) obj; + return Objects.equals(prependValue, other.prependValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index f99cdfa..f619d77 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -20,15 +20,18 @@ public class IntegerShiftLeftModification extends VariableModification private int shift; - public IntegerShiftLeftModification() {} + public IntegerShiftLeftModification() { + super(); + } public IntegerShiftLeftModification(int shift) { + super(); this.shift = shift; } @Override protected Integer modifyImplementationHook(Integer input) { - return (input == null) ? 0 : input << shift % MAX_SHIFT_MODIFIER; + return input == null ? 0 : input << shift % MAX_SHIFT_MODIFIER; } public int getShift() { @@ -56,6 +59,11 @@ public VariableModification getModifiedCopy() { return new IntegerShiftLeftModification(newShift); } + @Override + public VariableModification createCopy() { + return new IntegerShiftLeftModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -74,7 +82,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerShiftLeftModification other = (IntegerShiftLeftModification) obj; - return this.shift == other.shift; + IntegerShiftLeftModification other = (IntegerShiftLeftModification) obj; + return shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index 367e16d..7fe1383 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -20,15 +20,18 @@ public class IntegerShiftRightModification extends VariableModification private int shift; - public IntegerShiftRightModification() {} + public IntegerShiftRightModification() { + super(); + } public IntegerShiftRightModification(int shift) { + super(); this.shift = shift; } @Override - protected Integer modifyImplementationHook(final Integer input) { - return (input == null) ? 0 : input >> shift % MAX_SHIFT_MODIFIER; + protected Integer modifyImplementationHook(Integer input) { + return input == null ? 0 : input >> shift % MAX_SHIFT_MODIFIER; } public int getShift() { @@ -56,6 +59,11 @@ public VariableModification getModifiedCopy() { return new IntegerShiftRightModification(newShift); } + @Override + public VariableModification createCopy() { + return new IntegerShiftRightModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -74,7 +82,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerShiftRightModification other = (IntegerShiftRightModification) obj; - return this.shift == other.shift; + IntegerShiftRightModification other = (IntegerShiftRightModification) obj; + return shift == other.shift; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index 0691607..aa070ac 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -21,15 +21,18 @@ public class IntegerSubtractModification extends VariableModification { private Integer subtrahend; - public IntegerSubtractModification() {} + public IntegerSubtractModification() { + super(); + } public IntegerSubtractModification(Integer subtrahend) { + super(); this.subtrahend = subtrahend; } @Override - protected Integer modifyImplementationHook(final Integer input) { - return (input == null) ? -subtrahend : input - subtrahend; + protected Integer modifyImplementationHook(Integer input) { + return input == null ? -subtrahend : input - subtrahend; } public Integer getSubtrahend() { @@ -46,6 +49,11 @@ public VariableModification getModifiedCopy() { subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new IntegerSubtractModification(subtrahend); + } + @Override public int hashCode() { int hash = 7; @@ -64,7 +72,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerSubtractModification other = (IntegerSubtractModification) obj; - return Objects.equals(this.subtrahend, other.subtrahend); + IntegerSubtractModification other = (IntegerSubtractModification) obj; + return Objects.equals(subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index a91e8fb..09c6e09 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -21,15 +21,18 @@ public class IntegerXorModification extends VariableModification { private Integer xor; - public IntegerXorModification() {} + public IntegerXorModification() { + super(); + } public IntegerXorModification(Integer xor) { + super(); this.xor = xor; } @Override - protected Integer modifyImplementationHook(final Integer input) { - return (input == null) ? xor : input ^ xor; + protected Integer modifyImplementationHook(Integer input) { + return input == null ? xor : input ^ xor; } public Integer getXor() { @@ -44,12 +47,17 @@ public void setXor(Integer xor) { public VariableModification getModifiedCopy() { Random r = new Random(); if (r.nextBoolean()) { - return new IntegerSubtractModification(xor + new Random().nextInt(MAX_VALUE_MODIFIER)); + return new IntegerXorModification(xor + new Random().nextInt(MAX_VALUE_MODIFIER)); } else { - return new IntegerSubtractModification(xor - new Random().nextInt(MAX_VALUE_MODIFIER)); + return new IntegerXorModification(xor - new Random().nextInt(MAX_VALUE_MODIFIER)); } } + @Override + public VariableModification createCopy() { + return new IntegerXorModification(xor); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +76,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final IntegerXorModification other = (IntegerXorModification) obj; - return Objects.equals(this.xor, other.xor); + IntegerXorModification other = (IntegerXorModification) obj; + return Objects.equals(xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index e3daeb2..2f401a2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -20,12 +20,28 @@ public class ModifiableInteger extends ModifiableVariable { private Integer originalValue; + public ModifiableInteger() { + super(); + } + + public ModifiableInteger(ModifiableInteger other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } + @Override protected void createRandomModification() { VariableModification vm = IntegerModificationFactory.createRandomModification(); setModification(vm); } + @Override + public ModifiableInteger createCopy() { + return new ModifiableInteger(this); + } + public Integer getAssertEquals() { return assertEquals; } @@ -70,15 +86,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableInteger)) { + if (!(obj instanceof ModifiableInteger)) { return false; } - ModifiableInteger that = (ModifiableInteger) o; + ModifiableInteger that = (ModifiableInteger) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java index f54b99e..175cefc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java +++ b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java @@ -20,9 +20,20 @@ public class ModifiableLengthField extends ModifiableInteger { private final ModifiableByteArray ref; public ModifiableLengthField(ModifiableByteArray ref) { + super(); this.ref = ref; } + public ModifiableLengthField(ModifiableLengthField other) { + super(other); + ref = other.ref; + } + + @Override + public ModifiableLengthField createCopy() { + return new ModifiableLengthField(this); + } + @Override public Integer getOriginalValue() { return ref.getValue().length; @@ -40,17 +51,17 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableLengthField)) { + if (!(obj instanceof ModifiableLengthField)) { return false; } - ModifiableLengthField that = (ModifiableLengthField) o; + ModifiableLengthField that = (ModifiableLengthField) obj; - return ref != null ? getValue().equals(that.getValue()) : that.getValue() == null; + return ref != null ? getValue().equals(getValue()) : that.getValue() == null; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java index 36475e7..fa8009b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java +++ b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java @@ -39,7 +39,7 @@ category = "Core", elementType = "layout", printObject = true) -public class ExtendedPatternLayout extends AbstractStringLayout { +public final class ExtendedPatternLayout extends AbstractStringLayout { public static final String DEFAULT_CONVERSION_PATTERN = "%m%n"; public static final String TTCC_CONVERSION_PATTERN = "%r [%t] %p %c %notEmpty{%x }- %m%n"; public static final String SIMPLE_CONVERSION_PATTERN = "%d [%t] %p %c - %m%n"; @@ -80,9 +80,9 @@ private ExtendedPatternLayout( .setNoConsoleNoAnsi(noConsoleNoAnsi) .setPattern(footerPattern) .build()); - this.conversionPattern = eventPattern; + conversionPattern = eventPattern; this.patternSelector = patternSelector; - this.eventSerializer = + eventSerializer = newSerializerBuilder() .setConfiguration(config) .setReplace(replace) @@ -101,8 +101,8 @@ public static ExtendedPatternLayout.SerializerBuilder newSerializerBuilder() { @Override public boolean requiresLocation() { - return this.eventSerializer instanceof LocationAware - && ((LocationAware) this.eventSerializer).requiresLocation(); + return eventSerializer instanceof LocationAware + && ((LocationAware) eventSerializer).requiresLocation(); } /** @@ -129,7 +129,7 @@ public static AbstractStringLayout.Serializer createSerializer( } public String getConversionPattern() { - return this.conversionPattern; + return conversionPattern; } @Override @@ -137,32 +137,32 @@ public Map getContentFormat() { Map result = new HashMap<>(); result.put("structured", "false"); result.put("formatType", "conversion"); - result.put("format", this.conversionPattern); + result.put("format", conversionPattern); return result; } @Override public String toSerializable(LogEvent event) { - return this.eventSerializer.toSerializable(event); + return eventSerializer.toSerializable(event); } public void serialize(LogEvent event, StringBuilder stringBuilder) { - this.eventSerializer.toSerializable(event, stringBuilder); + eventSerializer.toSerializable(event, stringBuilder); } @Override public void encode(LogEvent event, ByteBufferDestination destination) { - if (this.eventSerializer == null) { + if (eventSerializer == null) { super.encode(event, destination); } else { - StringBuilder text = this.toText(this.eventSerializer, event, getStringBuilder()); - Encoder encoder = this.getStringBuilderEncoder(); + StringBuilder text = toText(eventSerializer, event, getStringBuilder()); + Encoder encoder = getStringBuilderEncoder(); encoder.encode(text, destination); trimToMaxSize(text); } } - private StringBuilder toText( + private static StringBuilder toText( AbstractStringLayout.Serializer2 serializer, LogEvent event, StringBuilder destination) { @@ -186,9 +186,7 @@ public static PatternParser createPatternParser(Configuration config) { @Override public String toString() { - return this.patternSelector == null - ? this.conversionPattern - : this.patternSelector.toString(); + return patternSelector == null ? conversionPattern : patternSelector.toString(); } /** @@ -234,10 +232,10 @@ public static ExtendedPatternLayout.Builder newBuilder() { } public AbstractStringLayout.Serializer getEventSerializer() { - return this.eventSerializer; + return eventSerializer; } - public static class Builder + public static final class Builder implements org.apache.logging.log4j.core.util.Builder { @PluginBuilderAttribute private String pattern; @@ -263,13 +261,14 @@ public static class Builder private static boolean prettyPrinting; private Builder() { - this.pattern = "%m%n"; - this.charset = Charset.defaultCharset(); - this.alwaysWriteExceptions = true; - this.disableAnsi = !this.useAnsiEscapeCodes(); + super(); + pattern = "%m%n"; + charset = Charset.defaultCharset(); + alwaysWriteExceptions = true; + disableAnsi = !useAnsiEscapeCodes(); } - private boolean useAnsiEscapeCodes() { + private static boolean useAnsiEscapeCodes() { PropertiesUtil propertiesUtil = PropertiesUtil.getProperties(); boolean isPlatformSupportsAnsi = !propertiesUtil.isOsWindows(); boolean isJansiRequested = !propertiesUtil.getBooleanProperty("log4j.skipJansi", true); @@ -333,78 +332,76 @@ public ExtendedPatternLayout.Builder withFooter(String footer) { @Override public ExtendedPatternLayout build() { - if (this.configuration == null) { - this.configuration = new DefaultConfiguration(); + if (configuration == null) { + configuration = new DefaultConfiguration(); } return new ExtendedPatternLayout( - this.configuration, - this.regexReplacement, - this.pattern, - this.patternSelector, - this.charset, - this.alwaysWriteExceptions, - this.disableAnsi, - this.noConsoleNoAnsi, - this.header, - this.footer); + configuration, + regexReplacement, + pattern, + patternSelector, + charset, + alwaysWriteExceptions, + disableAnsi, + noConsoleNoAnsi, + header, + footer); } } - private static class PatternSelectorSerializer + private static final class PatternSelectorSerializer implements AbstractStringLayout.Serializer, LocationAware { private final PatternSelector patternSelector; private final RegexReplacement replace; private PatternSelectorSerializer( PatternSelector patternSelector, RegexReplacement replace) { + super(); this.patternSelector = patternSelector; this.replace = replace; } @Override public String toSerializable(LogEvent event) { - StringBuilder sb = AbstractStringLayout.getStringBuilder(); + StringBuilder sb = getStringBuilder(); String var3; try { - var3 = this.toSerializable(event, sb).toString(); + var3 = toSerializable(event, sb).toString(); } finally { - AbstractStringLayout.trimToMaxSize(sb); + trimToMaxSize(sb); } return var3; } @Override - public StringBuilder toSerializable(LogEvent event, StringBuilder buffer) { - PatternFormatter[] formatters = this.patternSelector.getFormatters(event); - Arrays.stream(formatters).forEachOrdered(formatter -> formatter.format(event, buffer)); - - if (this.replace != null) { - String str = buffer.toString(); - str = this.replace.format(str); - buffer.setLength(0); - buffer.append(str); + public StringBuilder toSerializable(LogEvent event, StringBuilder builder) { + PatternFormatter[] formatters = patternSelector.getFormatters(event); + Arrays.stream(formatters).forEachOrdered(formatter -> formatter.format(event, builder)); + + if (replace != null) { + String str = builder.toString(); + str = replace.format(str); + builder.setLength(0); + builder.append(str); } - return buffer; + return builder; } @Override public boolean requiresLocation() { - return this.patternSelector instanceof LocationAware - && ((LocationAware) this.patternSelector).requiresLocation(); + return patternSelector instanceof LocationAware + && ((LocationAware) patternSelector).requiresLocation(); } @Override public String toString() { - return super.toString() - .concat("[patternSelector=") - .concat(this.patternSelector.toString()) - .concat(", replace=") - .concat(this.replace.toString()) - .concat("]"); + return String.format( + "%s[patternSelector=%s, replace=%s]", + super.toString(), patternSelector.toString(), replace.toString()); } } @@ -421,28 +418,27 @@ public static class SerializerBuilder @Override public AbstractStringLayout.Serializer build() { - if (Strings.isEmpty(this.pattern) && Strings.isEmpty(this.defaultPattern)) { + if (Strings.isEmpty(pattern) && Strings.isEmpty(defaultPattern)) { return null; - } else if (this.patternSelector == null) { + } else if (patternSelector == null) { try { - PatternParser parser = - ExtendedPatternLayout.createPatternParser(this.configuration); + PatternParser parser = createPatternParser(configuration); List list = parser.parse( - this.pattern == null ? this.defaultPattern : this.pattern, - this.alwaysWriteExceptions, - this.disableAnsi, - this.noConsoleNoAnsi); + pattern == null ? defaultPattern : pattern, + alwaysWriteExceptions, + disableAnsi, + noConsoleNoAnsi); PatternFormatter[] formatters = list.toArray(new PatternFormatter[0]); return new ExtendedPatternLayout.ExtendedPatternLayoutSerializer( - formatters, this.replace); + formatters, replace); } catch (RuntimeException var4) { throw new IllegalArgumentException( - "Cannot parse pattern '" + this.pattern + "'", var4); + "Cannot parse pattern '" + pattern + "'", var4); } } else { return new ExtendedPatternLayout.PatternSelectorSerializer( - this.patternSelector, this.replace); + patternSelector, replace); } } @@ -490,39 +486,40 @@ public ExtendedPatternLayout.SerializerBuilder setNoConsoleNoAnsi(boolean noCons } } - private static class ExtendedPatternLayoutSerializer + private static final class ExtendedPatternLayoutSerializer implements AbstractStringLayout.Serializer, LocationAware { private final PatternFormatter[] formatters; private final RegexReplacement replace; private ExtendedPatternLayoutSerializer( PatternFormatter[] formatters, RegexReplacement replace) { + super(); this.formatters = formatters; this.replace = replace; } @Override public String toSerializable(LogEvent event) { - StringBuilder sb = AbstractStringLayout.getStringBuilder(); + StringBuilder sb = getStringBuilder(); String var3; try { - var3 = this.toSerializable(event, sb).toString(); + var3 = toSerializable(event, sb).toString(); } finally { - AbstractStringLayout.trimToMaxSize(sb); + trimToMaxSize(sb); } return var3; } @Override - public StringBuilder toSerializable(LogEvent event, StringBuilder buffer) { - Arrays.stream(formatters).forEachOrdered(formatter -> formatter.format(event, buffer)); - - if (this.replace != null) { - String str = buffer.toString(); - str = this.replace.format(str); - buffer.setLength(0); - buffer.append(str); + public StringBuilder toSerializable(LogEvent event, StringBuilder builder) { + Arrays.stream(formatters).forEachOrdered(formatter -> formatter.format(event, builder)); + + if (replace != null) { + String str = builder.toString(); + str = replace.format(str); + builder.setLength(0); + builder.append(str); } // Added section to parse ByteArrays to the correct output format. @@ -538,9 +535,9 @@ public StringBuilder toSerializable(LogEvent event, StringBuilder buffer) { // calculated // by the ArrayConverter. if (param != null && bArrayClass.equals(param.getClass())) { - buffer.replace( - buffer.indexOf(Arrays.toString((byte[]) param)), - buffer.indexOf(Arrays.toString((byte[]) param)) + builder.replace( + builder.indexOf(Arrays.toString((byte[]) param)), + builder.indexOf(Arrays.toString((byte[]) param)) + Arrays.toString((byte[]) param).length(), ArrayConverter.bytesToHexString( (byte[]) param, @@ -549,21 +546,21 @@ public StringBuilder toSerializable(LogEvent event, StringBuilder buffer) { } } } - return buffer; + return builder; } public boolean requiresLocation() { - return Arrays.stream(this.formatters).anyMatch(PatternFormatter::requiresLocation); + return Arrays.stream(formatters).anyMatch(PatternFormatter::requiresLocation); } @Override public String toString() { return super.toString() - .concat("[formatters=") - .concat(Arrays.toString(this.formatters)) - .concat(", replace=") - .concat(this.replace.toString()) - .concat("]"); + + "[formatters=" + + Arrays.toString(formatters) + + ", replace=" + + replace.toString() + + "]"; } } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index f37fbc2..2a2bc5a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -21,15 +21,18 @@ public class LongAddModification extends VariableModification { private Long summand; - public LongAddModification() {} + public LongAddModification() { + super(); + } public LongAddModification(Long summand) { + super(); this.summand = summand; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? summand : input + summand; + protected Long modifyImplementationHook(Long input) { + return input == null ? summand : input + summand; } public Long getSummand() { @@ -45,6 +48,11 @@ public VariableModification getModifiedCopy() { return new LongAddModification(summand + new Random().nextInt(MAX_ADD_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new LongAddModification(summand); + } + @Override public int hashCode() { int hash = 7; @@ -63,7 +71,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongAddModification other = (LongAddModification) obj; - return Objects.equals(this.summand, other.summand); + LongAddModification other = (LongAddModification) obj; + return Objects.equals(summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index b7177fd..04bfa00 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -21,9 +21,12 @@ public class LongAppendValueModification extends VariableModification { private Long appendValue; - public LongAppendValueModification() {} + public LongAppendValueModification() { + super(); + } public LongAppendValueModification(Long appendValue) { + super(); this.appendValue = appendValue; } @@ -32,7 +35,7 @@ protected Long modifyImplementationHook(Long input) { if (input == null) { input = 0L; } - return (input << (Long.SIZE - Long.numberOfLeadingZeros((appendValue)))) | appendValue; + return input << Long.SIZE - Long.numberOfLeadingZeros(appendValue) | appendValue; } public Long getAppendValue() { @@ -49,6 +52,11 @@ public VariableModification getModifiedCopy() { appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new LongAppendValueModification(appendValue); + } + @Override public int hashCode() { int hash = 7; @@ -67,7 +75,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongAppendValueModification other = (LongAppendValueModification) obj; - return Objects.equals(this.appendValue, other.appendValue); + LongAppendValueModification other = (LongAppendValueModification) obj; + return Objects.equals(appendValue, other.appendValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index bfdc1b8..4414505 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -21,14 +21,17 @@ public class LongExplicitValueModification extends VariableModification { private Long explicitValue; - public LongExplicitValueModification() {} + public LongExplicitValueModification() { + super(); + } public LongExplicitValueModification(Long explicitValue) { + super(); this.explicitValue = explicitValue; } @Override - protected Long modifyImplementationHook(final Long input) { + protected Long modifyImplementationHook(Long input) { return explicitValue; } @@ -52,6 +55,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new LongExplicitValueModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -70,7 +78,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongExplicitValueModification other = (LongExplicitValueModification) obj; - return Objects.equals(this.explicitValue, other.explicitValue); + LongExplicitValueModification other = (LongExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index 88a24f1..a16e9e0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -23,9 +23,12 @@ public class LongInsertValueModification extends VariableModification { private Long insertValue; private int startPosition; - public LongInsertValueModification() {} + public LongInsertValueModification() { + super(); + } public LongInsertValueModification(Long insertValue, int startPosition) { + super(); this.insertValue = insertValue; this.startPosition = startPosition; } @@ -36,7 +39,7 @@ protected Long modifyImplementationHook(Long input) { input = 0L; } - int insertValueLength = Long.SIZE - Long.numberOfLeadingZeros((insertValue)); + int insertValueLength = Long.SIZE - Long.numberOfLeadingZeros(insertValue); // Wrap around long size int insertPosition = startPosition % Long.SIZE; @@ -44,10 +47,10 @@ protected Long modifyImplementationHook(Long input) { insertPosition += Long.SIZE - 1; } - long mask = ((1L << insertPosition) - 1); + long mask = (1L << insertPosition) - 1; - return (((input >> insertPosition) << insertValueLength) | insertValue) << insertPosition - | (mask & input); + return (input >> insertPosition << insertValueLength | insertValue) << insertPosition + | mask & input; } public Long getInsertValue() { @@ -86,6 +89,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new LongInsertValueModification(insertValue, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -105,10 +113,10 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongInsertValueModification other = (LongInsertValueModification) obj; - if (this.startPosition != other.startPosition) { + LongInsertValueModification other = (LongInsertValueModification) obj; + if (startPosition != other.startPosition) { return false; } - return Objects.equals(this.insertValue, other.insertValue); + return Objects.equals(insertValue, other.insertValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index 549b135..c0c66a7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Random; -public class LongModificationFactory { +public final class LongModificationFactory { private enum ModificationType { ADD, @@ -53,35 +53,35 @@ private enum ModificationType { public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/long.vec"; - public static LongAddModification add(final String summand) { + public static LongAddModification add(String summand) { return add(Long.parseLong(summand)); } - public static LongAddModification add(final Long summand) { + public static LongAddModification add(Long summand) { return new LongAddModification(summand); } - public static VariableModification sub(final String subtrahend) { + public static VariableModification sub(String subtrahend) { return sub(Long.parseLong(subtrahend)); } - public static VariableModification sub(final Long subtrahend) { + public static VariableModification sub(Long subtrahend) { return new LongSubtractModification(subtrahend); } - public static VariableModification xor(final String xor) { + public static VariableModification xor(String xor) { return xor(Long.parseLong(xor)); } - public static VariableModification xor(final Long xor) { + public static VariableModification xor(Long xor) { return new LongXorModification(xor); } - public static VariableModification explicitValue(final String value) { + public static VariableModification explicitValue(String value) { return explicitValue(Long.parseLong(value)); } - public static VariableModification explicitValue(final Long value) { + public static VariableModification explicitValue(Long value) { return new LongExplicitValueModification(value); } @@ -91,27 +91,27 @@ public static VariableModification explicitValueFromFile(int value) { return modifications.get(pos); } - public static VariableModification appendValue(final Long value) { + public static VariableModification appendValue(Long value) { return new LongAppendValueModification(value); } - public static VariableModification insertValue(final Long value, final int position) { + public static VariableModification insertValue(Long value, int position) { return new LongInsertValueModification(value, position); } - public static VariableModification prependValue(final Long value) { + public static VariableModification prependValue(Long value) { return new LongPrependValueModification(value); } - public static VariableModification multiply(final Long factor) { + public static VariableModification multiply(Long factor) { return new LongMultiplyModification(factor); } - public static VariableModification shiftLeft(final int shift) { + public static VariableModification shiftLeft(int shift) { return new LongShiftLeftModification(shift); } - public static VariableModification shiftRight(final int shift) { + public static VariableModification shiftRight(int shift) { return new LongShiftRightModification(shift); } @@ -172,5 +172,7 @@ public static VariableModification createRandomModification() { } } - private LongModificationFactory() {} + private LongModificationFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java index 0c1a9f1..463d82f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java @@ -21,15 +21,18 @@ public class LongMultiplyModification extends VariableModification { private Long factor; - public LongMultiplyModification() {} + public LongMultiplyModification() { + super(); + } public LongMultiplyModification(Long factor) { + super(); this.factor = factor; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? 0L : input * factor; + protected Long modifyImplementationHook(Long input) { + return input == null ? 0L : input * factor; } public Long getFactor() { @@ -45,6 +48,11 @@ public VariableModification getModifiedCopy() { return new LongMultiplyModification(factor + new Random().nextInt(MAX_FACTOR_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new LongMultiplyModification(factor); + } + @Override public int hashCode() { int hash = 7; @@ -63,7 +71,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongMultiplyModification other = (LongMultiplyModification) obj; - return Objects.equals(this.factor, other.factor); + LongMultiplyModification other = (LongMultiplyModification) obj; + return Objects.equals(factor, other.factor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index b803d6c..e0ec781 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -21,9 +21,12 @@ public class LongPrependValueModification extends VariableModification { private Long prependValue; - public LongPrependValueModification() {} + public LongPrependValueModification() { + super(); + } public LongPrependValueModification(Long prependValue) { + super(); this.prependValue = prependValue; } @@ -32,7 +35,7 @@ protected Long modifyImplementationHook(Long input) { if (input == null) { input = 0L; } - return (prependValue << (Long.SIZE - Long.numberOfLeadingZeros((input)))) | input; + return prependValue << Long.SIZE - Long.numberOfLeadingZeros(input) | input; } public Long getPrependValue() { @@ -49,6 +52,11 @@ public VariableModification getModifiedCopy() { prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new LongPrependValueModification(prependValue); + } + @Override public int hashCode() { int hash = 7; @@ -67,7 +75,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongPrependValueModification other = (LongPrependValueModification) obj; - return Objects.equals(this.prependValue, other.prependValue); + LongPrependValueModification other = (LongPrependValueModification) obj; + return Objects.equals(prependValue, other.prependValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java index 02cfbc3..bf508fe 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java @@ -21,15 +21,18 @@ public class LongShiftLeftModification extends VariableModification { private int shift; - public LongShiftLeftModification() {} + public LongShiftLeftModification() { + super(); + } public LongShiftLeftModification(int shift) { + super(); this.shift = shift; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? 0L : input << shift % MAX_SHIFT_MODIFIER; + protected Long modifyImplementationHook(Long input) { + return input == null ? 0L : input << shift % MAX_SHIFT_MODIFIER; } public int getShift() { @@ -58,6 +61,11 @@ public VariableModification getModifiedCopy() { return new LongShiftLeftModification(newShift); } + @Override + public VariableModification createCopy() { + return new LongShiftLeftModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -76,7 +84,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongShiftLeftModification other = (LongShiftLeftModification) obj; - return Objects.equals(this.shift, other.shift); + LongShiftLeftModification other = (LongShiftLeftModification) obj; + return Objects.equals(shift, other.shift); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java index 511eaf7..c901d71 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java @@ -21,15 +21,18 @@ public class LongShiftRightModification extends VariableModification { private int shift; - public LongShiftRightModification() {} + public LongShiftRightModification() { + super(); + } public LongShiftRightModification(int shift) { + super(); this.shift = shift; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? 0L : input >> shift % MAX_SHIFT_MODIFIER; + protected Long modifyImplementationHook(Long input) { + return input == null ? 0L : input >> shift % MAX_SHIFT_MODIFIER; } public int getShift() { @@ -58,6 +61,11 @@ public VariableModification getModifiedCopy() { return new LongShiftRightModification(newShift); } + @Override + public VariableModification createCopy() { + return new LongShiftRightModification(shift); + } + @Override public int hashCode() { int hash = 7; @@ -76,7 +84,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongShiftRightModification other = (LongShiftRightModification) obj; - return Objects.equals(this.shift, other.shift); + LongShiftRightModification other = (LongShiftRightModification) obj; + return Objects.equals(shift, other.shift); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index b43b0a8..f303ca8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -21,15 +21,18 @@ public class LongSubtractModification extends VariableModification { private Long subtrahend; - public LongSubtractModification() {} + public LongSubtractModification() { + super(); + } public LongSubtractModification(Long subtrahend) { + super(); this.subtrahend = subtrahend; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? -subtrahend : input - subtrahend; + protected Long modifyImplementationHook(Long input) { + return input == null ? -subtrahend : input - subtrahend; } public Long getSubtrahend() { @@ -46,6 +49,11 @@ public VariableModification getModifiedCopy() { subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER)); } + @Override + public VariableModification createCopy() { + return new LongSubtractModification(subtrahend); + } + @Override public int hashCode() { int hash = 7; @@ -64,7 +72,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongSubtractModification other = (LongSubtractModification) obj; - return Objects.equals(this.subtrahend, other.subtrahend); + LongSubtractModification other = (LongSubtractModification) obj; + return Objects.equals(subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index 07bd614..650704f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -21,15 +21,18 @@ public class LongXorModification extends VariableModification { private Long xor; - public LongXorModification() {} + public LongXorModification() { + super(); + } public LongXorModification(Long xor) { + super(); this.xor = xor; } @Override - protected Long modifyImplementationHook(final Long input) { - return (input == null) ? xor : input ^ xor; + protected Long modifyImplementationHook(Long input) { + return input == null ? xor : input ^ xor; } public Long getXor() { @@ -50,6 +53,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new LongXorModification(xor); + } + @Override public int hashCode() { int hash = 7; @@ -68,7 +76,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final LongXorModification other = (LongXorModification) obj; - return Objects.equals(this.xor, other.xor); + LongXorModification other = (LongXorModification) obj; + return Objects.equals(xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index 5e75ea3..b920476 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -20,12 +20,28 @@ public class ModifiableLong extends ModifiableVariable { private Long originalValue; + public ModifiableLong() { + super(); + } + + public ModifiableLong(ModifiableLong other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } + @Override protected void createRandomModification() { VariableModification vm = LongModificationFactory.createRandomModification(); setModification(vm); } + @Override + public ModifiableLong createCopy() { + return new ModifiableLong(this); + } + public Long getAssertEquals() { return assertEquals; } @@ -70,15 +86,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableLong)) { + if (!(obj instanceof ModifiableLong)) { return false; } - ModifiableLong that = (ModifiableLong) o; + ModifiableLong that = (ModifiableLong) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index 4e4e598..5448222 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -21,10 +21,13 @@ public class ByteAddModification extends VariableModification { private Byte summand; - public ByteAddModification() {} + public ByteAddModification() { + super(); + } - public ByteAddModification(Byte bi) { - this.summand = bi; + public ByteAddModification(Byte summand) { + super(); + this.summand = summand; } @Override @@ -48,6 +51,11 @@ public VariableModification getModifiedCopy() { return new ByteAddModification((byte) (summand + new Random().nextInt(MAX_ADD_MODIFIER))); } + @Override + public VariableModification createCopy() { + return new ByteAddModification(summand); + } + @Override public int hashCode() { int hash = 7; @@ -66,7 +74,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteAddModification other = (ByteAddModification) obj; - return Objects.equals(this.summand, other.summand); + ByteAddModification other = (ByteAddModification) obj; + return Objects.equals(summand, other.summand); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 7a428b7..b2439ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -21,14 +21,17 @@ public class ByteExplicitValueModification extends VariableModification { private Byte explicitValue; - public ByteExplicitValueModification() {} + public ByteExplicitValueModification() { + super(); + } - public ByteExplicitValueModification(Byte bi) { - this.explicitValue = bi; + public ByteExplicitValueModification(Byte explicitValue) { + super(); + this.explicitValue = explicitValue; } @Override - protected Byte modifyImplementationHook(final Byte input) { + protected Byte modifyImplementationHook(Byte input) { return explicitValue; } @@ -52,6 +55,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new ByteAddModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -70,7 +78,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteExplicitValueModification other = (ByteExplicitValueModification) obj; - return Objects.equals(this.explicitValue, other.explicitValue); + ByteExplicitValueModification other = (ByteExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java index 200925e..b9179be 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java @@ -18,7 +18,7 @@ import java.util.List; import java.util.Random; -public class ByteModificationFactory { +public final class ByteModificationFactory { private enum ModificationType { ADD, @@ -34,35 +34,35 @@ private enum ModificationType { public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/byte.vec"; - public static ByteAddModification add(final String summand) { + public static ByteAddModification add(String summand) { return add(Byte.parseByte(summand)); } - public static ByteAddModification add(final Byte summand) { + public static ByteAddModification add(Byte summand) { return new ByteAddModification(summand); } - public static VariableModification sub(final String subtrahend) { + public static VariableModification sub(String subtrahend) { return sub(Byte.parseByte(subtrahend)); } - public static VariableModification sub(final Byte subtrahend) { + public static VariableModification sub(Byte subtrahend) { return new ByteSubtractModification(subtrahend); } - public static VariableModification xor(final String xor) { + public static VariableModification xor(String xor) { return xor(Byte.parseByte(xor)); } - public static VariableModification xor(final Byte xor) { + public static VariableModification xor(Byte xor) { return new ByteXorModification(xor); } - public static VariableModification explicitValue(final String value) { + public static VariableModification explicitValue(String value) { return explicitValue(Byte.parseByte(value)); } - public static VariableModification explicitValue(final Byte value) { + public static VariableModification explicitValue(Byte value) { return new ByteExplicitValueModification(value); } @@ -112,5 +112,7 @@ public static VariableModification createRandomModification() { } } - private ByteModificationFactory() {} + private ByteModificationFactory() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index 1df8179..fb6627b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -21,10 +21,13 @@ public class ByteSubtractModification extends VariableModification { private Byte subtrahend; - public ByteSubtractModification() {} + public ByteSubtractModification() { + super(); + } - public ByteSubtractModification(Byte bi) { - this.subtrahend = bi; + public ByteSubtractModification(Byte subtrahend) { + super(); + this.subtrahend = subtrahend; } @Override @@ -45,10 +48,15 @@ public void setSubtrahend(Byte subtrahend) { @Override public VariableModification getModifiedCopy() { - return new ByteAddModification( + return new ByteSubtractModification( (byte) (subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER))); } + @Override + public VariableModification createCopy() { + return new ByteSubtractModification(subtrahend); + } + @Override public int hashCode() { int hash = 7; @@ -67,7 +75,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteSubtractModification other = (ByteSubtractModification) obj; - return Objects.equals(this.subtrahend, other.subtrahend); + ByteSubtractModification other = (ByteSubtractModification) obj; + return Objects.equals(subtrahend, other.subtrahend); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index cb10612..eb47170 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -22,10 +22,13 @@ public class ByteXorModification extends VariableModification { private Byte xor; - public ByteXorModification() {} + public ByteXorModification() { + super(); + } - public ByteXorModification(Byte bi) { - this.xor = bi; + public ByteXorModification(Byte xor) { + super(); + this.xor = xor; } @Override @@ -54,6 +57,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new ByteXorModification(xor); + } + @Override public int hashCode() { int hash = 7; @@ -72,7 +80,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ByteXorModification other = (ByteXorModification) obj; - return Objects.equals(this.xor, other.xor); + ByteXorModification other = (ByteXorModification) obj; + return Objects.equals(xor, other.xor); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index 6e8c79c..af338da 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -19,12 +19,28 @@ public class ModifiableByte extends ModifiableVariable { private Byte originalValue; + public ModifiableByte() { + super(); + } + + public ModifiableByte(ModifiableByte other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } + @Override protected void createRandomModification() { VariableModification vm = ByteModificationFactory.createRandomModification(); setModification(vm); } + @Override + public ModifiableByte createCopy() { + return new ModifiableByte(this); + } + public Byte getAssertEquals() { return assertEquals; } @@ -65,15 +81,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableByte)) { + if (!(obj instanceof ModifiableByte)) { return false; } - ModifiableByte that = (ModifiableByte) o; + ModifiableByte that = (ModifiableByte) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 05dd42a..237833a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -26,7 +26,16 @@ public class ModifiableString extends ModifiableVariable { @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String originalValue; - public ModifiableString() {} + public ModifiableString() { + super(); + } + + public ModifiableString(ModifiableString other) { + super(other); + if (other != null) { + originalValue = other.originalValue; + } + } @Override protected void createRandomModification() { @@ -34,6 +43,11 @@ protected void createRandomModification() { setModification(vm); } + @Override + public ModifiableString createCopy() { + return new ModifiableString(this); + } + public String getAssertEquals() { return assertEquals; } @@ -79,15 +93,15 @@ public String toString() { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object obj) { + if (this == obj) { return true; } - if (!(o instanceof ModifiableString)) { + if (!(obj instanceof ModifiableString)) { return false; } - ModifiableString that = (ModifiableString) o; + ModifiableString that = (ModifiableString) obj; return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index 5cef0f1..b485882 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -25,22 +25,25 @@ public class StringAppendValueModification extends VariableModification @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String appendValue; - public StringAppendValueModification() {} + public StringAppendValueModification() { + super(); + } - public StringAppendValueModification(final String appendValue) { + public StringAppendValueModification(String appendValue) { + super(); this.appendValue = appendValue; } @Override - protected String modifyImplementationHook(final String input) { - return input + this.appendValue; + protected String modifyImplementationHook(String input) { + return input + appendValue; } public String getAppendValue() { - return this.appendValue; + return appendValue; } - public void setAppendValue(final String appendValue) { + public void setAppendValue(String appendValue) { this.appendValue = appendValue; } @@ -54,6 +57,11 @@ public VariableModification getModifiedCopy() { return new StringAppendValueModification(modifiedString.toString()); } + @Override + public VariableModification createCopy() { + return new StringAppendValueModification(appendValue); + } + @Override public int hashCode() { int hash = 7; @@ -72,7 +80,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final StringAppendValueModification other = (StringAppendValueModification) obj; - return Objects.equals(this.appendValue, other.getAppendValue()); + StringAppendValueModification other = (StringAppendValueModification) obj; + return Objects.equals(appendValue, other.appendValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index e370f2b..7b564a2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -25,9 +25,12 @@ public class StringExplicitValueModification extends VariableModification getModifiedCopy() { return new StringExplicitValueModification(modifiedString.toString()); } + @Override + public VariableModification createCopy() { + return new StringExplicitValueModification(explicitValue); + } + @Override public int hashCode() { int hash = 7; @@ -75,7 +83,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final StringExplicitValueModification other = (StringExplicitValueModification) obj; - return Objects.equals(this.explicitValue, other.explicitValue); + StringExplicitValueModification other = (StringExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index b1acfc4..367ed4a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -29,15 +29,18 @@ public class StringInsertValueModification extends VariableModification private int startPosition; - public StringInsertValueModification() {} + public StringInsertValueModification() { + super(); + } - public StringInsertValueModification(final String insertValue, int startPosition) { + public StringInsertValueModification(String insertValue, int startPosition) { + super(); this.insertValue = insertValue; this.startPosition = startPosition; } @Override - protected String modifyImplementationHook(final String input) { + protected String modifyImplementationHook(String input) { // Wrap around and also allow to insert at the end of the original value int insertPosition = startPosition % (input.length() + 1); if (startPosition < 0) { @@ -48,10 +51,10 @@ protected String modifyImplementationHook(final String input) { } public String getInsertValue() { - return this.insertValue; + return insertValue; } - public void setInsertValue(final String insertValue) { + public void setInsertValue(String insertValue) { this.insertValue = insertValue; } @@ -86,6 +89,11 @@ public VariableModification getModifiedCopy() { } } + @Override + public VariableModification createCopy() { + return new StringInsertValueModification(insertValue, startPosition); + } + @Override public int hashCode() { int hash = 7; @@ -105,10 +113,10 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final StringInsertValueModification other = (StringInsertValueModification) obj; - if (this.startPosition != other.startPosition) { + StringInsertValueModification other = (StringInsertValueModification) obj; + if (startPosition != other.startPosition) { return false; } - return Objects.equals(this.insertValue, other.getInsertValue()); + return Objects.equals(insertValue, other.insertValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java index 56f4c65..1f81a34 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -12,7 +12,11 @@ import java.util.Random; /** */ -public class StringModificationFactory { +public final class StringModificationFactory { + + private StringModificationFactory() { + super(); + } private enum ModificationType { APPEND, @@ -29,19 +33,19 @@ private enum ModificationType { private static final int MODIFIED_STRING_LENGTH_ESTIMATION = 50; - public static VariableModification prependValue(final String value) { + public static VariableModification prependValue(String value) { return new StringPrependValueModification(value); } - public static VariableModification appendValue(final String value) { + public static VariableModification appendValue(String value) { return new StringAppendValueModification(value); } - public static VariableModification explicitValue(final String value) { + public static VariableModification explicitValue(String value) { return new StringExplicitValueModification(value); } - public static VariableModification insertValue(final String value, final int position) { + public static VariableModification insertValue(String value, int position) { return new StringInsertValueModification(value, position); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index d5a9fe5..1b5dcf5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -25,22 +25,25 @@ public class StringPrependValueModification extends VariableModification @XmlJavaTypeAdapter(IllegalStringAdapter.class) private String prependValue; - public StringPrependValueModification() {} + public StringPrependValueModification() { + super(); + } - public StringPrependValueModification(final String prependValue) { + public StringPrependValueModification(String prependValue) { + super(); this.prependValue = prependValue; } @Override - protected String modifyImplementationHook(final String input) { - return this.prependValue + input; + protected String modifyImplementationHook(String input) { + return prependValue + input; } public String getPrependValue() { - return this.prependValue; + return prependValue; } - public void setPrependValue(final String prependValue) { + public void setPrependValue(String prependValue) { this.prependValue = prependValue; } @@ -54,6 +57,11 @@ public VariableModification getModifiedCopy() { return new StringPrependValueModification(modifiedString.toString()); } + @Override + public VariableModification createCopy() { + return new StringPrependValueModification(prependValue); + } + @Override public int hashCode() { int hash = 7; @@ -72,7 +80,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final StringPrependValueModification other = (StringPrependValueModification) obj; - return Objects.equals(this.prependValue, other.getPrependValue()); + StringPrependValueModification other = (StringPrependValueModification) obj; + return Objects.equals(prependValue, other.prependValue); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java index 5449b1e..799c741 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java @@ -13,7 +13,11 @@ import java.util.List; /** A utility class to handle arrays and array conversions */ -public class ArrayConverter { +public final class ArrayConverter { + + private ArrayConverter() { + super(); + } /** * Takes a long value and converts it to 8 bytes (needed for example to convert SQN numbers in @@ -31,7 +35,7 @@ public static byte[] longToUint64Bytes(long l) { result[4] = (byte) (l >>> 24); result[5] = (byte) (l >>> 16); result[6] = (byte) (l >>> 8); - result[7] = (byte) (l); + result[7] = (byte) l; return result; } @@ -46,7 +50,7 @@ public static byte[] longToUint32Bytes(long l) { result[0] = (byte) (l >>> 24); result[1] = (byte) (l >>> 16); result[2] = (byte) (l >>> 8); - result[3] = (byte) (l); + result[3] = (byte) l; return result; } @@ -64,7 +68,7 @@ public static byte[] intToBytes(int value, int size) { } byte[] result = new byte[size]; int shift = 0; - int finalPosition = ((size > Integer.BYTES) ? (size - Integer.BYTES) : 0); + int finalPosition = size > Integer.BYTES ? size - Integer.BYTES : 0; for (int i = size - 1; i >= finalPosition; i--) { result[i] = (byte) (value >>> shift); shift += 8; @@ -87,7 +91,7 @@ public static byte[] longToBytes(long value, int size) { } byte[] result = new byte[size]; int shift = 0; - int finalPosition = ((size > Long.BYTES) ? (size - Long.BYTES) : 0); + int finalPosition = size > Long.BYTES ? size - Long.BYTES : 0; for (int i = size - 1; i >= finalPosition; i--) { result[i] = (byte) (value >>> shift); shift += 8; @@ -122,7 +126,7 @@ public static long bytesToLong(byte[] value) { long result = 0; int shift = 0; for (int i = value.length - 1; i >= 0; i--) { - result += ((long) (value[i] & 0xFF)) << shift; + result += (long) (value[i] & 0xFF) << shift; shift += 8; } return result; @@ -132,7 +136,7 @@ public static String bytesToHexString(byte[] array) { if (array == null) { array = new byte[0]; } - boolean usePrettyPrinting = (array.length > 15); + boolean usePrettyPrinting = array.length > 15; return bytesToHexString(array, usePrettyPrinting); } @@ -151,10 +155,10 @@ public static String bytesToHexString( } for (int i = 0; i < array.length; i++) { if (i != 0) { - if (usePrettyPrinting && (i % 16 == 0)) { + if (usePrettyPrinting && i % 16 == 0) { result.append("\n"); } else { - if (usePrettyPrinting && (i % 8 == 0)) { + if (usePrettyPrinting && i % 8 == 0) { result.append(" "); } result.append(" "); @@ -195,39 +199,39 @@ public static String bytesToRawHexString(byte[] array) { } @SafeVarargs - public static T[] concatenate(final T[]... arrays) { + public static T[] concatenate(T[]... arrays) { if (arrays == null || arrays.length == 0) { throw new IllegalArgumentException( "The minimal number of parameters for this function is one"); } int length = 0; - for (final T[] a : arrays) { + for (T[] a : arrays) { length += a.length; } @SuppressWarnings("unchecked") T[] result = (T[]) Array.newInstance(arrays[0].getClass().getComponentType(), length); int currentOffset = 0; - for (final T[] a : arrays) { + for (T[] a : arrays) { System.arraycopy(a, 0, result, currentOffset, a.length); currentOffset += a.length; } return result; } - public static byte[] concatenate(final byte[]... arrays) { + public static byte[] concatenate(byte[]... arrays) { if (arrays == null || arrays.length == 0) { throw new IllegalArgumentException( "The minimal number of parameters for this function is one"); } int length = 0; - for (final byte[] a : arrays) { + for (byte[] a : arrays) { if (a != null) { length += a.length; } } byte[] result = new byte[length]; int currentOffset = 0; - for (final byte[] a : arrays) { + for (byte[] a : arrays) { if (a != null) { System.arraycopy(a, 0, result, currentOffset, a.length); currentOffset += a.length; @@ -236,8 +240,7 @@ public static byte[] concatenate(final byte[]... arrays) { return result; } - public static byte[] concatenate( - final byte[] array1, final byte[] array2, int numberOfArray2Bytes) { + public static byte[] concatenate(byte[] array1, byte[] array2, int numberOfArray2Bytes) { int length = array1.length + numberOfArray2Bytes; byte[] result = new byte[length]; System.arraycopy(array1, 0, result, 0, array1.length); @@ -245,7 +248,7 @@ public static byte[] concatenate( return result; } - public static void makeArrayNonZero(final byte[] array) { + public static void makeArrayNonZero(byte[] array) { for (int i = 0; i < array.length; i++) { if (array[i] == 0) { array[i] = 1; @@ -331,7 +334,7 @@ public static BigInteger[] convertListToArray(List list) { * @return byte array */ public static byte[] hexStringToByteArray(String input) { - if ((input == null) || (input.length() % 2 != 0)) { + if (input == null || input.length() % 2 != 0) { throw new IllegalArgumentException( "The input must not be null and " + "shall have an even number of hexadecimal characters. Found: " diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java b/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java index e0711ec..ccc3df9 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java @@ -18,6 +18,7 @@ public class BadFixedRandom extends Random { byte retVal; public BadFixedRandom(byte retVal) { + super(); this.retVal = retVal; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/BadRandom.java b/src/main/java/de/rub/nds/modifiablevariable/util/BadRandom.java index ef8fc6d..c61b16c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/BadRandom.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/BadRandom.java @@ -18,14 +18,17 @@ public class BadRandom extends SecureRandom { private Random random; public BadRandom() { + super(); random = new Random(0); } public BadRandom(Random random, byte[] seed) { + super(); this.random = random; } public BadRandom(Random random, SecureRandomSpi secureRandomSpi, Provider provider) { + super(); this.random = random; } @@ -62,8 +65,8 @@ public int nextInt() { } @Override - public int nextInt(int n) { - return random.nextInt(n); + public int nextInt(int bound) { + return random.nextInt(bound); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java index 9382c05..018daa1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ComparableByteArray.java @@ -14,6 +14,7 @@ public class ComparableByteArray { private byte[] array; public ComparableByteArray(byte[] array) { + super(); this.array = array; } @@ -28,7 +29,7 @@ public void setArray(byte[] array) { @Override public int hashCode() { int hash = 7; - hash = 83 * hash + Arrays.hashCode(this.array); + hash = 83 * hash + Arrays.hashCode(array); return hash; } @@ -43,7 +44,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - final ComparableByteArray other = (ComparableByteArray) obj; - return Arrays.equals(this.array, other.array); + ComparableByteArray other = (ComparableByteArray) obj; + return Arrays.equals(array, other.array); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index 769b1ab..d883b46 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -26,7 +26,11 @@ import java.math.BigInteger; @SuppressWarnings("unused") -public class Modifiable { +public final class Modifiable { + + private Modifiable() { + super(); + } private static ModifiableByteArray getModifiableByteArrayWithModification( VariableModification modification) { @@ -94,7 +98,7 @@ public static ModifiableLong prepend(Long l) { return getModifiableLongWithModification(LongModificationFactory.prependValue(l)); } - public static ModifiableString prepend(final String s) { + public static ModifiableString prepend(String s) { return getModifiableStringWithModification(StringModificationFactory.prependValue(s)); } @@ -115,7 +119,7 @@ public static ModifiableLong append(Long l) { return getModifiableLongWithModification(LongModificationFactory.appendValue(l)); } - public static ModifiableString append(final String s) { + public static ModifiableString append(String s) { return getModifiableStringWithModification(StringModificationFactory.appendValue(s)); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableAnalyzer.java b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableAnalyzer.java index 2ceead4..e09c692 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableAnalyzer.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableAnalyzer.java @@ -16,10 +16,14 @@ import org.apache.logging.log4j.Logger; /** */ -public class ModifiableVariableAnalyzer { +public final class ModifiableVariableAnalyzer { private static final Logger LOGGER = LogManager.getLogger(ModifiableVariableAnalyzer.class); + private ModifiableVariableAnalyzer() { + super(); + } + /** * Lists all the modifiable variables declared in the given class * @@ -67,8 +71,8 @@ public static List getAllModifiableVariableFieldsRecurs getAllModifiableVariableHoldersRecursively(object); List fields = new LinkedList<>(); for (ModifiableVariableListHolder holder : holders) { - for (Field f : holder.getFields()) { - fields.add(new ModifiableVariableField(holder.getObject(), f)); + for (Field field : holder.getFields()) { + fields.add(new ModifiableVariableField(holder.getObject(), field)); } } return fields; @@ -89,16 +93,16 @@ public static List getAllModifiableVariableHolders holders.add(new ModifiableVariableListHolder(object, modFields)); } List allFields = ReflectionHelper.getFieldsUpTo(object.getClass(), null, null); - for (Field f : allFields) { + for (Field field : allFields) { try { HoldsModifiableVariable holdsVariable = - f.getAnnotation(HoldsModifiableVariable.class); - f.setAccessible(true); - Object possibleHolder = f.get(object); + field.getAnnotation(HoldsModifiableVariable.class); + field.setAccessible(true); + Object possibleHolder = field.get(object); if (possibleHolder != null && holdsVariable != null) { if (possibleHolder instanceof List) { @SuppressWarnings("unchecked") - List castedList = List.class.cast(possibleHolder); + List castedList = (List) possibleHolder; holders.addAll(getAllModifiableVariableHoldersFromList(castedList)); } else if (possibleHolder.getClass().isArray()) { holders.addAll( @@ -111,8 +115,8 @@ public static List getAllModifiableVariableHolders } catch (IllegalAccessException | IllegalArgumentException ex) { LOGGER.debug( "Accessing field {} of type {} not possible: {}", - f.getName(), - f.getType(), + field.getName(), + field.getType(), ex.toString()); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableField.java b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableField.java index a694673..95e3dd4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableField.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableField.java @@ -17,11 +17,14 @@ public class ModifiableVariableField { private Field field; - public ModifiableVariableField() {} + public ModifiableVariableField() { + super(); + } - public ModifiableVariableField(Object o, Field f) { - this.object = o; - this.field = f; + public ModifiableVariableField(Object o, Field field) { + super(); + object = o; + this.field = field; } public Object getObject() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableListHolder.java b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableListHolder.java index 84d2a45..732eb48 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableListHolder.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ModifiableVariableListHolder.java @@ -20,11 +20,14 @@ public class ModifiableVariableListHolder { private List fields; - public ModifiableVariableListHolder() {} + public ModifiableVariableListHolder() { + super(); + } - public ModifiableVariableListHolder(Object o, List f) { - this.object = o; - this.fields = f; + public ModifiableVariableListHolder(Object o, List fields) { + super(); + object = o; + this.fields = fields; } public Object getObject() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/RandomHelper.java b/src/main/java/de/rub/nds/modifiablevariable/util/RandomHelper.java index b851fcc..96bdb56 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/RandomHelper.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/RandomHelper.java @@ -10,7 +10,7 @@ import java.util.Random; /** */ -public class RandomHelper { +public final class RandomHelper { private static Random random; @@ -29,5 +29,7 @@ public static void setRandom(Random random) { RandomHelper.random = random; } - private RandomHelper() {} + private RandomHelper() { + super(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java b/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java index 23d0498..ec2c8ec 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java @@ -14,10 +14,15 @@ import java.util.LinkedList; import java.util.List; -public class ReflectionHelper { +public final class ReflectionHelper { + + private ReflectionHelper() { + super(); + } /** - * Source: http://stackoverflow.com/questions/17451506/list-all-private-fields -of-a-java-object + * Source: ... * Retrieves all fields (all access levels) from all classes up the class hierarchy starting * with {@code startClass} stopping with and not including {@code exclusiveParent}. Generally * {@code Object.class} should be passed as {@code exclusiveParent}. @@ -37,8 +42,7 @@ public static List getFieldsUpTo( Class parentClass = startClass.getSuperclass(); - if ((parentClass != null) - && ((exclusiveParent == null) || !(parentClass.equals(exclusiveParent)))) { + if (parentClass != null && !parentClass.equals(exclusiveParent)) { List parentClassFields = getFieldsUpTo(parentClass, exclusiveParent, filterClass); @@ -52,9 +56,9 @@ public static List getFieldsUpTo( private static List filterFieldList(List fields, Class filterClass) { List filteredFields = new LinkedList<>(); - for (Field f : fields) { - if ((filterClass == null) || filterClass.isAssignableFrom(f.getType())) { - filteredFields.add(f); + for (Field field : fields) { + if (filterClass == null || filterClass.isAssignableFrom(field.getType())) { + filteredFields.add(field); } } @@ -65,9 +69,9 @@ public static List getValuesFromFieldList(Object object, List fie throws IllegalAccessException { List list = new LinkedList<>(); - for (Field f : fields) { - f.setAccessible(true); - list.add(f.get(object)); + for (Field field : fields) { + field.setAccessible(true); + list.add(field.get(object)); } return list; diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java index bc07ffa..f94755d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java @@ -7,10 +7,12 @@ */ package de.rub.nds.modifiablevariable.util; -public class StringUtil { +public final class StringUtil { // Private constructor, because this is a utility class that is not meant // to be instantiated. - private StringUtil() {} + private StringUtil() { + super(); + } static final int HI_SURROGATE_START = 0xD800; @@ -21,10 +23,10 @@ private StringUtil() {} * @param value string that may contain non-printable or non-ascii chars * @return string with non-printable or non-ascii characters replaced */ - public static String backslashEscapeString(final String value) { - final StringBuffer buffer = new StringBuffer(value); + public static String backslashEscapeString(String value) { + StringBuffer buffer = new StringBuffer(value); for (int i = 0; i < buffer.length(); i++) { - final int codePoint = buffer.codePointAt(i); + int codePoint = buffer.codePointAt(i); String replacement; int numCodePoints = 1; switch (codePoint) { diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerOperationConcatenationTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerOperationConcatenationTest.java index da0d468..a17cfba 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerOperationConcatenationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerOperationConcatenationTest.java @@ -39,16 +39,12 @@ protected BigInteger modifyImplementationHook(BigInteger input) { @Override public VariableModification getModifiedCopy() { - throw new UnsupportedOperationException("Not supported yet."); // To - // change - // body - // of - // generated - // methods, - // choose - // Tools - // | - // Templates. + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public VariableModification createCopy() { + throw new UnsupportedOperationException("Not supported yet."); } }); expectedResult = new BigInteger("13"); From 9598313ec40224128ba48a01e9ab5f1a764085b5 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 29 Nov 2024 15:35:56 +0100 Subject: [PATCH 17/50] Fix equals() of ModifiableLengthField (I broke it in last commit) --- .../nds/modifiablevariable/length/ModifiableLengthField.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java index 175cefc..2fd2fc5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java +++ b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java @@ -61,7 +61,7 @@ public boolean equals(Object obj) { ModifiableLengthField that = (ModifiableLengthField) obj; - return ref != null ? getValue().equals(getValue()) : that.getValue() == null; + return ref != null ? getValue().equals(that.getValue()) : that.getValue() == null; } @Override From 580b5282657db4e45db4a0a82d163193b3032941 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 29 Nov 2024 15:50:15 +0100 Subject: [PATCH 18/50] Undo changes to use String.format() instead of string concatenation --- .../nds/modifiablevariable/ModifiableVariableHolder.java | 2 +- .../bytearray/ByteArrayAppendValueModification.java | 6 +++--- .../bytearray/ByteArrayPrependValueModification.java | 6 +++--- .../logging/ExtendedPatternLayout.java | 9 ++++++--- .../nds/modifiablevariable/string/ModifiableString.java | 3 +-- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java index 073365f..73bc492 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableHolder.java @@ -95,7 +95,7 @@ public void reset() { } public String getExtendedString() { - return String.format("%s{\n%s}\n", getClass().getSimpleName(), getExtendedString(1)); + return getClass().getSimpleName() + "{\n" + getExtendedString(1) + "}\n"; } protected String getExtendedString(int depth) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index 9048b3d..b9641e5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -94,8 +94,8 @@ public boolean equals(Object obj) { @Override public String toString() { - return String.format( - "ByteArrayInsertModification{bytesToAppend=%s}", - ArrayConverter.bytesToHexString(bytesToAppend)); + return "ByteArrayInsertModification{bytesToAppend=" + + ArrayConverter.bytesToHexString(bytesToAppend) + + "}"; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 792c887..4f0f434 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -94,8 +94,8 @@ public boolean equals(Object obj) { @Override public String toString() { - return String.format( - "ByteArrayInsertModification{bytesToPrepend=%s}", - ArrayConverter.bytesToHexString(bytesToPrepend)); + return "ByteArrayInsertModification{bytesToPrepend=" + + ArrayConverter.bytesToHexString(bytesToPrepend) + + "}"; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java index fa8009b..b293cc8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java +++ b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java @@ -399,9 +399,12 @@ public boolean requiresLocation() { @Override public String toString() { - return String.format( - "%s[patternSelector=%s, replace=%s]", - super.toString(), patternSelector.toString(), replace.toString()); + return super.toString() + + "[patternSelector=" + + patternSelector.toString() + + ", replace=" + + replace.toString() + + "]"; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 237833a..f3a63c1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -88,8 +88,7 @@ public void setOriginalValue(String originalValue) { @Override public String toString() { - return String.format( - "ModifiableString{originalValue=%s}", backslashEscapeString(originalValue)); + return "ModifiableString{originalValue=" + backslashEscapeString(originalValue) + "}"; } @Override From b153a9ec5f722be3ee228e6890af790198b061ec Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Sun, 1 Dec 2024 17:31:45 +0100 Subject: [PATCH 19/50] Change CopyConstructors. Throw NullPointerException instead of allowing null as object. I think it makes no sense to allow null as copy object. --- .gitignore | 8 ++++++-- .../rub/nds/modifiablevariable/ModifiableVariable.java | 10 ++++------ .../biginteger/ModifiableBigInteger.java | 4 +--- .../nds/modifiablevariable/bool/ModifiableBoolean.java | 4 +--- .../bytearray/ModifiableByteArray.java | 6 ++---- .../modifiablevariable/integer/ModifiableInteger.java | 4 +--- .../nds/modifiablevariable/longint/ModifiableLong.java | 4 +--- .../modifiablevariable/singlebyte/ModifiableByte.java | 4 +--- .../modifiablevariable/string/ModifiableString.java | 4 +--- 9 files changed, 18 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index e0f94da..69fb61a 100644 --- a/.gitignore +++ b/.gitignore @@ -9,9 +9,13 @@ nbproject/ nbactions.xml.project nbactions.xml -# IntelliJ -.idea/ +### IntelliJ IDEA ### +.idea/* +!.idea/inspectionProfiles +!.idea/runConfigurations +*.iws *.iml +*.ipr # VS Code .vscode/ diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 8488ab6..b3832cf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -163,12 +163,10 @@ protected ModifiableVariable() { protected ModifiableVariable(ModifiableVariable other) { super(); - if (other != null) { - createRandomModification = other.createRandomModification; - modification = other.modification != null ? other.modification.createCopy() : null; - // Warning: Make sure to copy assertEquals in subclass correctly - assertEquals = other.assertEquals; - } + createRandomModification = other.createRandomModification; + modification = other.modification != null ? other.modification.createCopy() : null; + // Warning: Make sure to copy assertEquals in subclass correctly + assertEquals = other.assertEquals; } public void setModification(VariableModification modification) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index d2af64c..ef32a2b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -27,9 +27,7 @@ public ModifiableBigInteger() { public ModifiableBigInteger(ModifiableBigInteger other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index 3cf082d..64d7f4a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -30,9 +30,7 @@ public ModifiableBoolean(Boolean originalValue) { public ModifiableBoolean(ModifiableBoolean other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index f989cf4..22fb143 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -30,10 +30,8 @@ public ModifiableByteArray() { @SuppressWarnings("IncompleteCopyConstructor") public ModifiableByteArray(ModifiableByteArray other) { super(other); - if (other != null) { - originalValue = other.originalValue != null ? other.originalValue.clone() : null; - assertEquals = other.assertEquals != null ? other.assertEquals.clone() : null; - } + originalValue = other.originalValue != null ? other.originalValue.clone() : null; + assertEquals = other.assertEquals != null ? other.assertEquals.clone() : null; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index 2f401a2..1280d2b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -26,9 +26,7 @@ public ModifiableInteger() { public ModifiableInteger(ModifiableInteger other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index b920476..dbe1622 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -26,9 +26,7 @@ public ModifiableLong() { public ModifiableLong(ModifiableLong other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index af338da..706fc68 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -25,9 +25,7 @@ public ModifiableByte() { public ModifiableByte(ModifiableByte other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index f3a63c1..7fbc8d7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -32,9 +32,7 @@ public ModifiableString() { public ModifiableString(ModifiableString other) { super(other); - if (other != null) { - originalValue = other.originalValue; - } + originalValue = other.originalValue; } @Override From 4b606ee9c5a748f9d5538d25e90985dc4e435943 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Sun, 1 Dec 2024 17:47:51 +0100 Subject: [PATCH 20/50] Add Project_Defaults.xml to repo. So everyone developing on this repo wil see the same Warnings, in IntelliJ. --- .idea/inspectionProfiles/Project_Default.xml | 323 +++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..0ad4972 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,323 @@ + + + + \ No newline at end of file From 509333d92d362f2677a6e4ac7b3660bd6638a0a3 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 2 Dec 2024 16:30:28 +0100 Subject: [PATCH 21/50] Add FromFileModifications, so one can distinguish it from normal explicit value modifications. --- ...egerExplicitValueFromFileModification.java | 75 +++++++++++++++++++ .../BigIntegerExplicitValueModification.java | 2 +- .../BigIntegerModificationFactory.java | 13 ++-- ...rrayExplicitValueFromFileModification.java | 74 ++++++++++++++++++ .../ByteArrayExplicitValueModification.java | 2 +- .../ByteArrayModificationFactory.java | 9 ++- ...egerExplicitValueFromFileModification.java | 73 ++++++++++++++++++ .../IntegerExplicitValueModification.java | 2 +- .../integer/IntegerModificationFactory.java | 10 ++- ...LongExplicitValueFromFileModification.java | 72 ++++++++++++++++++ .../LongExplicitValueModification.java | 2 +- .../longint/LongModificationFactory.java | 10 ++- ...ByteExplicitValueFromFileModification.java | 72 ++++++++++++++++++ .../ByteExplicitValueModification.java | 2 +- .../singlebyte/ByteModificationFactory.java | 10 ++- 15 files changed, 405 insertions(+), 23 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java new file mode 100644 index 0000000..84abbb1 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java @@ -0,0 +1,75 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.biginteger; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.math.BigInteger; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class BigIntegerExplicitValueFromFileModification + extends BigIntegerExplicitValueModification { + private int index; + + public BigIntegerExplicitValueFromFileModification() { + super(); + } + + public BigIntegerExplicitValueFromFileModification(int index, BigInteger explicitValue) { + super(explicitValue); + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of BigIntegerExplicitValueFromFileModification"); + } + + @Override + public VariableModification createCopy() { + return new BigIntegerExplicitValueFromFileModification(index, explicitValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + BigIntegerExplicitValueFromFileModification other = + (BigIntegerExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index 9dae5aa..aee2736 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -23,7 +23,7 @@ public class BigIntegerExplicitValueModification extends VariableModification interactive() { public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { - modificationsFromFile = new LinkedList<>(); + modificationsFromFile = new ArrayList<>(); ClassLoader classLoader = ByteArrayModificationFactory.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream(LongModificationFactory.FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; + int index = 0; while ((line = br.readLine()) != null) { String value = line.trim().split(" ")[0]; if (!value.isEmpty()) { - modificationsFromFile.add(explicitValue(value)); + modificationsFromFile.add( + new BigIntegerExplicitValueFromFileModification( + index, new BigInteger(value))); + index++; } } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java new file mode 100644 index 0000000..92ea790 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java @@ -0,0 +1,74 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.bytearray; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Arrays; + +@XmlRootElement +@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteArrayExplicitValueFromFileModification extends ByteArrayExplicitValueModification { + private int index; + + public ByteArrayExplicitValueFromFileModification() { + super(); + } + + public ByteArrayExplicitValueFromFileModification(int index, byte[] explicitValue) { + super(explicitValue); + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of ByteArrayExplicitValueFromFileModification"); + } + + @Override + public VariableModification createCopy() { + return new ByteArrayExplicitValueFromFileModification( + index, explicitValue != null ? explicitValue.clone() : null); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + Arrays.hashCode(explicitValue); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ByteArrayExplicitValueFromFileModification other = + (ByteArrayExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Arrays.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index f62d203..3f89b0a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -26,7 +26,7 @@ public class ByteArrayExplicitValueModification extends VariableModification shuffle(byte[] shuffle) { public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { - modificationsFromFile = new LinkedList<>(); + modificationsFromFile = new ArrayList<>(); ClassLoader classLoader = ByteArrayModificationFactory.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; + int index = 0; while ((line = br.readLine()) != null) { line = line.replaceAll("\\s+", ""); byte[] value = ArrayConverter.hexStringToByteArray(line); - modificationsFromFile.add(explicitValue(value)); + modificationsFromFile.add( + new ByteArrayExplicitValueFromFileModification(index, value)); + index++; } } return modificationsFromFile; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java new file mode 100644 index 0000000..07295fd --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java @@ -0,0 +1,73 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class IntegerExplicitValueFromFileModification extends IntegerExplicitValueModification { + private int index; + + public IntegerExplicitValueFromFileModification() { + super(); + } + + public IntegerExplicitValueFromFileModification(int index, Integer explicitValue) { + super(explicitValue); + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of IntegerExplicitValueFromFileModification"); + } + + @Override + public VariableModification createCopy() { + return new IntegerExplicitValueFromFileModification(index, explicitValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + IntegerExplicitValueFromFileModification other = + (IntegerExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 408d704..9e26ef0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -19,7 +19,7 @@ public class IntegerExplicitValueModification extends VariableModification multiply(Integer value) { public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { - modificationsFromFile = new LinkedList<>(); + modificationsFromFile = new ArrayList<>(); ClassLoader classLoader = IntegerModificationFactory.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; + int index = 0; while ((line = br.readLine()) != null) { String value = line.trim().split(" ")[0]; - modificationsFromFile.add(explicitValue(value)); + modificationsFromFile.add( + new IntegerExplicitValueFromFileModification( + index, Integer.parseInt(value))); + index++; } } return modificationsFromFile; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java new file mode 100644 index 0000000..791bcb6 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java @@ -0,0 +1,72 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class LongExplicitValueFromFileModification extends LongExplicitValueModification { + private int index; + + public LongExplicitValueFromFileModification() { + super(); + } + + public LongExplicitValueFromFileModification(int index, Long explicitValue) { + super(explicitValue); + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of LongExplicitValueFromFileModification"); + } + + @Override + public VariableModification createCopy() { + return new LongExplicitValueFromFileModification(index, explicitValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + LongExplicitValueFromFileModification other = (LongExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index 4414505..88e46b0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -19,7 +19,7 @@ public class LongExplicitValueModification extends VariableModification { private static final int MAX_EXPLICIT_MODIFIER = 256; - private Long explicitValue; + protected Long explicitValue; public LongExplicitValueModification() { super(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index c0c66a7..0b22db1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -15,7 +15,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -118,14 +118,18 @@ public static VariableModification shiftRight(int shift) { public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { - modificationsFromFile = new LinkedList<>(); + modificationsFromFile = new ArrayList<>(); ClassLoader classLoader = IntegerModificationFactory.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; + int index = 0; while ((line = br.readLine()) != null) { String value = line.trim().split(" ")[0]; - modificationsFromFile.add(explicitValue(value)); + modificationsFromFile.add( + new LongExplicitValueFromFileModification( + index, Long.parseLong(value))); + index++; } } return modificationsFromFile; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java new file mode 100644 index 0000000..16b208d --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java @@ -0,0 +1,72 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.singlebyte; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlAccessorType(XmlAccessType.FIELD) +public class ByteExplicitValueFromFileModification extends ByteExplicitValueModification { + private int index; + + public ByteExplicitValueFromFileModification() { + super(); + } + + public ByteExplicitValueFromFileModification(int index, Byte explicitValue) { + super(explicitValue); + this.index = index; + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of ByteExplicitValueFromFileModification"); + } + + @Override + public VariableModification createCopy() { + return new ByteExplicitValueFromFileModification(index, explicitValue); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ByteExplicitValueFromFileModification other = (ByteExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index b2439ae..bcaf6fd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -19,7 +19,7 @@ public class ByteExplicitValueModification extends VariableModification { private static final int MAX_EXPLICIT_MODIFIER = 16; - private Byte explicitValue; + protected Byte explicitValue; public ByteExplicitValueModification() { super(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java index b9179be..91627a4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java @@ -14,7 +14,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -75,14 +75,18 @@ public static VariableModification explicitValueFromFile(int value) { public static synchronized List> modificationsFromFile() { try { if (modificationsFromFile == null) { - modificationsFromFile = new LinkedList<>(); + modificationsFromFile = new ArrayList<>(); ClassLoader classLoader = ByteModificationFactory.class.getClassLoader(); InputStream is = classLoader.getResourceAsStream(FILE_NAME); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; + int index = 0; while ((line = br.readLine()) != null) { String value = line.trim().split(" ")[0]; - modificationsFromFile.add(explicitValue(value)); + modificationsFromFile.add( + new ByteExplicitValueFromFileModification( + index, Byte.parseByte(value))); + index++; } } return modificationsFromFile; From da88f9be231b7adef2f7f17a51a673ae5b1c06c0 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 2 Dec 2024 22:28:33 +0100 Subject: [PATCH 22/50] Fix CreateCopy() of ByteExplicitValue --- .../singlebyte/ByteExplicitValueModification.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index bcaf6fd..05df3e8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -57,7 +57,7 @@ public VariableModification getModifiedCopy() { @Override public VariableModification createCopy() { - return new ByteAddModification(explicitValue); + return new ByteExplicitValueModification(explicitValue); } @Override From be36e780515742dc717da7de8b12fac514cdddf3 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Tue, 3 Dec 2024 07:48:38 +0100 Subject: [PATCH 23/50] Add missing XmlElement for explicit from file modifications --- .../ModifiableVariable.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index b3832cf..f7fbe2d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -13,10 +13,7 @@ import de.rub.nds.modifiablevariable.bytearray.*; import de.rub.nds.modifiablevariable.integer.*; import de.rub.nds.modifiablevariable.longint.*; -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.singlebyte.*; import de.rub.nds.modifiablevariable.string.StringAppendValueModification; import de.rub.nds.modifiablevariable.string.StringExplicitValueModification; import de.rub.nds.modifiablevariable.string.StringInsertValueModification; @@ -53,6 +50,9 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = BigIntegerShiftLeftModification.class, name = "BigIntegerShiftLeftModification"), + @XmlElement( + type = BigIntegerExplicitValueFromFileModification.class, + name = "BigIntegerExplicitValueFromFileModification"), @XmlElement( type = BigIntegerExplicitValueModification.class, name = "BigIntegerExplicitValueModification"), @@ -89,6 +89,9 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = ByteArrayPrependValueModification.class, name = "ByteArrayPrependValueModification"), + @XmlElement( + type = ByteArrayExplicitValueFromFileModification.class, + name = "ByteArrayExplicitValueFromFileModification"), @XmlElement( type = ByteArrayExplicitValueModification.class, name = "ByteArrayExplicitValueModification"), @@ -105,6 +108,9 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = IntegerShiftLeftModification.class, name = "IntegerShiftLeftModification"), + @XmlElement( + type = IntegerExplicitValueFromFileModification.class, + name = "IntegerExplicitValueFromFileModification"), @XmlElement( type = IntegerExplicitValueModification.class, name = "IntegerExplicitValueModification"), @@ -120,6 +126,9 @@ public abstract class ModifiableVariable implements Serializable { name = "IntegerPrependValueModification"), @XmlElement(type = LongXorModification.class, name = "LongXorModification"), @XmlElement(type = LongSubtractModification.class, name = "LongSubtractModification"), + @XmlElement( + type = LongExplicitValueFromFileModification.class, + name = "LongExplicitValueFromFileModification"), @XmlElement( type = LongExplicitValueModification.class, name = "LongExplicitValueModification"), @@ -135,6 +144,9 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement(type = ByteXorModification.class, name = "ByteXorModification"), @XmlElement(type = ByteSubtractModification.class, name = "ByteSubtractModification"), @XmlElement(type = ByteAddModification.class, name = "ByteAddModification"), + @XmlElement( + type = ByteExplicitValueFromFileModification.class, + name = "ByteExplicitValueFromFileModification"), @XmlElement( type = ByteExplicitValueModification.class, name = "ByteExplicitValueModification"), From c073a2b7cb46f1b344ac3bfab6d5713283793df5 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 4 Dec 2024 18:43:14 +0100 Subject: [PATCH 24/50] Add PathModification. Fix copy methods --- .../ModifiableVariable.java | 6 + .../ModificationFilter.java | 10 + .../VariableModification.java | 14 +- .../biginteger/BigIntegerAddModification.java | 15 +- .../BigIntegerAppendValueModification.java | 15 +- ...egerExplicitValueFromFileModification.java | 18 +- .../BigIntegerExplicitValueModification.java | 15 +- .../BigIntegerInsertValueModification.java | 16 +- .../BigIntegerMultiplyModification.java | 15 +- .../BigIntegerPrependValueModification.java | 15 +- .../BigIntegerShiftLeftModification.java | 15 +- .../BigIntegerShiftRightModification.java | 15 +- .../BigIntegerSubtractModification.java | 15 +- .../biginteger/BigIntegerXorModification.java | 15 +- .../biginteger/ModifiableBigInteger.java | 10 +- .../BooleanExplicitValueModification.java | 15 +- .../bool/BooleanToggleModification.java | 14 +- .../bool/ModifiableBoolean.java | 10 +- .../ByteArrayAppendValueModification.java | 16 +- .../ByteArrayDeleteModification.java | 16 +- .../ByteArrayDuplicateModification.java | 14 +- ...rrayExplicitValueFromFileModification.java | 19 +- .../ByteArrayExplicitValueModification.java | 16 +- .../ByteArrayInsertValueModification.java | 17 +- .../ByteArrayPrependValueModification.java | 16 +- .../ByteArrayShuffleModification.java | 15 +- .../bytearray/ByteArrayXorModification.java | 16 +- .../bytearray/ModifiableByteArray.java | 11 +- .../filter/AccessModificationFilter.java | 11 ++ .../integer/IntegerAddModification.java | 15 +- .../IntegerAppendValueModification.java | 15 +- ...egerExplicitValueFromFileModification.java | 18 +- .../IntegerExplicitValueModification.java | 15 +- .../IntegerInsertValueModification.java | 16 +- .../integer/IntegerMultiplyModification.java | 15 +- .../IntegerPrependValueModification.java | 15 +- .../integer/IntegerShiftLeftModification.java | 15 +- .../IntegerShiftRightModification.java | 15 +- .../integer/IntegerSubtractModification.java | 15 +- .../integer/IntegerXorModification.java | 15 +- .../integer/ModifiableInteger.java | 10 +- .../longint/LongAddModification.java | 15 +- .../longint/LongAppendValueModification.java | 15 +- ...LongExplicitValueFromFileModification.java | 17 +- .../LongExplicitValueModification.java | 15 +- .../longint/LongInsertValueModification.java | 16 +- .../longint/LongMultiplyModification.java | 15 +- .../longint/LongPrependValueModification.java | 15 +- .../longint/LongShiftLeftModification.java | 15 +- .../longint/LongShiftRightModification.java | 15 +- .../longint/LongSubtractModification.java | 15 +- .../longint/LongXorModification.java | 15 +- .../longint/ModifiableLong.java | 10 +- .../path/ModifiablePath.java | 60 ++++++ .../path/PathAppendValueModification.java | 97 ++++++++++ ...rtDirectoryTraversalValueModification.java | 177 ++++++++++++++++++ .../path/PathInsertValueModification.java | 158 ++++++++++++++++ .../path/PathModificationFactory.java | 88 +++++++++ .../path/PathPrependValueModification.java | 97 ++++++++++ .../path/PathToggleRootValueModification.java | 63 +++++++ .../singlebyte/ByteAddModification.java | 15 +- ...ByteExplicitValueFromFileModification.java | 17 +- .../ByteExplicitValueModification.java | 15 +- .../singlebyte/ByteSubtractModification.java | 15 +- .../singlebyte/ByteXorModification.java | 15 +- .../singlebyte/ModifiableByte.java | 10 +- .../string/ModifiableString.java | 12 +- .../string/StringAppendValueModification.java | 17 +- ...ringExplicitValueFromFileModification.java | 78 ++++++++ .../StringExplicitValueModification.java | 17 +- .../string/StringInsertValueModification.java | 19 +- .../StringPrependValueModification.java | 17 +- .../ByteArraySerializationTest.java | 1 - 73 files changed, 1442 insertions(+), 318 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index f7fbe2d..29a45a4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -202,6 +202,12 @@ public E getValue() { return getOriginalValue(); } + public void reduceToOriginalValue(boolean evenWithNullOriginalValue) { + if (evenWithNullOriginalValue || getOriginalValue() != null) { + setOriginalValue(getValue()); + } + } + public abstract E getOriginalValue(); public abstract void setOriginalValue(E originalValue); diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java b/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java index 94f19f0..2481642 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModificationFilter.java @@ -18,5 +18,15 @@ @XmlSeeAlso(AccessModificationFilter.class) public abstract class ModificationFilter { + protected ModificationFilter() { + super(); + } + + protected ModificationFilter(ModificationFilter other) { + super(); + } + + public abstract ModificationFilter createCopy(); + public abstract boolean filterModification(); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java index 6558dcd..be4396b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java @@ -35,6 +35,18 @@ public abstract class VariableModification { @XmlElement(type = AccessModificationFilter.class, name = "AccessModificationFilter")) private ModificationFilter modificationFilter; + protected VariableModification() { + super(); + } + + protected VariableModification(VariableModification other) { + super(); + modificationFilter = + other.modificationFilter != null ? other.modificationFilter.createCopy() : null; + } + + public abstract VariableModification createCopy(); + public E modify(E input) { E modifiedValue = modifyImplementationHook(input); if (modificationFilter == null || !modificationFilter.filterModification()) { @@ -49,8 +61,6 @@ public E modify(E input) { public abstract VariableModification getModifiedCopy(); - public abstract VariableModification createCopy(); - /** * Debugging modified variables. Getting stack trace can be time-consuming, thus we use * isDebugEnabled() function diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index cd55562..7fbbdde 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -34,6 +34,16 @@ public BigIntegerAddModification(BigInteger summand) { this.summand = summand; } + public BigIntegerAddModification(BigIntegerAddModification other) { + super(other); + summand = other.summand; + } + + @Override + public BigIntegerAddModification createCopy() { + return new BigIntegerAddModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { return input == null ? summand : input.add(summand); @@ -53,11 +63,6 @@ public VariableModification getModifiedCopy() { summand.add(new BigInteger(MAX_ADD_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerAddModification(summand); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index c894edf..15068f5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -34,6 +34,16 @@ public BigIntegerAppendValueModification(BigInteger appendValue) { this.appendValue = appendValue; } + public BigIntegerAppendValueModification(BigIntegerAppendValueModification other) { + super(other); + appendValue = other.appendValue; + } + + @Override + public BigIntegerAppendValueModification createCopy() { + return new BigIntegerAppendValueModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -56,11 +66,6 @@ public VariableModification getModifiedCopy() { appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerAppendValueModification(appendValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java index 84abbb1..ae7eba2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java @@ -16,7 +16,7 @@ import java.util.Objects; @XmlRootElement -@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlType(propOrder = "index") @XmlAccessorType(XmlAccessType.FIELD) public class BigIntegerExplicitValueFromFileModification extends BigIntegerExplicitValueModification { @@ -31,6 +31,17 @@ public BigIntegerExplicitValueFromFileModification(int index, BigInteger explici this.index = index; } + public BigIntegerExplicitValueFromFileModification( + BigIntegerExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public BigIntegerExplicitValueFromFileModification createCopy() { + return new BigIntegerExplicitValueFromFileModification(this); + } + public int getIndex() { return index; } @@ -41,11 +52,6 @@ public VariableModification getModifiedCopy() { "Cannot set modify Value of BigIntegerExplicitValueFromFileModification"); } - @Override - public VariableModification createCopy() { - return new BigIntegerExplicitValueFromFileModification(index, explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index aee2736..d3694ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -34,6 +34,16 @@ public BigIntegerExplicitValueModification(BigInteger explicitValue) { this.explicitValue = explicitValue; } + public BigIntegerExplicitValueModification(BigIntegerExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public BigIntegerExplicitValueModification createCopy() { + return new BigIntegerExplicitValueModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { return explicitValue; @@ -59,11 +69,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new BigIntegerExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java index 407b8bb..d088685 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -37,6 +37,17 @@ public BigIntegerInsertValueModification(BigInteger insertValue, int startPositi this.startPosition = startPosition; } + public BigIntegerInsertValueModification(BigIntegerInsertValueModification other) { + super(other); + insertValue = other.insertValue; + startPosition = other.startPosition; + } + + @Override + public BigIntegerInsertValueModification createCopy() { + return new BigIntegerInsertValueModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -97,11 +108,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new BigIntegerInsertValueModification(insertValue, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index e5141c1..9569280 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -34,6 +34,16 @@ public BigIntegerMultiplyModification(BigInteger factor) { this.factor = factor; } + public BigIntegerMultiplyModification(BigIntegerMultiplyModification other) { + super(other); + factor = other.factor; + } + + @Override + public BigIntegerMultiplyModification createCopy() { + return new BigIntegerMultiplyModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { return input == null ? BigInteger.ZERO : input.multiply(factor); @@ -53,11 +63,6 @@ public VariableModification getModifiedCopy() { factor.add(new BigInteger(MAX_FACTOR_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerMultiplyModification(factor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 282bf2d..7bc86e7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -34,6 +34,16 @@ public BigIntegerPrependValueModification(BigInteger prependValue) { this.prependValue = prependValue; } + public BigIntegerPrependValueModification(BigIntegerPrependValueModification other) { + super(other); + prependValue = other.prependValue; + } + + @Override + public BigIntegerPrependValueModification createCopy() { + return new BigIntegerPrependValueModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -56,11 +66,6 @@ public VariableModification getModifiedCopy() { prependValue.add(new BigInteger(MAX_PREPEND_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerPrependValueModification(prependValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index 569280c..1509533 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -33,6 +33,16 @@ public BigIntegerShiftLeftModification(int shift) { this.shift = shift; } + public BigIntegerShiftLeftModification(BigIntegerShiftLeftModification other) { + super(other); + shift = other.shift; + } + + @Override + public BigIntegerShiftLeftModification createCopy() { + return new BigIntegerShiftLeftModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -54,11 +64,6 @@ public VariableModification getModifiedCopy() { return new BigIntegerShiftLeftModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH)); } - @Override - public VariableModification createCopy() { - return new BigIntegerShiftLeftModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index f103d97..0e59888 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -33,6 +33,16 @@ public BigIntegerShiftRightModification(int shift) { this.shift = shift; } + public BigIntegerShiftRightModification(BigIntegerShiftRightModification other) { + super(other); + shift = other.shift; + } + + @Override + public BigIntegerShiftRightModification createCopy() { + return new BigIntegerShiftRightModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -54,11 +64,6 @@ public VariableModification getModifiedCopy() { return new BigIntegerShiftRightModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH)); } - @Override - public VariableModification createCopy() { - return new BigIntegerShiftRightModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index a818dc8..f8fce93 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -34,6 +34,16 @@ public BigIntegerSubtractModification(BigInteger subtrahend) { this.subtrahend = subtrahend; } + public BigIntegerSubtractModification(BigIntegerSubtractModification other) { + super(other); + subtrahend = other.subtrahend; + } + + @Override + public BigIntegerSubtractModification createCopy() { + return new BigIntegerSubtractModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -56,11 +66,6 @@ public VariableModification getModifiedCopy() { subtrahend.add(new BigInteger(MAX_SUBTRACT_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerSubtractModification(subtrahend); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index 2c3529a..5cbc9bb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -34,6 +34,16 @@ public BigIntegerXorModification(BigInteger xor) { this.xor = xor; } + public BigIntegerXorModification(BigIntegerXorModification other) { + super(other); + xor = other.xor; + } + + @Override + public BigIntegerXorModification createCopy() { + return new BigIntegerXorModification(this); + } + @Override protected BigInteger modifyImplementationHook(BigInteger input) { if (input == null) { @@ -55,11 +65,6 @@ public VariableModification getModifiedCopy() { return new BigIntegerXorModification(xor.add(new BigInteger(MAX_XOR_LENGTH, new Random()))); } - @Override - public VariableModification createCopy() { - return new BigIntegerXorModification(xor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index ef32a2b..07eb645 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -30,6 +30,11 @@ public ModifiableBigInteger(ModifiableBigInteger other) { originalValue = other.originalValue; } + @Override + public ModifiableBigInteger createCopy() { + return new ModifiableBigInteger(this); + } + @Override protected void createRandomModification() { VariableModification vm = @@ -37,11 +42,6 @@ protected void createRandomModification() { setModification(vm); } - @Override - public ModifiableBigInteger createCopy() { - return new ModifiableBigInteger(this); - } - public BigInteger getAssertEquals() { return assertEquals; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java index 744ba2f..123d95f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanExplicitValueModification.java @@ -26,6 +26,16 @@ public BooleanExplicitValueModification(boolean explicitValue) { this.explicitValue = explicitValue; } + public BooleanExplicitValueModification(BooleanExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public BooleanExplicitValueModification createCopy() { + return new BooleanExplicitValueModification(this); + } + @Override protected Boolean modifyImplementationHook(Boolean input) { return explicitValue; @@ -44,11 +54,6 @@ public VariableModification getModifiedCopy() { return new BooleanExplicitValueModification(!explicitValue); } - @Override - public VariableModification createCopy() { - return new BooleanExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java index 5d12e6a..34ad760 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/BooleanToggleModification.java @@ -19,6 +19,15 @@ public BooleanToggleModification() { super(); } + public BooleanToggleModification(BooleanToggleModification other) { + super(other); + } + + @Override + public BooleanToggleModification createCopy() { + return new BooleanToggleModification(this); + } + @Override protected Boolean modifyImplementationHook(Boolean input) { if (input == null) { @@ -32,11 +41,6 @@ public VariableModification getModifiedCopy() { return new BooleanToggleModification(); } - @Override - public VariableModification createCopy() { - return new BooleanToggleModification(); - } - @Override public int hashCode() { return 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index 64d7f4a..fc03f2d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -33,6 +33,11 @@ public ModifiableBoolean(ModifiableBoolean other) { originalValue = other.originalValue; } + @Override + public ModifiableBoolean createCopy() { + return new ModifiableBoolean(this); + } + @Override public Boolean getOriginalValue() { return originalValue; @@ -49,11 +54,6 @@ protected void createRandomModification() { setModification(vm); } - @Override - public ModifiableBoolean createCopy() { - return new ModifiableBoolean(this); - } - @Override public boolean isOriginalValueModified() { return originalValue != null && originalValue.compareTo(getValue()) != 0; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java index b9641e5..78eb3d2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayAppendValueModification.java @@ -37,6 +37,16 @@ public ByteArrayAppendValueModification(byte[] bytesToAppend) { this.bytesToAppend = bytesToAppend; } + public ByteArrayAppendValueModification(ByteArrayAppendValueModification other) { + super(other); + bytesToAppend = other.bytesToAppend != null ? other.bytesToAppend.clone() : null; + } + + @Override + public ByteArrayAppendValueModification createCopy() { + return new ByteArrayAppendValueModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -64,12 +74,6 @@ public VariableModification getModifiedCopy() { return new ByteArrayAppendValueModification(newValue); } - @Override - public VariableModification createCopy() { - return new ByteArrayAppendValueModification( - bytesToAppend != null ? bytesToAppend.clone() : null); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 4838c43..f44e2a1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -39,6 +39,17 @@ public ByteArrayDeleteModification(int startPosition, int count) { this.count = count; } + public ByteArrayDeleteModification(ByteArrayDeleteModification other) { + super(other); + count = other.count; + startPosition = other.startPosition; + } + + @Override + public ByteArrayDeleteModification createCopy() { + return new ByteArrayDeleteModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -114,11 +125,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new ByteArrayDeleteModification(startPosition, count); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java index 55d5f3c..b919fcc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDuplicateModification.java @@ -23,6 +23,15 @@ public ByteArrayDuplicateModification() { super(); } + public ByteArrayDuplicateModification(ByteArrayDuplicateModification other) { + super(other); + } + + @Override + public ByteArrayDuplicateModification createCopy() { + return new ByteArrayDuplicateModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -36,11 +45,6 @@ public VariableModification getModifiedCopy() { return new ByteArrayDuplicateModification(); } - @Override - public VariableModification createCopy() { - return new ByteArrayDuplicateModification(); - } - @Override public int hashCode() { return 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java index 92ea790..e95a9e3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java @@ -15,7 +15,7 @@ import java.util.Arrays; @XmlRootElement -@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlType(propOrder = "index") @XmlAccessorType(XmlAccessType.FIELD) public class ByteArrayExplicitValueFromFileModification extends ByteArrayExplicitValueModification { private int index; @@ -29,6 +29,17 @@ public ByteArrayExplicitValueFromFileModification(int index, byte[] explicitValu this.index = index; } + public ByteArrayExplicitValueFromFileModification( + ByteArrayExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public ByteArrayExplicitValueFromFileModification createCopy() { + return new ByteArrayExplicitValueFromFileModification(this); + } + public int getIndex() { return index; } @@ -39,12 +50,6 @@ public VariableModification getModifiedCopy() { "Cannot set modify Value of ByteArrayExplicitValueFromFileModification"); } - @Override - public VariableModification createCopy() { - return new ByteArrayExplicitValueFromFileModification( - index, explicitValue != null ? explicitValue.clone() : null); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java index 3f89b0a..83fca1b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueModification.java @@ -37,6 +37,16 @@ public ByteArrayExplicitValueModification(byte[] explicitValue) { this.explicitValue = explicitValue; } + public ByteArrayExplicitValueModification(ByteArrayExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue != null ? other.explicitValue.clone() : null; + } + + @Override + public ByteArrayExplicitValueModification createCopy() { + return new ByteArrayExplicitValueModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { return explicitValue.clone(); @@ -70,12 +80,6 @@ public VariableModification getModifiedCopy() { return new ByteArrayExplicitValueModification(newValue); } - @Override - public VariableModification createCopy() { - return new ByteArrayExplicitValueModification( - explicitValue != null ? explicitValue.clone() : null); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java index 180f16b..59579e1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertValueModification.java @@ -42,6 +42,17 @@ public ByteArrayInsertValueModification(byte[] bytesToInsert, int startPosition) this.startPosition = startPosition; } + public ByteArrayInsertValueModification(ByteArrayInsertValueModification other) { + super(other); + bytesToInsert = other.bytesToInsert != null ? other.bytesToInsert.clone() : null; + startPosition = other.startPosition; + } + + @Override + public ByteArrayInsertValueModification createCopy() { + return new ByteArrayInsertValueModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -101,12 +112,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new ByteArrayInsertValueModification( - bytesToInsert != null ? bytesToInsert.clone() : null, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 4f0f434..17e8135 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -37,6 +37,16 @@ public ByteArrayPrependValueModification(byte[] bytesToPrepend) { this.bytesToPrepend = bytesToPrepend; } + public ByteArrayPrependValueModification(ByteArrayPrependValueModification other) { + super(other); + bytesToPrepend = other.bytesToPrepend != null ? other.bytesToPrepend.clone() : null; + } + + @Override + public ByteArrayPrependValueModification createCopy() { + return new ByteArrayPrependValueModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -64,12 +74,6 @@ public VariableModification getModifiedCopy() { return new ByteArrayPrependValueModification(newValue); } - @Override - public VariableModification createCopy() { - return new ByteArrayPrependValueModification( - bytesToPrepend != null ? bytesToPrepend.clone() : null); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 0ce87fd..cddfd27 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -41,6 +41,16 @@ public ByteArrayShuffleModification(byte[] shuffle) { this.shuffle = shuffle; } + public ByteArrayShuffleModification(ByteArrayShuffleModification other) { + super(other); + shuffle = other.shuffle != null ? other.shuffle.clone() : null; + } + + @Override + public ByteArrayShuffleModification createCopy() { + return new ByteArrayShuffleModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -77,11 +87,6 @@ public VariableModification getModifiedCopy() { return new ByteArrayShuffleModification(newValue); } - @Override - public VariableModification createCopy() { - return new ByteArrayShuffleModification(shuffle != null ? shuffle.clone() : null); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index 9dfbb39..b26a5c8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -42,6 +42,17 @@ public ByteArrayXorModification(byte[] xor, int startPosition) { this.startPosition = startPosition; } + public ByteArrayXorModification(ByteArrayXorModification other) { + super(other); + xor = other.xor != null ? other.xor.clone() : null; + startPosition = other.startPosition; + } + + @Override + public ByteArrayXorModification createCopy() { + return new ByteArrayXorModification(this); + } + @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { @@ -109,11 +120,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new ByteArrayXorModification(xor != null ? xor.clone() : null, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index 22fb143..3bd16da 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -27,13 +27,17 @@ public ModifiableByteArray() { super(); } - @SuppressWarnings("IncompleteCopyConstructor") public ModifiableByteArray(ModifiableByteArray other) { super(other); originalValue = other.originalValue != null ? other.originalValue.clone() : null; assertEquals = other.assertEquals != null ? other.assertEquals.clone() : null; } + @Override + public ModifiableByteArray createCopy() { + return new ModifiableByteArray(this); + } + @Override protected void createRandomModification() { VariableModification vm = @@ -41,11 +45,6 @@ protected void createRandomModification() { setModification(vm); } - @Override - public ModifiableByteArray createCopy() { - return new ModifiableByteArray(this); - } - @Override @XmlJavaTypeAdapter(UnformattedByteArrayAdapter.class) public byte[] getOriginalValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java b/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java index 54ca94c..cbf940a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/filter/AccessModificationFilter.java @@ -39,6 +39,17 @@ public AccessModificationFilter(int[] accessNumbers) { this.accessNumbers = accessNumbers; } + public AccessModificationFilter(AccessModificationFilter other) { + super(other); + accessCounter = other.accessCounter; + accessNumbers = other.accessNumbers != null ? other.accessNumbers.clone() : null; + } + + @Override + public AccessModificationFilter createCopy() { + return new AccessModificationFilter(this); + } + @Override public boolean filterModification() { boolean filter = contains(accessNumbers, accessCounter); diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index 129906a..f7f698f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -30,6 +30,16 @@ public IntegerAddModification(Integer summand) { this.summand = summand; } + public IntegerAddModification(IntegerAddModification other) { + super(other); + summand = other.summand; + } + + @Override + public IntegerAddModification createCopy() { + return new IntegerAddModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? summand : input + summand; @@ -48,11 +58,6 @@ public VariableModification getModifiedCopy() { return new IntegerAddModification(summand + new Random().nextInt(MAX_ADD_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new IntegerAddModification(summand); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index 572f659..3cbafa1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -30,6 +30,16 @@ public IntegerAppendValueModification(Integer appendValue) { this.appendValue = appendValue; } + public IntegerAppendValueModification(IntegerAppendValueModification other) { + super(other); + appendValue = other.appendValue; + } + + @Override + public IntegerAppendValueModification createCopy() { + return new IntegerAppendValueModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { if (input == null) { @@ -52,11 +62,6 @@ public VariableModification getModifiedCopy() { appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new IntegerAppendValueModification(appendValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java index 07295fd..488875a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java @@ -15,7 +15,7 @@ import java.util.Objects; @XmlRootElement -@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlType(propOrder = "index") @XmlAccessorType(XmlAccessType.FIELD) public class IntegerExplicitValueFromFileModification extends IntegerExplicitValueModification { private int index; @@ -29,6 +29,17 @@ public IntegerExplicitValueFromFileModification(int index, Integer explicitValue this.index = index; } + public IntegerExplicitValueFromFileModification( + IntegerExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public IntegerExplicitValueFromFileModification createCopy() { + return new IntegerExplicitValueFromFileModification(this); + } + public int getIndex() { return index; } @@ -39,11 +50,6 @@ public VariableModification getModifiedCopy() { "Cannot set modify Value of IntegerExplicitValueFromFileModification"); } - @Override - public VariableModification createCopy() { - return new IntegerExplicitValueFromFileModification(index, explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 9e26ef0..26ec5ea 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -30,6 +30,16 @@ public IntegerExplicitValueModification(Integer explicitValue) { this.explicitValue = explicitValue; } + public IntegerExplicitValueModification(IntegerExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public IntegerExplicitValueModification createCopy() { + return new IntegerExplicitValueModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return explicitValue; @@ -55,11 +65,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new IntegerExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index 36b0c27..f56056c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -35,6 +35,17 @@ public IntegerInsertValueModification(Integer insertValue, int startPosition) { this.startPosition = startPosition; } + public IntegerInsertValueModification(IntegerInsertValueModification other) { + super(other); + insertValue = other.insertValue; + startPosition = other.startPosition; + } + + @Override + public IntegerInsertValueModification createCopy() { + return new IntegerInsertValueModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { if (input == null) { @@ -91,11 +102,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new IntegerInsertValueModification(insertValue, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index a978315..aae8071 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -30,6 +30,16 @@ public IntegerMultiplyModification(Integer factor) { this.factor = factor; } + public IntegerMultiplyModification(IntegerMultiplyModification other) { + super(other); + factor = other.factor; + } + + @Override + public IntegerMultiplyModification createCopy() { + return new IntegerMultiplyModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? 0 : input * factor; @@ -50,11 +60,6 @@ public VariableModification getModifiedCopy() { return new IntegerMultiplyModification(factor + r.nextInt(MAX_FACTOR_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new IntegerMultiplyModification(factor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index 67c970a..a8043aa 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -30,6 +30,16 @@ public IntegerPrependValueModification(Integer prependValue) { this.prependValue = prependValue; } + public IntegerPrependValueModification(IntegerPrependValueModification other) { + super(other); + prependValue = other.prependValue; + } + + @Override + public IntegerPrependValueModification createCopy() { + return new IntegerPrependValueModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { if (input == null) { @@ -53,11 +63,6 @@ public VariableModification getModifiedCopy() { prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new IntegerPrependValueModification(prependValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index f619d77..712e7c8 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -29,6 +29,16 @@ public IntegerShiftLeftModification(int shift) { this.shift = shift; } + public IntegerShiftLeftModification(IntegerShiftLeftModification other) { + super(other); + shift = other.shift; + } + + @Override + public IntegerShiftLeftModification createCopy() { + return new IntegerShiftLeftModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? 0 : input << shift % MAX_SHIFT_MODIFIER; @@ -59,11 +69,6 @@ public VariableModification getModifiedCopy() { return new IntegerShiftLeftModification(newShift); } - @Override - public VariableModification createCopy() { - return new IntegerShiftLeftModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index 7fe1383..0abfd06 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -29,6 +29,16 @@ public IntegerShiftRightModification(int shift) { this.shift = shift; } + public IntegerShiftRightModification(IntegerShiftRightModification other) { + super(other); + shift = other.shift; + } + + @Override + public IntegerShiftRightModification createCopy() { + return new IntegerShiftRightModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? 0 : input >> shift % MAX_SHIFT_MODIFIER; @@ -59,11 +69,6 @@ public VariableModification getModifiedCopy() { return new IntegerShiftRightModification(newShift); } - @Override - public VariableModification createCopy() { - return new IntegerShiftRightModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index aa070ac..e052658 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -30,6 +30,16 @@ public IntegerSubtractModification(Integer subtrahend) { this.subtrahend = subtrahend; } + public IntegerSubtractModification(IntegerSubtractModification other) { + super(other); + subtrahend = other.subtrahend; + } + + @Override + public IntegerSubtractModification createCopy() { + return new IntegerSubtractModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? -subtrahend : input - subtrahend; @@ -49,11 +59,6 @@ public VariableModification getModifiedCopy() { subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new IntegerSubtractModification(subtrahend); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index 09c6e09..729392e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -30,6 +30,16 @@ public IntegerXorModification(Integer xor) { this.xor = xor; } + public IntegerXorModification(IntegerXorModification other) { + super(other); + xor = other.xor; + } + + @Override + public IntegerXorModification createCopy() { + return new IntegerXorModification(this); + } + @Override protected Integer modifyImplementationHook(Integer input) { return input == null ? xor : input ^ xor; @@ -53,11 +63,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new IntegerXorModification(xor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index 1280d2b..0977990 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -30,14 +30,14 @@ public ModifiableInteger(ModifiableInteger other) { } @Override - protected void createRandomModification() { - VariableModification vm = IntegerModificationFactory.createRandomModification(); - setModification(vm); + public ModifiableInteger createCopy() { + return new ModifiableInteger(this); } @Override - public ModifiableInteger createCopy() { - return new ModifiableInteger(this); + protected void createRandomModification() { + VariableModification vm = IntegerModificationFactory.createRandomModification(); + setModification(vm); } public Integer getAssertEquals() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index 2a2bc5a..d5339a5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -30,6 +30,16 @@ public LongAddModification(Long summand) { this.summand = summand; } + public LongAddModification(LongAddModification other) { + super(other); + summand = other.summand; + } + + @Override + public LongAddModification createCopy() { + return new LongAddModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? summand : input + summand; @@ -48,11 +58,6 @@ public VariableModification getModifiedCopy() { return new LongAddModification(summand + new Random().nextInt(MAX_ADD_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new LongAddModification(summand); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index 04bfa00..2b1c633 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -30,6 +30,16 @@ public LongAppendValueModification(Long appendValue) { this.appendValue = appendValue; } + public LongAppendValueModification(LongAppendValueModification other) { + super(other); + appendValue = other.appendValue; + } + + @Override + public LongAppendValueModification createCopy() { + return new LongAppendValueModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { if (input == null) { @@ -52,11 +62,6 @@ public VariableModification getModifiedCopy() { appendValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new LongAppendValueModification(appendValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java index 791bcb6..f242228 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java @@ -15,7 +15,7 @@ import java.util.Objects; @XmlRootElement -@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlType(propOrder = "index") @XmlAccessorType(XmlAccessType.FIELD) public class LongExplicitValueFromFileModification extends LongExplicitValueModification { private int index; @@ -29,6 +29,16 @@ public LongExplicitValueFromFileModification(int index, Long explicitValue) { this.index = index; } + public LongExplicitValueFromFileModification(LongExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public LongExplicitValueFromFileModification createCopy() { + return new LongExplicitValueFromFileModification(this); + } + public int getIndex() { return index; } @@ -39,11 +49,6 @@ public VariableModification getModifiedCopy() { "Cannot set modify Value of LongExplicitValueFromFileModification"); } - @Override - public VariableModification createCopy() { - return new LongExplicitValueFromFileModification(index, explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index 88e46b0..e2bd2af 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -30,6 +30,16 @@ public LongExplicitValueModification(Long explicitValue) { this.explicitValue = explicitValue; } + public LongExplicitValueModification(LongExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public LongExplicitValueModification createCopy() { + return new LongExplicitValueModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return explicitValue; @@ -55,11 +65,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new LongExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index a16e9e0..9f77686 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -33,6 +33,17 @@ public LongInsertValueModification(Long insertValue, int startPosition) { this.startPosition = startPosition; } + public LongInsertValueModification(LongInsertValueModification other) { + super(other); + insertValue = other.insertValue; + startPosition = other.startPosition; + } + + @Override + public LongInsertValueModification createCopy() { + return new LongInsertValueModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { if (input == null) { @@ -89,11 +100,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new LongInsertValueModification(insertValue, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java index 463d82f..76f735f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java @@ -30,6 +30,16 @@ public LongMultiplyModification(Long factor) { this.factor = factor; } + public LongMultiplyModification(LongMultiplyModification other) { + super(other); + factor = other.factor; + } + + @Override + public LongMultiplyModification createCopy() { + return new LongMultiplyModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? 0L : input * factor; @@ -48,11 +58,6 @@ public VariableModification getModifiedCopy() { return new LongMultiplyModification(factor + new Random().nextInt(MAX_FACTOR_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new LongMultiplyModification(factor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index e0ec781..a2ddbd6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -30,6 +30,16 @@ public LongPrependValueModification(Long prependValue) { this.prependValue = prependValue; } + public LongPrependValueModification(LongPrependValueModification other) { + super(other); + prependValue = other.prependValue; + } + + @Override + public LongPrependValueModification createCopy() { + return new LongPrependValueModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { if (input == null) { @@ -52,11 +62,6 @@ public VariableModification getModifiedCopy() { prependValue + new Random().nextInt(MAX_VALUE_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new LongPrependValueModification(prependValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java index bf508fe..2a65b5c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java @@ -30,6 +30,16 @@ public LongShiftLeftModification(int shift) { this.shift = shift; } + public LongShiftLeftModification(LongShiftLeftModification other) { + super(other); + shift = other.shift; + } + + @Override + public LongShiftLeftModification createCopy() { + return new LongShiftLeftModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? 0L : input << shift % MAX_SHIFT_MODIFIER; @@ -61,11 +71,6 @@ public VariableModification getModifiedCopy() { return new LongShiftLeftModification(newShift); } - @Override - public VariableModification createCopy() { - return new LongShiftLeftModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java index c901d71..bb0d5a7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java @@ -30,6 +30,16 @@ public LongShiftRightModification(int shift) { this.shift = shift; } + public LongShiftRightModification(LongShiftRightModification other) { + super(other); + shift = other.shift; + } + + @Override + public LongShiftRightModification createCopy() { + return new LongShiftRightModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? 0L : input >> shift % MAX_SHIFT_MODIFIER; @@ -61,11 +71,6 @@ public VariableModification getModifiedCopy() { return new LongShiftRightModification(newShift); } - @Override - public VariableModification createCopy() { - return new LongShiftRightModification(shift); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index f303ca8..2af2263 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -30,6 +30,16 @@ public LongSubtractModification(Long subtrahend) { this.subtrahend = subtrahend; } + public LongSubtractModification(LongSubtractModification other) { + super(other); + subtrahend = other.subtrahend; + } + + @Override + public LongSubtractModification createCopy() { + return new LongSubtractModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? -subtrahend : input - subtrahend; @@ -49,11 +59,6 @@ public VariableModification getModifiedCopy() { subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER)); } - @Override - public VariableModification createCopy() { - return new LongSubtractModification(subtrahend); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index 650704f..a8fff82 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -30,6 +30,16 @@ public LongXorModification(Long xor) { this.xor = xor; } + public LongXorModification(LongXorModification other) { + super(other); + xor = other.xor; + } + + @Override + public LongXorModification createCopy() { + return new LongXorModification(this); + } + @Override protected Long modifyImplementationHook(Long input) { return input == null ? xor : input ^ xor; @@ -53,11 +63,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new LongXorModification(xor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index dbe1622..9a377ba 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -30,14 +30,14 @@ public ModifiableLong(ModifiableLong other) { } @Override - protected void createRandomModification() { - VariableModification vm = LongModificationFactory.createRandomModification(); - setModification(vm); + public ModifiableLong createCopy() { + return new ModifiableLong(this); } @Override - public ModifiableLong createCopy() { - return new ModifiableLong(this); + protected void createRandomModification() { + VariableModification vm = LongModificationFactory.createRandomModification(); + setModification(vm); } public Long getAssertEquals() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java new file mode 100644 index 0000000..5fcbf31 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -0,0 +1,60 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.string.ModifiableString; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; + +/** */ +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class ModifiablePath extends ModifiableString { + + public ModifiablePath() { + super(); + } + + public ModifiablePath(ModifiablePath other) { + super(other); + } + + @Override + public ModifiablePath createCopy() { + return new ModifiablePath(this); + } + + @Override + protected void createRandomModification() { + VariableModification vm = PathModificationFactory.createRandomModification(null); + setModification(vm); + } + + @Override + public String toString() { + return "ModifiablePath{originalValue=" + backslashEscapeString(originalValue) + "}"; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof ModifiablePath)) { + return false; + } + + ModifiablePath that = (ModifiablePath) obj; + + return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java new file mode 100644 index 0000000..9a106a7 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java @@ -0,0 +1,97 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"appendValue", "modificationFilter"}) +public class PathAppendValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String appendValue; + + public PathAppendValueModification() { + super(); + } + + public PathAppendValueModification(String appendValue) { + super(); + this.appendValue = appendValue; + } + + public PathAppendValueModification(PathAppendValueModification other) { + super(other); + appendValue = other.appendValue; + } + + @Override + public PathAppendValueModification createCopy() { + return new PathAppendValueModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + if (input.endsWith("/")) { + return input + appendValue + "/"; + } + return input + "/" + appendValue; + } + + public String getAppendValue() { + return appendValue; + } + + public void setAppendValue(String appendValue) { + this.appendValue = appendValue; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + int index = r.nextInt(appendValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); + StringBuilder modifiedString = new StringBuilder(appendValue); + modifiedString.setCharAt(index, randomChar); + return new PathAppendValueModification(modifiedString.toString()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + appendValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathAppendValueModification other = (PathAppendValueModification) obj; + return Objects.equals(appendValue, other.appendValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java new file mode 100644 index 0000000..94f222c --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java @@ -0,0 +1,177 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"insertValue", "count", "startPosition", "modificationFilter"}) +public class PathInsertDirectoryTraversalValueModification extends VariableModification { + + private static final int MAX_INSERT_MODIFIER = 32; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String insertValue; + + private int count; + private int startPosition; + + public PathInsertDirectoryTraversalValueModification() { + super(); + } + + public PathInsertDirectoryTraversalValueModification(int count, int startPosition) { + super(); + this.count = count; + this.startPosition = startPosition; + updateInsertValue(); + } + + public PathInsertDirectoryTraversalValueModification( + PathInsertDirectoryTraversalValueModification other) { + super(other); + insertValue = other.insertValue; + count = other.count; + startPosition = other.startPosition; + } + + @Override + public PathInsertDirectoryTraversalValueModification createCopy() { + return new PathInsertDirectoryTraversalValueModification(this); + } + + private void updateInsertValue() { + StringBuilder builder = new StringBuilder(count * 3 - 1); + for (int i = 0; i < count; i++) { + builder.append(".."); + if (i < count - 1) { + builder.append("/"); + } + } + insertValue = builder.toString(); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + + if (input.isEmpty()) { + return insertValue; + } + String[] pathParts = input.split("/"); + boolean leadingSlash = pathParts[0].isEmpty(); + + // Wrap around and also allow to insert at the end of the original value + int insertPosition; + if (leadingSlash) { + // If the path starts with a slash, skip the first empty path part. + insertPosition = startPosition % pathParts.length; + if (startPosition < 0) { + insertPosition += pathParts.length - 1; + } + insertPosition++; + } else { + insertPosition = startPosition % (pathParts.length + 1); + if (startPosition < 0) { + insertPosition += pathParts.length; + } + } + + if (insertPosition == 0 && leadingSlash) { + pathParts[insertPosition] = "/" + insertValue; + } else if (insertPosition == pathParts.length) { + pathParts[insertPosition - 1] = pathParts[insertPosition - 1] + "/" + insertValue; + } else { + pathParts[insertPosition] = insertValue + "/" + pathParts[insertPosition]; + } + if (input.endsWith("/")) { + pathParts[pathParts.length - 1] += "/"; + } + return String.join("/", pathParts); + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + updateInsertValue(); + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = count + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathInsertDirectoryTraversalValueModification(modifier, startPosition); + } else { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathInsertDirectoryTraversalValueModification(count, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + count; + hash = 31 * hash + startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathInsertDirectoryTraversalValueModification other = + (PathInsertDirectoryTraversalValueModification) obj; + if (startPosition != other.startPosition) { + return false; + } + return Objects.equals(count, other.count); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java new file mode 100644 index 0000000..12a694a --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java @@ -0,0 +1,158 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) +public class PathInsertValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + private static final int MAX_INSERT_MODIFIER = 32; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String insertValue; + + private int startPosition; + + public PathInsertValueModification() { + super(); + } + + public PathInsertValueModification(String insertValue, int startPosition) { + super(); + this.insertValue = insertValue; + this.startPosition = startPosition; + } + + public PathInsertValueModification(PathInsertValueModification other) { + super(other); + insertValue = other.insertValue; + startPosition = other.startPosition; + } + + @Override + public PathInsertValueModification createCopy() { + return new PathInsertValueModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + + if (input.isEmpty()) { + return insertValue; + } + String[] pathParts = input.split("/"); + boolean leadingSlash = pathParts[0].isEmpty(); + + // Wrap around and also allow to insert at the end of the original value + int insertPosition; + if (leadingSlash) { + // If the path starts with a slash, skip the first empty path part. + insertPosition = startPosition % pathParts.length; + if (startPosition < 0) { + insertPosition += pathParts.length - 1; + } + insertPosition++; + } else { + insertPosition = startPosition % (pathParts.length + 1); + if (startPosition < 0) { + insertPosition += pathParts.length; + } + } + + if (insertPosition == 0 && leadingSlash) { + pathParts[insertPosition] = "/" + insertValue; + } else if (insertPosition == pathParts.length) { + pathParts[insertPosition - 1] = pathParts[insertPosition - 1] + "/" + insertValue; + } else { + pathParts[insertPosition] = insertValue + "/" + pathParts[insertPosition]; + } + if (input.endsWith("/")) { + pathParts[pathParts.length - 1] += "/"; + } + return String.join("/", pathParts); + } + + public String getInsertValue() { + return insertValue; + } + + public void setInsertValue(String insertValue) { + this.insertValue = insertValue; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int index = r.nextInt(insertValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); + StringBuilder modifiedString = new StringBuilder(insertValue); + modifiedString.setCharAt(index, randomChar); + return new PathInsertValueModification(modifiedString.toString(), startPosition); + } else { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathInsertValueModification(insertValue, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + insertValue.hashCode(); + hash = 31 * hash + startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathInsertValueModification other = (PathInsertValueModification) obj; + if (startPosition != other.startPosition) { + return false; + } + return Objects.equals(insertValue, other.insertValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java new file mode 100644 index 0000000..46f2ead --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java @@ -0,0 +1,88 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.RandomHelper; +import java.util.Random; + +/** */ +public final class PathModificationFactory { + + private PathModificationFactory() { + super(); + } + + private enum ModificationType { + APPEND, + PREPEND, + INSERT + } + + private static final int MODIFICATION_COUNT = ModificationType.values().length; + + private static final int MAX_BYTE_LENGTH_INSERT = 200; + + private static final int MODIFIED_STRING_LENGTH_ESTIMATION = 50; + + public static VariableModification prependValue(String value) { + return new PathPrependValueModification(value); + } + + public static VariableModification appendValue(String value) { + return new PathAppendValueModification(value); + } + + public static VariableModification insertValue(String value, int position) { + return new PathInsertValueModification(value, position); + } + + public static VariableModification createRandomModification(String originalValue) { + Random random = RandomHelper.getRandom(); + ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; + int modificationArrayLength; + int modifiedArrayLength; + if (originalValue == null) { + modifiedArrayLength = MODIFIED_STRING_LENGTH_ESTIMATION; + } else { + modifiedArrayLength = originalValue.length(); + if (modifiedArrayLength == 0 || modifiedArrayLength == 1) { + randomType = ModificationType.APPEND; + } + } + switch (randomType) { + case APPEND: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToAppend = new byte[modificationArrayLength]; + random.nextBytes(bytesToAppend); + return new PathAppendValueModification(new String(bytesToAppend)); + case PREPEND: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToPrepend = new byte[modificationArrayLength]; + random.nextBytes(bytesToPrepend); + return new PathPrependValueModification(new String(bytesToPrepend)); + case INSERT: + modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationArrayLength == 0) { + modificationArrayLength++; + } + byte[] bytesToInsert = new byte[modificationArrayLength]; + random.nextBytes(bytesToInsert); + int insertPosition = random.nextInt(modifiedArrayLength); + return new PathInsertValueModification(new String(bytesToInsert), insertPosition); + default: + throw new IllegalStateException("Unexpected modification type: " + randomType); + } + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java new file mode 100644 index 0000000..fb4efc3 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java @@ -0,0 +1,97 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +/** Modification that prepends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"prependValue", "modificationFilter"}) +public class PathPrependValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String prependValue; + + public PathPrependValueModification() { + super(); + } + + public PathPrependValueModification(String prependValue) { + super(); + this.prependValue = prependValue; + } + + public PathPrependValueModification(PathPrependValueModification other) { + super(other); + prependValue = other.prependValue; + } + + @Override + public PathPrependValueModification createCopy() { + return new PathPrependValueModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + if (input.startsWith("/")) { + return "/" + prependValue + input; + } + return prependValue + "/" + input; + } + + public String getPrependValue() { + return prependValue; + } + + public void setPrependValue(String prependValue) { + this.prependValue = prependValue; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + int index = r.nextInt(prependValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); + StringBuilder modifiedString = new StringBuilder(prependValue); + modifiedString.setCharAt(index, randomChar); + return new PathPrependValueModification(modifiedString.toString()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + prependValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathPrependValueModification other = (PathPrependValueModification) obj; + return Objects.equals(prependValue, other.prependValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java new file mode 100644 index 0000000..ac84f82 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java @@ -0,0 +1,63 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"modificationFilter"}) +public class PathToggleRootValueModification extends VariableModification { + + public PathToggleRootValueModification() { + super(); + } + + public PathToggleRootValueModification(PathToggleRootValueModification other) { + super(other); + } + + @Override + public PathToggleRootValueModification createCopy() { + return new PathToggleRootValueModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + if (!input.isEmpty() && input.charAt(0) == '/') { + return input.substring(1); + } + return "/" + input; + } + + @Override + public VariableModification getModifiedCopy() { + return new PathToggleRootValueModification(); + } + + @Override + public int hashCode() { + return 7; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + return getClass() == obj.getClass(); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index 5448222..b5ce1bc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -30,6 +30,16 @@ public ByteAddModification(Byte summand) { this.summand = summand; } + public ByteAddModification(ByteAddModification other) { + super(other); + summand = other.summand; + } + + @Override + public ByteAddModification createCopy() { + return new ByteAddModification(this); + } + @Override protected Byte modifyImplementationHook(Byte input) { if (input == null) { @@ -51,11 +61,6 @@ public VariableModification getModifiedCopy() { return new ByteAddModification((byte) (summand + new Random().nextInt(MAX_ADD_MODIFIER))); } - @Override - public VariableModification createCopy() { - return new ByteAddModification(summand); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java index 16b208d..b8948fb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java @@ -15,7 +15,7 @@ import java.util.Objects; @XmlRootElement -@XmlType(propOrder = {"index", "explicitValue", "modificationFilter"}) +@XmlType(propOrder = "index") @XmlAccessorType(XmlAccessType.FIELD) public class ByteExplicitValueFromFileModification extends ByteExplicitValueModification { private int index; @@ -29,6 +29,16 @@ public ByteExplicitValueFromFileModification(int index, Byte explicitValue) { this.index = index; } + public ByteExplicitValueFromFileModification(ByteExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public ByteExplicitValueFromFileModification createCopy() { + return new ByteExplicitValueFromFileModification(this); + } + public int getIndex() { return index; } @@ -39,11 +49,6 @@ public VariableModification getModifiedCopy() { "Cannot set modify Value of ByteExplicitValueFromFileModification"); } - @Override - public VariableModification createCopy() { - return new ByteExplicitValueFromFileModification(index, explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 05df3e8..47d2db5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -30,6 +30,16 @@ public ByteExplicitValueModification(Byte explicitValue) { this.explicitValue = explicitValue; } + public ByteExplicitValueModification(ByteExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public ByteExplicitValueModification createCopy() { + return new ByteExplicitValueModification(this); + } + @Override protected Byte modifyImplementationHook(Byte input) { return explicitValue; @@ -55,11 +65,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new ByteExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index fb6627b..834bcc3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -30,6 +30,16 @@ public ByteSubtractModification(Byte subtrahend) { this.subtrahend = subtrahend; } + public ByteSubtractModification(ByteSubtractModification other) { + super(other); + subtrahend = other.subtrahend; + } + + @Override + public ByteSubtractModification createCopy() { + return new ByteSubtractModification(this); + } + @Override protected Byte modifyImplementationHook(Byte input) { if (input == null) { @@ -52,11 +62,6 @@ public VariableModification getModifiedCopy() { (byte) (subtrahend + new Random().nextInt(MAX_SUBTRACT_MODIFIER))); } - @Override - public VariableModification createCopy() { - return new ByteSubtractModification(subtrahend); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index eb47170..19b8aef 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -31,6 +31,16 @@ public ByteXorModification(Byte xor) { this.xor = xor; } + public ByteXorModification(ByteXorModification other) { + super(other); + xor = other.xor; + } + + @Override + public ByteXorModification createCopy() { + return new ByteXorModification(this); + } + @Override protected Byte modifyImplementationHook(Byte input) { if (input == null) { @@ -57,11 +67,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new ByteXorModification(xor); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index 706fc68..3a76bd7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -29,14 +29,14 @@ public ModifiableByte(ModifiableByte other) { } @Override - protected void createRandomModification() { - VariableModification vm = ByteModificationFactory.createRandomModification(); - setModification(vm); + public ModifiableByte createCopy() { + return new ModifiableByte(this); } @Override - public ModifiableByte createCopy() { - return new ModifiableByte(this); + protected void createRandomModification() { + VariableModification vm = ByteModificationFactory.createRandomModification(); + setModification(vm); } public Byte getAssertEquals() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 7fbc8d7..c207b18 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -24,7 +24,7 @@ public class ModifiableString extends ModifiableVariable { @XmlJavaTypeAdapter(IllegalStringAdapter.class) - private String originalValue; + protected String originalValue; public ModifiableString() { super(); @@ -36,14 +36,14 @@ public ModifiableString(ModifiableString other) { } @Override - protected void createRandomModification() { - VariableModification vm = StringModificationFactory.createRandomModification(null); - setModification(vm); + public ModifiableString createCopy() { + return new ModifiableString(this); } @Override - public ModifiableString createCopy() { - return new ModifiableString(this); + protected void createRandomModification() { + VariableModification vm = StringModificationFactory.createRandomModification(null); + setModification(vm); } public String getAssertEquals() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index b485882..3de565f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -34,9 +34,19 @@ public StringAppendValueModification(String appendValue) { this.appendValue = appendValue; } + public StringAppendValueModification(StringAppendValueModification other) { + super(other); + appendValue = other.appendValue; + } + + @Override + public StringAppendValueModification createCopy() { + return new StringAppendValueModification(this); + } + @Override protected String modifyImplementationHook(String input) { - return input + appendValue; + return input != null ? input + appendValue : appendValue; } public String getAppendValue() { @@ -57,11 +67,6 @@ public VariableModification getModifiedCopy() { return new StringAppendValueModification(modifiedString.toString()); } - @Override - public VariableModification createCopy() { - return new StringAppendValueModification(appendValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java new file mode 100644 index 0000000..5d7acd1 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java @@ -0,0 +1,78 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.string; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = "index") +@XmlAccessorType(XmlAccessType.FIELD) +public class StringExplicitValueFromFileModification extends StringExplicitValueModification { + private int index; + + public StringExplicitValueFromFileModification() { + super(); + } + + public StringExplicitValueFromFileModification(int index, String explicitValue) { + super(explicitValue); + this.index = index; + } + + public StringExplicitValueFromFileModification(StringExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public StringExplicitValueFromFileModification createCopy() { + return new StringExplicitValueFromFileModification(this); + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of StringExplicitValueFromFileModification"); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StringExplicitValueFromFileModification other = + (StringExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index 7b564a2..d901fc5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -23,7 +23,7 @@ public class StringExplicitValueModification extends VariableModification getModifiedCopy() { return new StringExplicitValueModification(modifiedString.toString()); } - @Override - public VariableModification createCopy() { - return new StringExplicitValueModification(explicitValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index 367ed4a..ea99f58 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -39,8 +39,22 @@ public StringInsertValueModification(String insertValue, int startPosition) { this.startPosition = startPosition; } + public StringInsertValueModification(StringInsertValueModification other) { + super(other); + insertValue = other.insertValue; + startPosition = other.startPosition; + } + + @Override + public StringInsertValueModification createCopy() { + return new StringInsertValueModification(this); + } + @Override protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } // Wrap around and also allow to insert at the end of the original value int insertPosition = startPosition % (input.length() + 1); if (startPosition < 0) { @@ -89,11 +103,6 @@ public VariableModification getModifiedCopy() { } } - @Override - public VariableModification createCopy() { - return new StringInsertValueModification(insertValue, startPosition); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index 1b5dcf5..93452fe 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -34,9 +34,19 @@ public StringPrependValueModification(String prependValue) { this.prependValue = prependValue; } + public StringPrependValueModification(StringPrependValueModification other) { + super(other); + prependValue = other.prependValue; + } + + @Override + public StringPrependValueModification createCopy() { + return new StringPrependValueModification(this); + } + @Override protected String modifyImplementationHook(String input) { - return prependValue + input; + return input != null ? prependValue + input : prependValue; } public String getPrependValue() { @@ -57,11 +67,6 @@ public VariableModification getModifiedCopy() { return new StringPrependValueModification(modifiedString.toString()); } - @Override - public VariableModification createCopy() { - return new StringPrependValueModification(prependValue); - } - @Override public int hashCode() { int hash = 7; diff --git a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java index 9aeba5c..ec87a84 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/serialization/ByteArraySerializationTest.java @@ -82,7 +82,6 @@ public void testSerializeDeserializeSimple() throws Exception { public void testSerializeDeserializeWithModification() throws Exception { VariableModification modifier = ByteArrayModificationFactory.insertValue(new byte[] {1, 2}, 0); - start.setModification(modifier); m.marshal(start, writer); From 3bb9d9f1f9db990abfb3c7f7194532d1bb66be79 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 4 Dec 2024 19:32:16 +0100 Subject: [PATCH 25/50] Add ModifiablePath utilities and missing XmlElement Annotations --- .../ModifiableVariable.java | 24 +++++-- .../ModifiableVariableFactory.java | 21 ++++++ .../path/ModifiablePath.java | 1 - ...InsertDirectoryTraversalModification.java} | 22 +++--- .../path/PathModificationFactory.java | 72 +++++++++++++------ ...n.java => PathToggleRootModification.java} | 12 ++-- .../modifiablevariable/util/Modifiable.java | 37 ++++++++-- 7 files changed, 140 insertions(+), 49 deletions(-) rename src/main/java/de/rub/nds/modifiablevariable/path/{PathInsertDirectoryTraversalValueModification.java => PathInsertDirectoryTraversalModification.java} (85%) rename src/main/java/de/rub/nds/modifiablevariable/path/{PathToggleRootValueModification.java => PathToggleRootModification.java} (77%) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 29a45a4..0080189 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -13,11 +13,9 @@ import de.rub.nds.modifiablevariable.bytearray.*; import de.rub.nds.modifiablevariable.integer.*; import de.rub.nds.modifiablevariable.longint.*; +import de.rub.nds.modifiablevariable.path.*; import de.rub.nds.modifiablevariable.singlebyte.*; -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 de.rub.nds.modifiablevariable.string.*; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; @@ -156,14 +154,28 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = StringAppendValueModification.class, name = "StringAppendValueModification"), + @XmlElement( + type = StringExplicitValueFromFileModification.class, + name = "StringExplicitValueFromFileModification"), @XmlElement( type = StringExplicitValueModification.class, name = "StringExplicitValueModification"), @XmlElement( type = StringInsertValueModification.class, - name = "StringInsertValueModification") + name = "StringInsertValueModification"), + @XmlElement(type = PathAppendValueModification.class, name = "PathAppendValueModification"), + @XmlElement( + type = PathInsertDirectoryTraversalModification.class, + name = "PathInsertDirectoryTraversalValueModification"), + @XmlElement(type = PathInsertValueModification.class, name = "PathInsertValueModification"), + @XmlElement( + type = PathPrependValueModification.class, + name = "PathPrependValueModification"), + @XmlElement( + type = PathToggleRootModification.class, + name = "PathToggleRootValueModification"), }) - private VariableModification modification = null; + private VariableModification modification; private Boolean createRandomModification; diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java index 4e3e3e9..08fe41b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java @@ -12,6 +12,7 @@ import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray; import de.rub.nds.modifiablevariable.integer.ModifiableInteger; import de.rub.nds.modifiablevariable.longint.ModifiableLong; +import de.rub.nds.modifiablevariable.path.ModifiablePath; import de.rub.nds.modifiablevariable.singlebyte.ModifiableByte; import de.rub.nds.modifiablevariable.string.ModifiableString; import java.math.BigInteger; @@ -38,6 +39,18 @@ public static ModifiableLong createLongModifiableVariable() { return new ModifiableLong(); } + public static ModifiableBoolean createBooleanModifiableVariable() { + return new ModifiableBoolean(); + } + + public static ModifiableString createStringModifiableVariable() { + return new ModifiableString(); + } + + public static ModifiablePath createPathModifiableVariable() { + return new ModifiablePath(); + } + public static ModifiableBigInteger safelySetValue(ModifiableBigInteger mv, BigInteger value) { if (mv == null) { mv = new ModifiableBigInteger(); @@ -94,6 +107,14 @@ public static ModifiableBoolean safelySetValue(ModifiableBoolean mv, Boolean val return mv; } + public static ModifiablePath safelySetValue(ModifiablePath mv, String value) { + if (mv == null) { + mv = new ModifiablePath(); + } + mv.setOriginalValue(value); + return mv; + } + private ModifiableVariableFactory() { super(); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java index 5fcbf31..47e4489 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -15,7 +15,6 @@ import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlRootElement; -/** */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class ModifiablePath extends ModifiableString { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java similarity index 85% rename from src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java rename to src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java index 94f222c..253cd67 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java @@ -18,7 +18,7 @@ /** Modification that appends a string to the original value. */ @XmlRootElement @XmlType(propOrder = {"insertValue", "count", "startPosition", "modificationFilter"}) -public class PathInsertDirectoryTraversalValueModification extends VariableModification { +public class PathInsertDirectoryTraversalModification extends VariableModification { private static final int MAX_INSERT_MODIFIER = 32; @@ -28,19 +28,19 @@ public class PathInsertDirectoryTraversalValueModification extends VariableModif private int count; private int startPosition; - public PathInsertDirectoryTraversalValueModification() { + public PathInsertDirectoryTraversalModification() { super(); } - public PathInsertDirectoryTraversalValueModification(int count, int startPosition) { + public PathInsertDirectoryTraversalModification(int count, int startPosition) { super(); this.count = count; this.startPosition = startPosition; updateInsertValue(); } - public PathInsertDirectoryTraversalValueModification( - PathInsertDirectoryTraversalValueModification other) { + public PathInsertDirectoryTraversalModification( + PathInsertDirectoryTraversalModification other) { super(other); insertValue = other.insertValue; count = other.count; @@ -48,8 +48,8 @@ public PathInsertDirectoryTraversalValueModification( } @Override - public PathInsertDirectoryTraversalValueModification createCopy() { - return new PathInsertDirectoryTraversalValueModification(this); + public PathInsertDirectoryTraversalModification createCopy() { + return new PathInsertDirectoryTraversalModification(this); } private void updateInsertValue() { @@ -134,7 +134,7 @@ public VariableModification getModifiedCopy() { if (modifier <= 0) { modifier = 1; } - return new PathInsertDirectoryTraversalValueModification(modifier, startPosition); + return new PathInsertDirectoryTraversalModification(modifier, startPosition); } else { int modifier = r.nextInt(MAX_INSERT_MODIFIER); if (r.nextBoolean()) { @@ -144,7 +144,7 @@ public VariableModification getModifiedCopy() { if (modifier <= 0) { modifier = 1; } - return new PathInsertDirectoryTraversalValueModification(count, modifier); + return new PathInsertDirectoryTraversalModification(count, modifier); } } @@ -167,8 +167,8 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - PathInsertDirectoryTraversalValueModification other = - (PathInsertDirectoryTraversalValueModification) obj; + PathInsertDirectoryTraversalModification other = + (PathInsertDirectoryTraversalModification) obj; if (startPosition != other.startPosition) { return false; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java index 46f2ead..267cacd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java @@ -21,14 +21,18 @@ private PathModificationFactory() { private enum ModificationType { APPEND, PREPEND, - INSERT + INSERT, + INSERT_DIRECTORY_TRAVERSAL, + TOGGLE_ROOT, } private static final int MODIFICATION_COUNT = ModificationType.values().length; private static final int MAX_BYTE_LENGTH_INSERT = 200; - private static final int MODIFIED_STRING_LENGTH_ESTIMATION = 50; + private static final int NUMBER_OF_PATH_PARTS_ESTIMATION = 50; + + private static final int MAX_NUMBER_OF_DIRECTORY_TRAVERSAL_INSERT = 10; public static VariableModification prependValue(String value) { return new PathPrependValueModification(value); @@ -42,45 +46,71 @@ public static VariableModification insertValue(String value, int positio return new PathInsertValueModification(value, position); } + public static VariableModification insertDirectoryTraversal(int count, int position) { + return new PathInsertDirectoryTraversalModification(count, position); + } + + public static VariableModification toggleRoot() { + return new PathToggleRootModification(); + } + public static VariableModification createRandomModification(String originalValue) { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; - int modificationArrayLength; - int modifiedArrayLength; + int modificationStringLength; + int numberOfPathParts; if (originalValue == null) { - modifiedArrayLength = MODIFIED_STRING_LENGTH_ESTIMATION; + numberOfPathParts = NUMBER_OF_PATH_PARTS_ESTIMATION; } else { - modifiedArrayLength = originalValue.length(); - if (modifiedArrayLength == 0 || modifiedArrayLength == 1) { - randomType = ModificationType.APPEND; + String[] pathParts = originalValue.split("/"); + if (pathParts.length == 0) { + if (randomType == ModificationType.INSERT) { + randomType = ModificationType.APPEND; + } + numberOfPathParts = 0; + } else { + if (pathParts[0].isEmpty()) { + numberOfPathParts = originalValue.split("/").length - 1; + } else { + numberOfPathParts = originalValue.split("/").length; + } } } + int insertPosition; switch (randomType) { case APPEND: - modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); - if (modificationArrayLength == 0) { - modificationArrayLength++; + modificationStringLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationStringLength == 0) { + modificationStringLength++; } - byte[] bytesToAppend = new byte[modificationArrayLength]; + byte[] bytesToAppend = new byte[modificationStringLength]; random.nextBytes(bytesToAppend); return new PathAppendValueModification(new String(bytesToAppend)); case PREPEND: - modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); - if (modificationArrayLength == 0) { - modificationArrayLength++; + modificationStringLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationStringLength == 0) { + modificationStringLength++; } - byte[] bytesToPrepend = new byte[modificationArrayLength]; + byte[] bytesToPrepend = new byte[modificationStringLength]; random.nextBytes(bytesToPrepend); return new PathPrependValueModification(new String(bytesToPrepend)); case INSERT: - modificationArrayLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); - if (modificationArrayLength == 0) { - modificationArrayLength++; + modificationStringLength = random.nextInt(MAX_BYTE_LENGTH_INSERT); + if (modificationStringLength == 0) { + modificationStringLength++; } - byte[] bytesToInsert = new byte[modificationArrayLength]; + byte[] bytesToInsert = new byte[modificationStringLength]; random.nextBytes(bytesToInsert); - int insertPosition = random.nextInt(modifiedArrayLength); + insertPosition = random.nextInt(numberOfPathParts); return new PathInsertValueModification(new String(bytesToInsert), insertPosition); + case INSERT_DIRECTORY_TRAVERSAL: + int numberOfDirectoryTraversal = + random.nextInt(MAX_NUMBER_OF_DIRECTORY_TRAVERSAL_INSERT); + insertPosition = random.nextInt(numberOfPathParts); + return new PathInsertDirectoryTraversalModification( + numberOfDirectoryTraversal, insertPosition); + case TOGGLE_ROOT: + return new PathToggleRootModification(); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java similarity index 77% rename from src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java rename to src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java index ac84f82..ea06e1d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java @@ -14,19 +14,19 @@ /** Modification that appends a string to the original value. */ @XmlRootElement @XmlType(propOrder = {"modificationFilter"}) -public class PathToggleRootValueModification extends VariableModification { +public class PathToggleRootModification extends VariableModification { - public PathToggleRootValueModification() { + public PathToggleRootModification() { super(); } - public PathToggleRootValueModification(PathToggleRootValueModification other) { + public PathToggleRootModification(PathToggleRootModification other) { super(other); } @Override - public PathToggleRootValueModification createCopy() { - return new PathToggleRootValueModification(this); + public PathToggleRootModification createCopy() { + return new PathToggleRootModification(this); } @Override @@ -42,7 +42,7 @@ protected String modifyImplementationHook(String input) { @Override public VariableModification getModifiedCopy() { - return new PathToggleRootValueModification(); + return new PathToggleRootModification(); } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index d883b46..6db0364 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -10,8 +10,7 @@ import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.biginteger.BigIntegerModificationFactory; import de.rub.nds.modifiablevariable.biginteger.ModifiableBigInteger; -import de.rub.nds.modifiablevariable.bool.BooleanExplicitValueModification; -import de.rub.nds.modifiablevariable.bool.BooleanToggleModification; +import de.rub.nds.modifiablevariable.bool.BooleanModificationFactory; import de.rub.nds.modifiablevariable.bool.ModifiableBoolean; import de.rub.nds.modifiablevariable.bytearray.ByteArrayModificationFactory; import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray; @@ -19,6 +18,8 @@ import de.rub.nds.modifiablevariable.integer.ModifiableInteger; import de.rub.nds.modifiablevariable.longint.LongModificationFactory; import de.rub.nds.modifiablevariable.longint.ModifiableLong; +import de.rub.nds.modifiablevariable.path.ModifiablePath; +import de.rub.nds.modifiablevariable.path.PathModificationFactory; import de.rub.nds.modifiablevariable.singlebyte.ByteModificationFactory; import de.rub.nds.modifiablevariable.singlebyte.ModifiableByte; import de.rub.nds.modifiablevariable.string.ModifiableString; @@ -81,6 +82,13 @@ private static ModifiableString getModifiableStringWithModification( return modifiableString; } + private static ModifiablePath getModifiablePathWithModification( + VariableModification modification) { + ModifiablePath modifiablePath = new ModifiablePath(); + modifiablePath.setModification(modification); + return modifiablePath; + } + public static ModifiableBigInteger prepend(BigInteger i) { return getModifiableBigIntegerWithModification( BigIntegerModificationFactory.prependValue(i)); @@ -102,6 +110,10 @@ public static ModifiableString prepend(String s) { return getModifiableStringWithModification(StringModificationFactory.prependValue(s)); } + public static ModifiablePath prependPath(String s) { + return getModifiablePathWithModification(PathModificationFactory.prependValue(s)); + } + public static ModifiableBigInteger append(BigInteger i) { return getModifiableBigIntegerWithModification( BigIntegerModificationFactory.appendValue(i)); @@ -123,6 +135,10 @@ public static ModifiableString append(String s) { return getModifiableStringWithModification(StringModificationFactory.appendValue(s)); } + public static ModifiablePath appendPath(String s) { + return getModifiablePathWithModification(PathModificationFactory.appendValue(s)); + } + public static ModifiableByteArray explicit(byte[] b) { return getModifiableByteArrayWithModification( ByteArrayModificationFactory.explicitValue(b)); @@ -146,7 +162,7 @@ public static ModifiableLong explicit(Long l) { } public static ModifiableBoolean explicit(Boolean b) { - return getModifiableBooleanWithModification(new BooleanExplicitValueModification(b)); + return getModifiableBooleanWithModification(BooleanModificationFactory.explicitValue(b)); } public static ModifiableString explicit(String s) { @@ -177,6 +193,15 @@ public static ModifiableString insert(String s, int position) { StringModificationFactory.insertValue(s, position)); } + public static ModifiablePath insertPath(String s, int position) { + return getModifiablePathWithModification(PathModificationFactory.insertValue(s, position)); + } + + public static ModifiablePath insertDirectoryTraversal(int count, int position) { + return getModifiablePathWithModification( + PathModificationFactory.insertDirectoryTraversal(count, position)); + } + public static ModifiableByteArray xor(byte[] b, int position) { return getModifiableByteArrayWithModification( ByteArrayModificationFactory.xor(b, position)); @@ -245,7 +270,11 @@ public static ModifiableByteArray duplicate() { } public static ModifiableBoolean toggle() { - return getModifiableBooleanWithModification(new BooleanToggleModification()); + return getModifiableBooleanWithModification(BooleanModificationFactory.toggle()); + } + + public static ModifiablePath toggleRoot() { + return getModifiablePathWithModification(PathModificationFactory.toggleRoot()); } public static ModifiableBigInteger shiftLeftBigInteger(Integer i) { From 753aa9dc1344514f405e4226651de3c6ed7d8657 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 4 Dec 2024 19:40:11 +0100 Subject: [PATCH 26/50] run formatter --- .../de/rub/nds/modifiablevariable/ModifiableVariable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 0080189..a88741e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -155,8 +155,8 @@ public abstract class ModifiableVariable implements Serializable { type = StringAppendValueModification.class, name = "StringAppendValueModification"), @XmlElement( - type = StringExplicitValueFromFileModification.class, - name = "StringExplicitValueFromFileModification"), + type = StringExplicitValueFromFileModification.class, + name = "StringExplicitValueFromFileModification"), @XmlElement( type = StringExplicitValueModification.class, name = "StringExplicitValueModification"), From 6566fb94292ae0ef9f702e4fc72698474203eb14 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 5 Dec 2024 15:25:05 +0100 Subject: [PATCH 27/50] Add PathInsertDirectorySeparatorModification --- .../ModifiableVariable.java | 3 + ...hInsertDirectorySeparatorModification.java | 134 ++++++++++++++++++ ...hInsertDirectoryTraversalModification.java | 38 +---- .../path/PathInsertValueModification.java | 38 +---- .../path/PathModificationFactory.java | 12 ++ .../nds/modifiablevariable/path/PathUtil.java | 62 ++++++++ .../modifiablevariable/util/Modifiable.java | 5 + 7 files changed, 218 insertions(+), 74 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index a88741e..77d59ac 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -164,6 +164,9 @@ public abstract class ModifiableVariable implements Serializable { type = StringInsertValueModification.class, name = "StringInsertValueModification"), @XmlElement(type = PathAppendValueModification.class, name = "PathAppendValueModification"), + @XmlElement( + type = PathInsertDirectorySeparatorModification.class, + name = "PathInsertDirectorySeparatorModification"), @XmlElement( type = PathInsertDirectoryTraversalModification.class, name = "PathInsertDirectoryTraversalValueModification"), diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java new file mode 100644 index 0000000..77741bf --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java @@ -0,0 +1,134 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +/** Modification that appends a string to the original value. */ +@XmlRootElement +@XmlType(propOrder = {"insertValue", "count", "startPosition", "modificationFilter"}) +public class PathInsertDirectorySeparatorModification extends VariableModification { + + private static final int MAX_INSERT_MODIFIER = 32; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + private String insertValue; + + private int count; + private int startPosition; + + public PathInsertDirectorySeparatorModification() { + super(); + } + + public PathInsertDirectorySeparatorModification(int count, int startPosition) { + super(); + this.count = count; + this.startPosition = startPosition; + updateInsertValue(); + } + + public PathInsertDirectorySeparatorModification( + PathInsertDirectorySeparatorModification other) { + super(other); + insertValue = other.insertValue; + count = other.count; + startPosition = other.startPosition; + } + + @Override + public PathInsertDirectorySeparatorModification createCopy() { + return new PathInsertDirectorySeparatorModification(this); + } + + private void updateInsertValue() { + insertValue = "/".repeat(Math.max(0, count)); + } + + @Override + protected String modifyImplementationHook(String input) { + return PathUtil.insertValueAsPathPart(input, insertValue, startPosition); + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + updateInsertValue(); + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = count + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathInsertDirectorySeparatorModification(modifier, startPosition); + } else { + int modifier = r.nextInt(MAX_INSERT_MODIFIER); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathInsertDirectorySeparatorModification(count, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + count; + hash = 31 * hash + startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathInsertDirectorySeparatorModification other = + (PathInsertDirectorySeparatorModification) obj; + if (startPosition != other.startPosition) { + return false; + } + return Objects.equals(count, other.count); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java index 253cd67..4506bc3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java @@ -65,43 +65,7 @@ private void updateInsertValue() { @Override protected String modifyImplementationHook(String input) { - if (input == null) { - return null; - } - - if (input.isEmpty()) { - return insertValue; - } - String[] pathParts = input.split("/"); - boolean leadingSlash = pathParts[0].isEmpty(); - - // Wrap around and also allow to insert at the end of the original value - int insertPosition; - if (leadingSlash) { - // If the path starts with a slash, skip the first empty path part. - insertPosition = startPosition % pathParts.length; - if (startPosition < 0) { - insertPosition += pathParts.length - 1; - } - insertPosition++; - } else { - insertPosition = startPosition % (pathParts.length + 1); - if (startPosition < 0) { - insertPosition += pathParts.length; - } - } - - if (insertPosition == 0 && leadingSlash) { - pathParts[insertPosition] = "/" + insertValue; - } else if (insertPosition == pathParts.length) { - pathParts[insertPosition - 1] = pathParts[insertPosition - 1] + "/" + insertValue; - } else { - pathParts[insertPosition] = insertValue + "/" + pathParts[insertPosition]; - } - if (input.endsWith("/")) { - pathParts[pathParts.length - 1] += "/"; - } - return String.join("/", pathParts); + return PathUtil.insertValueAsPathPart(input, insertValue, startPosition); } public int getCount() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java index 12a694a..b391b40 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java @@ -52,43 +52,7 @@ public PathInsertValueModification createCopy() { @Override protected String modifyImplementationHook(String input) { - if (input == null) { - return null; - } - - if (input.isEmpty()) { - return insertValue; - } - String[] pathParts = input.split("/"); - boolean leadingSlash = pathParts[0].isEmpty(); - - // Wrap around and also allow to insert at the end of the original value - int insertPosition; - if (leadingSlash) { - // If the path starts with a slash, skip the first empty path part. - insertPosition = startPosition % pathParts.length; - if (startPosition < 0) { - insertPosition += pathParts.length - 1; - } - insertPosition++; - } else { - insertPosition = startPosition % (pathParts.length + 1); - if (startPosition < 0) { - insertPosition += pathParts.length; - } - } - - if (insertPosition == 0 && leadingSlash) { - pathParts[insertPosition] = "/" + insertValue; - } else if (insertPosition == pathParts.length) { - pathParts[insertPosition - 1] = pathParts[insertPosition - 1] + "/" + insertValue; - } else { - pathParts[insertPosition] = insertValue + "/" + pathParts[insertPosition]; - } - if (input.endsWith("/")) { - pathParts[pathParts.length - 1] += "/"; - } - return String.join("/", pathParts); + return PathUtil.insertValueAsPathPart(input, insertValue, startPosition); } public String getInsertValue() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java index 267cacd..b1e6d37 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java @@ -23,6 +23,7 @@ private enum ModificationType { PREPEND, INSERT, INSERT_DIRECTORY_TRAVERSAL, + INSERT_DIRECTORY_SEPERATOR, TOGGLE_ROOT, } @@ -33,6 +34,7 @@ private enum ModificationType { private static final int NUMBER_OF_PATH_PARTS_ESTIMATION = 50; private static final int MAX_NUMBER_OF_DIRECTORY_TRAVERSAL_INSERT = 10; + private static final int MAX_NUMBER_OF_DIRECTORY_SEPERATOR_INSERT = 10; public static VariableModification prependValue(String value) { return new PathPrependValueModification(value); @@ -50,6 +52,10 @@ public static VariableModification insertDirectoryTraversal(int count, i return new PathInsertDirectoryTraversalModification(count, position); } + public static VariableModification insertDirectorySeperator(int count, int position) { + return new PathInsertDirectorySeparatorModification(count, position); + } + public static VariableModification toggleRoot() { return new PathToggleRootModification(); } @@ -109,6 +115,12 @@ public static VariableModification createRandomModification(String origi insertPosition = random.nextInt(numberOfPathParts); return new PathInsertDirectoryTraversalModification( numberOfDirectoryTraversal, insertPosition); + case INSERT_DIRECTORY_SEPERATOR: + int numberOfDirectorySeperator = + random.nextInt(MAX_NUMBER_OF_DIRECTORY_SEPERATOR_INSERT); + insertPosition = random.nextInt(numberOfPathParts); + return new PathInsertDirectorySeparatorModification( + numberOfDirectorySeperator, insertPosition); case TOGGLE_ROOT: return new PathToggleRootModification(); default: diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java new file mode 100644 index 0000000..b4154de --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java @@ -0,0 +1,62 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +public final class PathUtil { + + private PathUtil() { + super(); + } + + public static String insertValueAsPathPart( + String input, String insertValue, int startPosition) { + if (input == null) { + return null; + } + + if (input.isEmpty()) { + return insertValue; + } + String[] pathParts = input.split("/"); + boolean leadingSlash = pathParts[0].isEmpty(); + + // Wrap around and also allow to insert at the end of the original value + int insertPosition = getInsertPosition(startPosition, leadingSlash, pathParts); + + if (insertPosition == 0 && leadingSlash) { + pathParts[insertPosition] = "/" + insertValue; + } else if (insertPosition == pathParts.length) { + pathParts[insertPosition - 1] = pathParts[insertPosition - 1] + "/" + insertValue; + } else { + pathParts[insertPosition] = insertValue + "/" + pathParts[insertPosition]; + } + if (input.endsWith("/")) { + pathParts[pathParts.length - 1] += "/"; + } + return String.join("/", pathParts); + } + + private static int getInsertPosition( + int startPosition, boolean leadingSlash, String[] pathParts) { + int insertPosition; + if (leadingSlash) { + // If the path starts with a slash, skip the first empty path part. + insertPosition = startPosition % pathParts.length; + if (startPosition < 0) { + insertPosition += pathParts.length - 1; + } + insertPosition++; + } else { + insertPosition = startPosition % (pathParts.length + 1); + if (startPosition < 0) { + insertPosition += pathParts.length; + } + } + return insertPosition; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index 6db0364..a950732 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -202,6 +202,11 @@ public static ModifiablePath insertDirectoryTraversal(int count, int position) { PathModificationFactory.insertDirectoryTraversal(count, position)); } + public static ModifiablePath insertDirectorySeperator(int count, int position) { + return getModifiablePathWithModification( + PathModificationFactory.insertDirectorySeperator(count, position)); + } + public static ModifiableByteArray xor(byte[] b, int position) { return getModifiableByteArrayWithModification( ByteArrayModificationFactory.xor(b, position)); From 95bb1ec4bd14ae2cfbc9ed7116464ecbec03fd4a Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 5 Dec 2024 15:27:55 +0100 Subject: [PATCH 28/50] Fix some comments --- .../modifiablevariable/path/PathAppendValueModification.java | 2 +- .../path/PathInsertDirectorySeparatorModification.java | 2 +- .../path/PathInsertDirectoryTraversalModification.java | 2 +- .../modifiablevariable/path/PathInsertValueModification.java | 2 +- .../nds/modifiablevariable/path/PathToggleRootModification.java | 2 +- .../string/StringInsertValueModification.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java index 9a106a7..67cf917 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java @@ -15,7 +15,7 @@ import java.util.Objects; import java.util.Random; -/** Modification that appends a string to the original value. */ +/** Modification that appends a path parts to the original value. */ @XmlRootElement @XmlType(propOrder = {"appendValue", "modificationFilter"}) public class PathAppendValueModification extends VariableModification { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java index 77741bf..2235ff5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java @@ -15,7 +15,7 @@ import java.util.Objects; import java.util.Random; -/** Modification that appends a string to the original value. */ +/** Modification that inserts directory separators as path parts to the original value. */ @XmlRootElement @XmlType(propOrder = {"insertValue", "count", "startPosition", "modificationFilter"}) public class PathInsertDirectorySeparatorModification extends VariableModification { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java index 4506bc3..1ee351e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java @@ -15,7 +15,7 @@ import java.util.Objects; import java.util.Random; -/** Modification that appends a string to the original value. */ +/** Modification that directory traversal path parts the original value. */ @XmlRootElement @XmlType(propOrder = {"insertValue", "count", "startPosition", "modificationFilter"}) public class PathInsertDirectoryTraversalModification extends VariableModification { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java index b391b40..620c747 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java @@ -15,7 +15,7 @@ import java.util.Objects; import java.util.Random; -/** Modification that appends a string to the original value. */ +/** Modification that inserts path parts to the original value. */ @XmlRootElement @XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) public class PathInsertValueModification extends VariableModification { diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java index ea06e1d..6847934 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java @@ -11,7 +11,7 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; -/** Modification that appends a string to the original value. */ +/** Modification that toggle the root slash of the original value. */ @XmlRootElement @XmlType(propOrder = {"modificationFilter"}) public class PathToggleRootModification extends VariableModification { diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index ea99f58..8009d55 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -15,7 +15,7 @@ import java.util.Objects; import java.util.Random; -/** Modification that appends a string to the original value. */ +/** Modification that inserts a string to the original value. */ @XmlRootElement @XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) public class StringInsertValueModification extends VariableModification { From 4ded76cdbd6d62740cdd722189654624644503c0 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 5 Dec 2024 16:23:06 +0100 Subject: [PATCH 29/50] Add PathExplicitValueModification and PathExplicitValueFromFileModification --- .../ModifiableVariable.java | 6 ++ ...PathExplicitValueFromFileModification.java | 77 +++++++++++++++ .../path/PathExplicitValueModification.java | 93 +++++++++++++++++++ .../path/PathModificationFactory.java | 4 + 4 files changed, 180 insertions(+) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 77d59ac..bc2afa0 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -163,6 +163,12 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = StringInsertValueModification.class, name = "StringInsertValueModification"), + @XmlElement( + type = PathExplicitValueFromFileModification.class, + name = "PathExplicitValueFromFileModification"), + @XmlElement( + type = PathExplicitValueModification.class, + name = "PathExplicitValueModification"), @XmlElement(type = PathAppendValueModification.class, name = "PathAppendValueModification"), @XmlElement( type = PathInsertDirectorySeparatorModification.class, diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java new file mode 100644 index 0000000..34f445d --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java @@ -0,0 +1,77 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlAccessType; +import jakarta.xml.bind.annotation.XmlAccessorType; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; + +@XmlRootElement +@XmlType(propOrder = "index") +@XmlAccessorType(XmlAccessType.FIELD) +public class PathExplicitValueFromFileModification extends PathExplicitValueModification { + private int index; + + public PathExplicitValueFromFileModification() { + super(); + } + + public PathExplicitValueFromFileModification(int index, String explicitValue) { + super(explicitValue); + this.index = index; + } + + public PathExplicitValueFromFileModification(PathExplicitValueFromFileModification other) { + super(other); + index = other.index; + } + + @Override + public PathExplicitValueFromFileModification createCopy() { + return new PathExplicitValueFromFileModification(this); + } + + public int getIndex() { + return index; + } + + @Override + public VariableModification getModifiedCopy() { + throw new UnsupportedOperationException( + "Cannot set modify Value of PathExplicitValueFromFileModification"); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + index; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathExplicitValueFromFileModification other = (PathExplicitValueFromFileModification) obj; + if (index != other.index) { + return false; + } + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java new file mode 100644 index 0000000..01d4f04 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java @@ -0,0 +1,93 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import jakarta.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.Objects; +import java.util.Random; + +@XmlRootElement +@XmlType(propOrder = {"explicitValue", "modificationFilter"}) +public class PathExplicitValueModification extends VariableModification { + + private static final int MAX_EXPLICIT_VALUE = 256; + + @XmlJavaTypeAdapter(IllegalStringAdapter.class) + protected String explicitValue; + + public PathExplicitValueModification() { + super(); + } + + public PathExplicitValueModification(String explicitValue) { + super(); + this.explicitValue = explicitValue; + } + + public PathExplicitValueModification(PathExplicitValueModification other) { + super(other); + explicitValue = other.explicitValue; + } + + @Override + public PathExplicitValueModification createCopy() { + return new PathExplicitValueModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + return explicitValue; + } + + public String getExplicitValue() { + return explicitValue; + } + + public void setExplicitValue(String explicitValue) { + this.explicitValue = explicitValue; + } + + @Override + public VariableModification getModifiedCopy() { + if (explicitValue.isEmpty()) { + return this; + } + Random r = new Random(); + int index = r.nextInt(explicitValue.length()); + char randomChar = (char) r.nextInt(MAX_EXPLICIT_VALUE); + StringBuilder modifiedString = new StringBuilder(explicitValue); + modifiedString.setCharAt(index, randomChar); + return new PathExplicitValueModification(modifiedString.toString()); + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + explicitValue.hashCode(); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathExplicitValueModification other = (PathExplicitValueModification) obj; + return Objects.equals(explicitValue, other.explicitValue); + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java index b1e6d37..bd86f8b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java @@ -40,6 +40,10 @@ public static VariableModification prependValue(String value) { return new PathPrependValueModification(value); } + public static VariableModification explicitValue(String value) { + return new PathExplicitValueModification(value); + } + public static VariableModification appendValue(String value) { return new PathAppendValueModification(value); } From f9b1a010597f33c770b28553e220d3b124cf3d32 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 5 Dec 2024 17:11:17 +0100 Subject: [PATCH 30/50] Be kind to negative and null count in PathInsertDirectoryTraversalModification --- .../path/PathInsertDirectoryTraversalModification.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java index 1ee351e..8df1104 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java @@ -53,6 +53,10 @@ public PathInsertDirectoryTraversalModification createCopy() { } private void updateInsertValue() { + if (count <= 0) { + insertValue = ""; + return; + } StringBuilder builder = new StringBuilder(count * 3 - 1); for (int i = 0; i < count; i++) { builder.append(".."); From 73094349815e2fd64dbad5a939e9ac1726ec64b9 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 11:59:11 +0100 Subject: [PATCH 31/50] Add some toString() methods. Change backslashEscapeString() to return null if the value is null. --- .../biginteger/BigIntegerAddModification.java | 5 ++++ .../BigIntegerAppendValueModification.java | 5 ++++ ...egerExplicitValueFromFileModification.java | 10 ++++++++ .../BigIntegerExplicitValueModification.java | 5 ++++ .../BigIntegerInsertValueModification.java | 10 ++++++++ .../BigIntegerMultiplyModification.java | 5 ++++ .../BigIntegerPrependValueModification.java | 5 ++++ .../BigIntegerShiftLeftModification.java | 5 ++++ .../BigIntegerShiftRightModification.java | 5 ++++ .../BigIntegerSubtractModification.java | 5 ++++ .../biginteger/BigIntegerXorModification.java | 5 ++++ ...rrayExplicitValueFromFileModification.java | 11 +++++++++ .../ByteArrayPrependValueModification.java | 2 +- .../bytearray/ModifiableByteArray.java | 23 +++++++------------ .../integer/IntegerAddModification.java | 5 ++++ .../IntegerAppendValueModification.java | 5 ++++ ...egerExplicitValueFromFileModification.java | 10 ++++++++ .../IntegerExplicitValueModification.java | 5 ++++ .../IntegerInsertValueModification.java | 10 ++++++++ .../integer/IntegerMultiplyModification.java | 5 ++++ .../IntegerPrependValueModification.java | 5 ++++ .../integer/IntegerShiftLeftModification.java | 5 ++++ .../IntegerShiftRightModification.java | 5 ++++ .../integer/IntegerSubtractModification.java | 5 ++++ .../integer/IntegerXorModification.java | 5 ++++ .../longint/LongAddModification.java | 5 ++++ .../longint/LongAppendValueModification.java | 5 ++++ ...LongExplicitValueFromFileModification.java | 10 ++++++++ .../LongExplicitValueModification.java | 5 ++++ .../longint/LongInsertValueModification.java | 10 ++++++++ .../longint/LongMultiplyModification.java | 5 ++++ .../longint/LongPrependValueModification.java | 5 ++++ .../longint/LongShiftLeftModification.java | 5 ++++ .../longint/LongShiftRightModification.java | 5 ++++ .../longint/LongSubtractModification.java | 5 ++++ .../longint/LongXorModification.java | 5 ++++ .../path/ModifiablePath.java | 6 ++++- .../path/PathAppendValueModification.java | 11 +++++++++ ...PathExplicitValueFromFileModification.java | 12 ++++++++++ .../path/PathExplicitValueModification.java | 11 +++++++++ ...hInsertDirectorySeparatorModification.java | 13 +++++++++++ ...hInsertDirectoryTraversalModification.java | 13 +++++++++++ .../path/PathInsertValueModification.java | 13 +++++++++++ .../path/PathPrependValueModification.java | 11 +++++++++ .../path/PathToggleRootModification.java | 5 ++++ .../singlebyte/ByteAddModification.java | 5 ++++ ...ByteExplicitValueFromFileModification.java | 10 ++++++++ .../ByteExplicitValueModification.java | 5 ++++ .../singlebyte/ByteSubtractModification.java | 5 ++++ .../singlebyte/ByteXorModification.java | 5 ++++ .../string/ModifiableString.java | 6 ++++- .../string/StringAppendValueModification.java | 11 +++++++++ ...ringExplicitValueFromFileModification.java | 13 +++++++++++ .../StringExplicitValueModification.java | 11 +++++++++ .../string/StringInsertValueModification.java | 13 +++++++++++ .../StringPrependValueModification.java | 11 +++++++++ .../modifiablevariable/util/StringUtil.java | 3 +++ 57 files changed, 406 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java index 7fbbdde..8e5e44d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAddModification.java @@ -84,4 +84,9 @@ public boolean equals(Object obj) { BigIntegerAddModification other = (BigIntegerAddModification) obj; return Objects.equals(summand, other.summand); } + + @Override + public String toString() { + return "BigIntegerAddModification{" + "summand=" + summand + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java index 15068f5..0e7b70e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java @@ -87,4 +87,9 @@ public boolean equals(Object obj) { BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj; return Objects.equals(appendValue, other.appendValue); } + + @Override + public String toString() { + return "BigIntegerAppendValueModification{" + "appendValue=" + appendValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java index ae7eba2..3cfe18b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueFromFileModification.java @@ -78,4 +78,14 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "BigIntegerExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + explicitValue + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index d3694ae..3150a89 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -90,4 +90,9 @@ public boolean equals(Object obj) { BigIntegerExplicitValueModification other = (BigIntegerExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "BigIntegerExplicitValueModification{" + "explicitValue=" + explicitValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java index d088685..007f9f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java @@ -133,4 +133,14 @@ public boolean equals(Object obj) { } return Objects.equals(insertValue, other.insertValue); } + + @Override + public String toString() { + return "BigIntegerInsertValueModification{" + + "insertValue=" + + insertValue + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java index 9569280..93a732e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerMultiplyModification.java @@ -84,4 +84,9 @@ public boolean equals(Object obj) { BigIntegerMultiplyModification other = (BigIntegerMultiplyModification) obj; return Objects.equals(factor, other.factor); } + + @Override + public String toString() { + return "BigIntegerMultiplyModification{" + "factor=" + factor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java index 7bc86e7..d9e2fe1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerPrependValueModification.java @@ -87,4 +87,9 @@ public boolean equals(Object obj) { BigIntegerPrependValueModification other = (BigIntegerPrependValueModification) obj; return Objects.equals(prependValue, other.prependValue); } + + @Override + public String toString() { + return "BigIntegerPrependValueModification{" + "prependValue=" + prependValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java index 1509533..77a9295 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftLeftModification.java @@ -85,4 +85,9 @@ public boolean equals(Object obj) { BigIntegerShiftLeftModification other = (BigIntegerShiftLeftModification) obj; return shift == other.shift; } + + @Override + public String toString() { + return "BigIntegerShiftLeftModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java index 0e59888..0d14237 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerShiftRightModification.java @@ -85,4 +85,9 @@ public boolean equals(Object obj) { BigIntegerShiftRightModification other = (BigIntegerShiftRightModification) obj; return shift == other.shift; } + + @Override + public String toString() { + return "BigIntegerShiftRightModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java index f8fce93..f07e4fb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerSubtractModification.java @@ -87,4 +87,9 @@ public boolean equals(Object obj) { BigIntegerSubtractModification other = (BigIntegerSubtractModification) obj; return Objects.equals(subtrahend, other.subtrahend); } + + @Override + public String toString() { + return "BigIntegerSubtractModification{" + "subtrahend=" + subtrahend + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java index 5cbc9bb..c3d6775 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerXorModification.java @@ -86,4 +86,9 @@ public boolean equals(Object obj) { BigIntegerXorModification other = (BigIntegerXorModification) obj; return Objects.equals(xor, other.xor); } + + @Override + public String toString() { + return "BigIntegerXorModification{" + "xor=" + xor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java index e95a9e3..f303e92 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayExplicitValueFromFileModification.java @@ -8,6 +8,7 @@ package de.rub.nds.modifiablevariable.bytearray; import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.ArrayConverter; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlRootElement; @@ -76,4 +77,14 @@ public boolean equals(Object obj) { } return Arrays.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "ByteArrayExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + ArrayConverter.bytesToHexString(explicitValue) + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java index 17e8135..7399d6e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayPrependValueModification.java @@ -98,7 +98,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return "ByteArrayInsertModification{bytesToPrepend=" + return "ByteArrayPrependValueModification{bytesToPrepend=" + ArrayConverter.bytesToHexString(bytesToPrepend) + "}"; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index 3bd16da..2973f82 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -81,21 +81,6 @@ public boolean validateAssertions() { return valid; } - @Override - public String toString() { - StringBuilder result = new StringBuilder(); - if (isOriginalValueModified()) { - result.append("Actual byte value is: "); - result.append(ArrayConverter.bytesToHexString(this)); - result.append("\nOriginal value was: "); - result.append(ArrayConverter.bytesToHexString(getOriginalValue())); - } else { - result.append("Original byte value is: "); - result.append(ArrayConverter.bytesToHexString(getOriginalValue())); - } - return result.toString(); - } - @Override public boolean equals(Object obj) { if (this == obj) { @@ -116,4 +101,12 @@ public int hashCode() { result = 31 * result + Arrays.hashCode(getValue()); return result; } + + @Override + public String toString() { + return "ModifiableByteArray{" + + "originalValue=" + + ArrayConverter.bytesToHexString(originalValue) + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java index f7f698f..d0e24a6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAddModification.java @@ -79,4 +79,9 @@ public boolean equals(Object obj) { IntegerAddModification other = (IntegerAddModification) obj; return Objects.equals(summand, other.summand); } + + @Override + public String toString() { + return "IntegerAddModification{" + "summand=" + summand + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java index 3cbafa1..1f4729a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerAppendValueModification.java @@ -83,4 +83,9 @@ public boolean equals(Object obj) { IntegerAppendValueModification other = (IntegerAppendValueModification) obj; return Objects.equals(appendValue, other.appendValue); } + + @Override + public String toString() { + return "IntegerAppendValueModification{" + "appendValue=" + appendValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java index 488875a..f8affae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueFromFileModification.java @@ -76,4 +76,14 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "IntegerExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + explicitValue + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java index 26ec5ea..10d5e6f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerExplicitValueModification.java @@ -86,4 +86,9 @@ public boolean equals(Object obj) { IntegerExplicitValueModification other = (IntegerExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "IntegerExplicitValueModification{" + "explicitValue=" + explicitValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java index f56056c..2473144 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerInsertValueModification.java @@ -127,4 +127,14 @@ public boolean equals(Object obj) { } return Objects.equals(insertValue, other.insertValue); } + + @Override + public String toString() { + return "IntegerInsertValueModification{" + + "insertValue=" + + insertValue + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java index aae8071..0f441bb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerMultiplyModification.java @@ -81,4 +81,9 @@ public boolean equals(Object obj) { IntegerMultiplyModification other = (IntegerMultiplyModification) obj; return Objects.equals(factor, other.factor); } + + @Override + public String toString() { + return "IntegerMultiplyModification{" + "factor=" + factor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java index a8043aa..ddbf367 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerPrependValueModification.java @@ -84,4 +84,9 @@ public boolean equals(Object obj) { IntegerPrependValueModification other = (IntegerPrependValueModification) obj; return Objects.equals(prependValue, other.prependValue); } + + @Override + public String toString() { + return "IntegerPrependValueModification{" + "prependValue=" + prependValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java index 712e7c8..7c6aced 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftLeftModification.java @@ -90,4 +90,9 @@ public boolean equals(Object obj) { IntegerShiftLeftModification other = (IntegerShiftLeftModification) obj; return shift == other.shift; } + + @Override + public String toString() { + return "IntegerShiftLeftModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java index 0abfd06..bb25bd2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerShiftRightModification.java @@ -90,4 +90,9 @@ public boolean equals(Object obj) { IntegerShiftRightModification other = (IntegerShiftRightModification) obj; return shift == other.shift; } + + @Override + public String toString() { + return "IntegerShiftRightModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java index e052658..3586d55 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSubtractModification.java @@ -80,4 +80,9 @@ public boolean equals(Object obj) { IntegerSubtractModification other = (IntegerSubtractModification) obj; return Objects.equals(subtrahend, other.subtrahend); } + + @Override + public String toString() { + return "IntegerSubtractModification{" + "subtrahend=" + subtrahend + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java index 729392e..d33f6fc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerXorModification.java @@ -84,4 +84,9 @@ public boolean equals(Object obj) { IntegerXorModification other = (IntegerXorModification) obj; return Objects.equals(xor, other.xor); } + + @Override + public String toString() { + return "IntegerXorModification{" + "xor=" + xor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java index d5339a5..a42604f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAddModification.java @@ -79,4 +79,9 @@ public boolean equals(Object obj) { LongAddModification other = (LongAddModification) obj; return Objects.equals(summand, other.summand); } + + @Override + public String toString() { + return "LongAddModification{" + "summand=" + summand + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java index 2b1c633..b6f0544 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongAppendValueModification.java @@ -83,4 +83,9 @@ public boolean equals(Object obj) { LongAppendValueModification other = (LongAppendValueModification) obj; return Objects.equals(appendValue, other.appendValue); } + + @Override + public String toString() { + return "LongAppendValueModification{" + "appendValue=" + appendValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java index f242228..9635702 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueFromFileModification.java @@ -74,4 +74,14 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "LongExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + explicitValue + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java index e2bd2af..a52d08e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongExplicitValueModification.java @@ -86,4 +86,9 @@ public boolean equals(Object obj) { LongExplicitValueModification other = (LongExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "LongExplicitValueModification{" + "explicitValue=" + explicitValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java index 9f77686..3eb3071 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongInsertValueModification.java @@ -125,4 +125,14 @@ public boolean equals(Object obj) { } return Objects.equals(insertValue, other.insertValue); } + + @Override + public String toString() { + return "LongInsertValueModification{" + + "insertValue=" + + insertValue + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java index 76f735f..180f96b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongMultiplyModification.java @@ -79,4 +79,9 @@ public boolean equals(Object obj) { LongMultiplyModification other = (LongMultiplyModification) obj; return Objects.equals(factor, other.factor); } + + @Override + public String toString() { + return "LongMultiplyModification{" + "factor=" + factor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java index a2ddbd6..484d710 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongPrependValueModification.java @@ -83,4 +83,9 @@ public boolean equals(Object obj) { LongPrependValueModification other = (LongPrependValueModification) obj; return Objects.equals(prependValue, other.prependValue); } + + @Override + public String toString() { + return "LongPrependValueModification{" + "prependValue=" + prependValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java index 2a65b5c..2d47936 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftLeftModification.java @@ -92,4 +92,9 @@ public boolean equals(Object obj) { LongShiftLeftModification other = (LongShiftLeftModification) obj; return Objects.equals(shift, other.shift); } + + @Override + public String toString() { + return "LongShiftLeftModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java index bb0d5a7..0f8b2cf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongShiftRightModification.java @@ -92,4 +92,9 @@ public boolean equals(Object obj) { LongShiftRightModification other = (LongShiftRightModification) obj; return Objects.equals(shift, other.shift); } + + @Override + public String toString() { + return "LongShiftRightModification{" + "shift=" + shift + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java index 2af2263..2f04ac4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSubtractModification.java @@ -80,4 +80,9 @@ public boolean equals(Object obj) { LongSubtractModification other = (LongSubtractModification) obj; return Objects.equals(subtrahend, other.subtrahend); } + + @Override + public String toString() { + return "LongSubtractModification{" + "subtrahend=" + subtrahend + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java index a8fff82..9407bed 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongXorModification.java @@ -84,4 +84,9 @@ public boolean equals(Object obj) { LongXorModification other = (LongXorModification) obj; return Objects.equals(xor, other.xor); } + + @Override + public String toString() { + return "LongXorModification{" + "xor=" + xor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java index 47e4489..44252cb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -40,7 +40,11 @@ protected void createRandomModification() { @Override public String toString() { - return "ModifiablePath{originalValue=" + backslashEscapeString(originalValue) + "}"; + return "ModifiablePath{" + + "originalValue='" + + backslashEscapeString(originalValue) + + '\'' + + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java index 67cf917..1a806de 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathAppendValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.path; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -94,4 +96,13 @@ public boolean equals(Object obj) { PathAppendValueModification other = (PathAppendValueModification) obj; return Objects.equals(appendValue, other.appendValue); } + + @Override + public String toString() { + return "PathAppendValueModification{" + + "appendValue='" + + backslashEscapeString(appendValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java index 34f445d..7d78424 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueFromFileModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.path; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; @@ -74,4 +76,14 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "PathExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + backslashEscapeString(explicitValue) + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java index 01d4f04..d5ea0b6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathExplicitValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.path; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -90,4 +92,13 @@ public boolean equals(Object obj) { PathExplicitValueModification other = (PathExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "PathExplicitValueModification{" + + "explicitValue='" + + backslashEscapeString(explicitValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java index 2235ff5..0dfa225 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectorySeparatorModification.java @@ -131,4 +131,17 @@ public boolean equals(Object obj) { } return Objects.equals(count, other.count); } + + @Override + public String toString() { + return "PathInsertDirectorySeparatorModification{" + + "insertValue='" + + insertValue + + '\'' + + ", count=" + + count + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java index 8df1104..1e22284 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertDirectoryTraversalModification.java @@ -142,4 +142,17 @@ public boolean equals(Object obj) { } return Objects.equals(count, other.count); } + + @Override + public String toString() { + return "PathInsertDirectoryTraversalModification{" + + "insertValue='" + + insertValue + + '\'' + + ", count=" + + count + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java index 620c747..60ab6dc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathInsertValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.path; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -119,4 +121,15 @@ public boolean equals(Object obj) { } return Objects.equals(insertValue, other.insertValue); } + + @Override + public String toString() { + return "PathInsertValueModification{" + + "insertValue='" + + backslashEscapeString(insertValue) + + '\'' + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java index fb4efc3..e56f147 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathPrependValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.path; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -94,4 +96,13 @@ public boolean equals(Object obj) { PathPrependValueModification other = (PathPrependValueModification) obj; return Objects.equals(prependValue, other.prependValue); } + + @Override + public String toString() { + return "PathPrependValueModification{" + + "prependValue='" + + backslashEscapeString(prependValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java index 6847934..671e413 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java @@ -60,4 +60,9 @@ public boolean equals(Object obj) { } return getClass() == obj.getClass(); } + + @Override + public String toString() { + return "PathToggleRootModification{}"; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java index b5ce1bc..2fd73b2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteAddModification.java @@ -82,4 +82,9 @@ public boolean equals(Object obj) { ByteAddModification other = (ByteAddModification) obj; return Objects.equals(summand, other.summand); } + + @Override + public String toString() { + return "ByteAddModification{" + "summand=" + summand + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java index b8948fb..6460f96 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueFromFileModification.java @@ -74,4 +74,14 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "ByteExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue=" + + explicitValue + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java index 47d2db5..f0e6bff 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteExplicitValueModification.java @@ -86,4 +86,9 @@ public boolean equals(Object obj) { ByteExplicitValueModification other = (ByteExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "ByteExplicitValueModification{" + "explicitValue=" + explicitValue + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java index 834bcc3..9093969 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteSubtractModification.java @@ -83,4 +83,9 @@ public boolean equals(Object obj) { ByteSubtractModification other = (ByteSubtractModification) obj; return Objects.equals(subtrahend, other.subtrahend); } + + @Override + public String toString() { + return "ByteSubtractModification{" + "subtrahend=" + subtrahend + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java index 19b8aef..da6ed4d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteXorModification.java @@ -88,4 +88,9 @@ public boolean equals(Object obj) { ByteXorModification other = (ByteXorModification) obj; return Objects.equals(xor, other.xor); } + + @Override + public String toString() { + return "ByteXorModification{" + "xor=" + xor + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index c207b18..742fb79 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -86,7 +86,11 @@ public void setOriginalValue(String originalValue) { @Override public String toString() { - return "ModifiableString{originalValue=" + backslashEscapeString(originalValue) + "}"; + return "ModifiableString{" + + "originalValue='" + + backslashEscapeString(originalValue) + + '\'' + + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java index 3de565f..d5cd99b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringAppendValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.string; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -88,4 +90,13 @@ public boolean equals(Object obj) { StringAppendValueModification other = (StringAppendValueModification) obj; return Objects.equals(appendValue, other.appendValue); } + + @Override + public String toString() { + return "StringAppendValueModification{" + + "appendValue='" + + backslashEscapeString(appendValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java index 5d7acd1..4c42994 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueFromFileModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.string; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; @@ -75,4 +77,15 @@ public boolean equals(Object obj) { } return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "StringExplicitValueFromFileModification{" + + "index=" + + index + + ", explicitValue='" + + backslashEscapeString(explicitValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java index d901fc5..f2f9bdd 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.string; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -91,4 +93,13 @@ public boolean equals(Object obj) { StringExplicitValueModification other = (StringExplicitValueModification) obj; return Objects.equals(explicitValue, other.explicitValue); } + + @Override + public String toString() { + return "StringExplicitValueModification{" + + "explicitValue='" + + backslashEscapeString(explicitValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java index 8009d55..595d92d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringInsertValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.string; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -128,4 +130,15 @@ public boolean equals(Object obj) { } return Objects.equals(insertValue, other.insertValue); } + + @Override + public String toString() { + return "StringInsertValueModification{" + + "insertValue='" + + backslashEscapeString(insertValue) + + '\'' + + ", startPosition=" + + startPosition + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java index 93452fe..ef96848 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringPrependValueModification.java @@ -7,6 +7,8 @@ */ package de.rub.nds.modifiablevariable.string; +import static de.rub.nds.modifiablevariable.util.StringUtil.backslashEscapeString; + import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.IllegalStringAdapter; import jakarta.xml.bind.annotation.XmlRootElement; @@ -88,4 +90,13 @@ public boolean equals(Object obj) { StringPrependValueModification other = (StringPrependValueModification) obj; return Objects.equals(prependValue, other.prependValue); } + + @Override + public String toString() { + return "StringPrependValueModification{" + + "prependValue='" + + backslashEscapeString(prependValue) + + '\'' + + '}'; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java index f94755d..628a0c2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java @@ -24,6 +24,9 @@ private StringUtil() { * @return string with non-printable or non-ascii characters replaced */ public static String backslashEscapeString(String value) { + if (value == null) { + return null; + } StringBuffer buffer = new StringBuffer(value); for (int i = 0; i < buffer.length(); i++) { int codePoint = buffer.codePointAt(i); From 149ceb26d92715e089e66f2a04812b2b565b4984 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 12:08:36 +0100 Subject: [PATCH 32/50] Replace StringBuffer with StringBuilder in backslashEscapeString. To make it a little bit faster, since we do not need the synchronisation of StringBuffer. fix test, since I changed toString of ModifiableByteArray --- .../path/PathToggleRootModification.java | 2 +- .../de/rub/nds/modifiablevariable/util/StringUtil.java | 10 +++++----- .../bytearray/ModifiableByteArrayTest.java | 10 +--------- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java index 671e413..8d6ee3e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathToggleRootModification.java @@ -13,7 +13,7 @@ /** Modification that toggle the root slash of the original value. */ @XmlRootElement -@XmlType(propOrder = {"modificationFilter"}) +@XmlType(propOrder = "modificationFilter") public class PathToggleRootModification extends VariableModification { public PathToggleRootModification() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java index 628a0c2..947926b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/StringUtil.java @@ -27,9 +27,9 @@ public static String backslashEscapeString(String value) { if (value == null) { return null; } - StringBuffer buffer = new StringBuffer(value); - for (int i = 0; i < buffer.length(); i++) { - int codePoint = buffer.codePointAt(i); + StringBuilder builder = new StringBuilder(value); + for (int i = 0; i < builder.length(); i++) { + int codePoint = builder.codePointAt(i); String replacement; int numCodePoints = 1; switch (codePoint) { @@ -73,10 +73,10 @@ public static String backslashEscapeString(String value) { } } - buffer.replace(i, i + numCodePoints, replacement); + builder.replace(i, i + numCodePoints, replacement); i += replacement.length() - 1; } - return buffer.toString(); + return builder.toString(); } } diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 26b643f..2f7ae9b 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -357,15 +357,7 @@ public void toStringTest() { toTest = ModifiableVariableFactory.safelySetValue( toTest, new byte[] {0x00, 0x11, 0x22, 0x33, 0x44}); - assertEquals("Original byte value is: 00 11 22 33 44", toTest.toString()); - - VariableModification modification = - new ByteArrayExplicitValueModification( - new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}); - toTest.setModification(modification); - assertEquals( - "Actual byte value is: 00 01 02 03 04 05 06 07 08\nOriginal value was: 00 11 22 33 44", - toTest.toString()); + assertEquals("ModifiableByteArray{originalValue=00 11 22 33 44}", toTest.toString()); } @Test From 882c926d3bc36abc40b392afa5296dc81b3e5f46 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 12:10:57 +0100 Subject: [PATCH 33/50] fix logger of ModifiableByteArrayTest --- .../modifiablevariable/bytearray/ModifiableByteArrayTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 2f7ae9b..384d376 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -21,7 +21,7 @@ public class ModifiableByteArrayTest { - private static final Logger LOGGER = LogManager.getLogger(ModifiableByteArray.class); + private static final Logger LOGGER = LogManager.getLogger(); private ModifiableByteArray start; From 09a055a631fff4d74903b1dc2aeb996bcef460ed Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 20:44:28 +0100 Subject: [PATCH 34/50] Make ByteArrayDeleteModification more useful by allowing more random inputs, that still results in modifications. Add Delete modification for Path and Strings. --- .../ModifiableVariable.java | 2 + .../ByteArrayDeleteModification.java | 41 ++--- .../path/PathDeleteModification.java | 161 ++++++++++++++++++ .../path/PathModificationFactory.java | 16 +- .../nds/modifiablevariable/path/PathUtil.java | 19 +++ .../string/StringDeleteModification.java | 147 ++++++++++++++++ .../string/StringModificationFactory.java | 12 +- 7 files changed, 368 insertions(+), 30 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/path/PathDeleteModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index bc2afa0..e584943 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -163,6 +163,7 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = StringInsertValueModification.class, name = "StringInsertValueModification"), + @XmlElement(type = StringDeleteModification.class, name = "StringDeleteModification"), @XmlElement( type = PathExplicitValueFromFileModification.class, name = "PathExplicitValueFromFileModification"), @@ -173,6 +174,7 @@ public abstract class ModifiableVariable implements Serializable { @XmlElement( type = PathInsertDirectorySeparatorModification.class, name = "PathInsertDirectorySeparatorModification"), + @XmlElement(type = PathDeleteModification.class, name = "PathDeleteModification"), @XmlElement( type = PathInsertDirectoryTraversalModification.class, name = "PathInsertDirectoryTraversalValueModification"), diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index f44e2a1..a841355 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -7,8 +7,6 @@ */ package de.rub.nds.modifiablevariable.bytearray; -import static de.rub.nds.modifiablevariable.util.ArrayConverter.bytesToHexString; - import de.rub.nds.modifiablevariable.VariableModification; import de.rub.nds.modifiablevariable.util.ArrayConverter; import jakarta.xml.bind.annotation.XmlAccessType; @@ -55,34 +53,23 @@ protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { input = new byte[0]; } - int start = startPosition; - if (start < 0) { - start += input.length; - if (start < 0) { - LOGGER.debug( - "Trying to delete from too negative Startposition. start = {}", - start - input.length); - return input; - } - } - int endPosition = start + count; - if (endPosition > input.length) { - LOGGER.debug( - "Bytes {}..{} cannot be deleted from {{}} of length {}", - start, - endPosition, - bytesToHexString(input), - input.length); - return input; + + // Wrap around and also allow to delete at the end of the original value + int deleteStartPosition = startPosition % input.length; + if (startPosition < 0) { + deleteStartPosition += input.length - 1; } - if (count <= 0) { - LOGGER.debug("You must delete at least one byte. count = {}", count); - return input; + + // If the end position overflows, it is fixed at the end of the byte array + int deleteEndPosition = deleteStartPosition + Math.max(0, count); + if (deleteEndPosition > input.length) { + deleteEndPosition = input.length; } - byte[] ret1 = Arrays.copyOf(input, start); + + byte[] ret1 = Arrays.copyOf(input, deleteStartPosition); byte[] ret2 = null; - if (endPosition < input.length) { - ret2 = Arrays.copyOfRange(input, endPosition, input.length); + if (deleteEndPosition < input.length) { + ret2 = Arrays.copyOfRange(input, deleteEndPosition, input.length); } return ArrayConverter.concatenate(ret1, ret2); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathDeleteModification.java new file mode 100644 index 0000000..3de7c14 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathDeleteModification.java @@ -0,0 +1,161 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.path; + +import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.util.ArrayConverter; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Arrays; +import java.util.Objects; +import java.util.Random; + +/** Modification that deletes path parts from the original value. */ +@XmlRootElement +@XmlType(propOrder = {"count", "startPosition", "modificationFilter"}) +public class PathDeleteModification extends VariableModification { + + private static final int MAX_MODIFIER_LENGTH = 32; + + private int count; + + private int startPosition; + + public PathDeleteModification() { + super(); + } + + public PathDeleteModification(int startPosition, int count) { + super(); + this.count = count; + this.startPosition = startPosition; + } + + public PathDeleteModification(PathDeleteModification other) { + super(other); + count = other.count; + startPosition = other.startPosition; + } + + @Override + public PathDeleteModification createCopy() { + return new PathDeleteModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + if (input.isEmpty()) { + return input; + } + String[] pathParts = input.split("/"); + boolean leadingSlash = pathParts[0].isEmpty(); + + // Wrap around and also allow to delete at the end of the original value + int deleteStartPosition = + PathUtil.getPathPartPosition(startPosition, leadingSlash, pathParts); + // If the end position overflows, it is fixed at the end of the path + int deleteEndPosition = deleteStartPosition + count; + if (deleteEndPosition > pathParts.length) { + deleteEndPosition = pathParts.length; + } + + String[] partsBefore = Arrays.copyOf(pathParts, deleteStartPosition); + String[] partsAfter = null; + if (deleteEndPosition < pathParts.length) { + partsAfter = Arrays.copyOfRange(pathParts, deleteEndPosition, pathParts.length); + } + String[] resultParts = ArrayConverter.concatenate(partsBefore, partsAfter); + + if (input.endsWith("/") && resultParts.length > 0) { + resultParts[resultParts.length - 1] += "/"; + } + return String.join("/", resultParts); + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int modifier = r.nextInt(MAX_MODIFIER_LENGTH); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = count + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathDeleteModification(modifier, startPosition); + } else { + int modifier = r.nextInt(MAX_MODIFIER_LENGTH); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new PathDeleteModification(count, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + count; + hash = 31 * hash + startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + PathDeleteModification other = (PathDeleteModification) obj; + if (startPosition != other.startPosition) { + return false; + } + return Objects.equals(count, other.count); + } + + @Override + public String toString() { + return "PathDeleteModification{" + + "count=" + + count + + ", startPosition=" + + startPosition + + '}'; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java index bd86f8b..f143360 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathModificationFactory.java @@ -8,6 +8,7 @@ package de.rub.nds.modifiablevariable.path; import de.rub.nds.modifiablevariable.VariableModification; +import de.rub.nds.modifiablevariable.string.StringDeleteModification; import de.rub.nds.modifiablevariable.util.RandomHelper; import java.util.Random; @@ -22,9 +23,10 @@ private enum ModificationType { APPEND, PREPEND, INSERT, + DELETE, INSERT_DIRECTORY_TRAVERSAL, INSERT_DIRECTORY_SEPERATOR, - TOGGLE_ROOT, + TOGGLE_ROOT } private static final int MODIFICATION_COUNT = ModificationType.values().length; @@ -52,6 +54,10 @@ public static VariableModification insertValue(String value, int positio return new PathInsertValueModification(value, position); } + public static VariableModification delete(int position, int count) { + return new PathDeleteModification(position, count); + } + public static VariableModification insertDirectoryTraversal(int count, int position) { return new PathInsertDirectoryTraversalModification(count, position); } @@ -74,7 +80,8 @@ public static VariableModification createRandomModification(String origi } else { String[] pathParts = originalValue.split("/"); if (pathParts.length == 0) { - if (randomType == ModificationType.INSERT) { + if (randomType == ModificationType.INSERT + || randomType == ModificationType.DELETE) { randomType = ModificationType.APPEND; } numberOfPathParts = 0; @@ -127,6 +134,11 @@ public static VariableModification createRandomModification(String origi numberOfDirectorySeperator, insertPosition); case TOGGLE_ROOT: return new PathToggleRootModification(); + case DELETE: + int startPosition = random.nextInt(numberOfPathParts - 1); + int count = random.nextInt(numberOfPathParts - startPosition); + count++; + return new StringDeleteModification(startPosition, count); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java b/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java index b4154de..549f98c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/PathUtil.java @@ -59,4 +59,23 @@ private static int getInsertPosition( } return insertPosition; } + + public static int getPathPartPosition( + int startPosition, boolean leadingSlash, String[] pathParts) { + int pathPartPosition; + if (leadingSlash) { + // If the path starts with a slash, skip the first empty path part. + pathPartPosition = startPosition % (pathParts.length - 1); + if (startPosition < 0) { + pathPartPosition += pathParts.length - 2; + } + pathPartPosition++; + } else { + pathPartPosition = startPosition % pathParts.length; + if (startPosition < 0) { + pathPartPosition += pathParts.length - 1; + } + } + return pathPartPosition; + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java new file mode 100644 index 0000000..85dee06 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java @@ -0,0 +1,147 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.string; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; +import java.util.Objects; +import java.util.Random; + +/** Modification that deletes part of a string from the original value. */ +@XmlRootElement +@XmlType(propOrder = {"count", "startPosition", "modificationFilter"}) +public class StringDeleteModification extends VariableModification { + + private static final int MAX_MODIFIER_LENGTH = 32; + + private int count; + + private int startPosition; + + public StringDeleteModification() { + super(); + } + + public StringDeleteModification(int startPosition, int count) { + super(); + this.startPosition = startPosition; + this.count = count; + } + + public StringDeleteModification(StringDeleteModification other) { + super(other); + count = other.count; + startPosition = other.startPosition; + } + + @Override + public StringDeleteModification createCopy() { + return new StringDeleteModification(this); + } + + @Override + protected String modifyImplementationHook(String input) { + if (input == null) { + return null; + } + + // Wrap around and also allow to delete at the end of the original value + int deleteStartPosition = startPosition % input.length(); + if (startPosition < 0) { + deleteStartPosition += input.length() - 1; + } + + // If the end position overflows, it is fixed at the end of the string + int deleteEndPosition = deleteStartPosition + Math.max(0, count); + if (deleteEndPosition > input.length()) { + deleteEndPosition = input.length(); + } + + return new StringBuilder(input).delete(deleteStartPosition, deleteEndPosition).toString(); + } + + public int getCount() { + return count; + } + + public void setCount(int count) { + this.count = count; + } + + public int getStartPosition() { + return startPosition; + } + + public void setStartPosition(int startPosition) { + this.startPosition = startPosition; + } + + @Override + public VariableModification getModifiedCopy() { + Random r = new Random(); + + if (r.nextBoolean()) { + int modifier = r.nextInt(MAX_MODIFIER_LENGTH); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = count + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new StringDeleteModification(modifier, startPosition); + } else { + int modifier = r.nextInt(MAX_MODIFIER_LENGTH); + if (r.nextBoolean()) { + modifier *= -1; + } + modifier = startPosition + modifier; + if (modifier <= 0) { + modifier = 1; + } + return new StringDeleteModification(count, modifier); + } + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + count; + hash = 31 * hash + startPosition; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + StringDeleteModification other = (StringDeleteModification) obj; + if (startPosition != other.startPosition) { + return false; + } + return Objects.equals(count, other.count); + } + + @Override + public String toString() { + return "StringDeleteModification{" + + "count=" + + count + + ", startPosition=" + + startPosition + + '}'; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java index 1f81a34..b7d5709 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -22,7 +22,8 @@ private enum ModificationType { APPEND, PREPEND, EXPLICIT, - INSERT + INSERT, + DELETE } private static final int MODIFICATION_COUNT = ModificationType.values().length; @@ -49,6 +50,10 @@ public static VariableModification insertValue(String value, int positio return new StringInsertValueModification(value, position); } + public static VariableModification delete(int startPosition, int count) { + return new StringDeleteModification(startPosition, count); + } + public static VariableModification createRandomModification(String originalValue) { Random random = RandomHelper.getRandom(); ModificationType randomType = ModificationType.values()[random.nextInt(MODIFICATION_COUNT)]; @@ -93,6 +98,11 @@ public static VariableModification createRandomModification(String origi random.nextBytes(bytesToInsert); int insertPosition = random.nextInt(modifiedArrayLength); return new StringInsertValueModification(new String(bytesToInsert), insertPosition); + case DELETE: + int startPosition = random.nextInt(modifiedArrayLength - 1); + int count = random.nextInt(modifiedArrayLength - startPosition); + count++; + return new StringDeleteModification(startPosition, count); default: throw new IllegalStateException("Unexpected modification type: " + randomType); } From e688cae34b9216334ae5c4633bb06aecab4b0e81 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 20:54:24 +0100 Subject: [PATCH 35/50] Fix tests because I changed the behavior of ByteArrayDeleteModification --- .../bytearray/ModifiableByteArrayTest.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 384d376..b1d5e54 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -201,6 +201,8 @@ public void testDeleteBytes() { LOGGER.debug("Testing Delete all Bytes"); int len = originalValue.length; byte[] expResult = new byte[0]; + byte[] expResult2 = {(byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5}; + byte[] expResult3 = {(byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6}; VariableModification modifier = ByteArrayModificationFactory.delete(0, len); start.setModification(modifier); @@ -212,7 +214,7 @@ public void testDeleteBytes() { modifier = ByteArrayModificationFactory.delete(0, len + 1); start.setModification(modifier); - assertArrayEquals(start.getValue(), originalValue); + assertArrayEquals(start.getValue(), expResult); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete negative amount"); @@ -228,15 +230,15 @@ public void testDeleteBytes() { start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from negative Start position"); - modifier = ByteArrayModificationFactory.delete(len * -2, modification1.length); + modifier = ByteArrayModificationFactory.delete(len * -2, 1); start.setModification(modifier); - assertArrayEquals(start.getValue(), originalValue); + assertArrayEquals(start.getValue(), expResult2); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from to big Start Position"); - modifier = ByteArrayModificationFactory.delete(len * 2, modification1.length); + modifier = ByteArrayModificationFactory.delete(len * 2, 2); start.setModification(modifier); - assertArrayEquals(start.getValue(), originalValue); + assertArrayEquals(start.getValue(), expResult3); } /** Test of setInsertBytes method, of class ModifiableByteArray. */ From 0ba036f10ba0b4244d81a89722fce05ebddcde1b Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 6 Dec 2024 22:08:40 +0100 Subject: [PATCH 36/50] Fix ByteArrayShuffleModification to also shuffle byte arrays with length > 255 correctly up to length of 65535 --- .../bytearray/ByteArrayShuffleModification.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index cddfd27..852456a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -58,7 +58,16 @@ protected byte[] modifyImplementationHook(byte[] input) { } byte[] result = input.clone(); int size = input.length; - if (size != 0) { + if (size > 255) { + for (int i = 0; i < shuffle.length - 3; i += 4) { + // Combine two consecutive bytes to form 16-bit values + int p1 = ((shuffle[i] & 0xff) << 8 | shuffle[i + 1] & 0xff) % size; + int p2 = ((shuffle[i + 2] & 0xff) << 8 | shuffle[i + 3] & 0xff) % size; + byte tmp = result[p1]; + result[p1] = result[p2]; + result[p2] = tmp; + } + } else if (size > 0) { for (int i = 0; i < shuffle.length - 1; i += 2) { int p1 = (shuffle[i] & 0xff) % size; int p2 = (shuffle[i + 1] & 0xff) % size; From 2adcc6936063a96b318d6348c43a24adb999b2b3 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 9 Dec 2024 12:12:48 +0100 Subject: [PATCH 37/50] Also print modifications in toString() methods. Not very nicely implemented using innerToString() but good enough for now. --- .../nds/modifiablevariable/ModifiableVariable.java | 14 ++++++++++++++ .../biginteger/ModifiableBigInteger.java | 2 +- .../modifiablevariable/bool/ModifiableBoolean.java | 2 +- .../bytearray/ModifiableByteArray.java | 1 + .../integer/ModifiableInteger.java | 2 +- .../length/ModifiableLengthField.java | 2 +- .../modifiablevariable/longint/ModifiableLong.java | 2 +- .../modifiablevariable/path/ModifiablePath.java | 1 + .../singlebyte/ModifiableByte.java | 2 +- .../string/ModifiableString.java | 1 + 10 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index e584943..d64be33 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -254,4 +254,18 @@ public boolean containsAssertion() { public Boolean isCreateRandomModification() { return Objects.requireNonNullElse(createRandomModification, false); } + + public String innerToString() { + StringBuilder result = new StringBuilder(); + result.append(", modification=").append(modification); + + if (createRandomModification != null) { + result.append(", createRandomModification=").append(createRandomModification); + } + if (assertEquals != null) { + result.append(", assertEquals=").append(assertEquals); + } + + return result.toString(); + } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index 07eb645..5967ca6 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -83,7 +83,7 @@ public void setOriginalValue(BigInteger originalValue) { @Override public String toString() { - return "ModifiableBigInteger{" + "originalValue=" + originalValue + '}'; + return "ModifiableBigInteger{" + "originalValue=" + originalValue + innerToString() + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index fc03f2d..0db7a52 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -69,7 +69,7 @@ public boolean validateAssertions() { @Override public String toString() { - return "ModifiableBoolean{" + "originalValue=" + originalValue + '}'; + return "ModifiableBoolean{" + "originalValue=" + originalValue + innerToString() + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index 2973f82..44ee354 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -107,6 +107,7 @@ public String toString() { return "ModifiableByteArray{" + "originalValue=" + ArrayConverter.bytesToHexString(originalValue) + + innerToString() + '}'; } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index 0977990..e983e33 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -80,7 +80,7 @@ public void setOriginalValue(Integer originalValue) { @Override public String toString() { - return "ModifiableInteger{" + "originalValue=" + originalValue + '}'; + return "ModifiableInteger{" + "originalValue=" + originalValue + innerToString() + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java index 2fd2fc5..0afcfe2 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java +++ b/src/main/java/de/rub/nds/modifiablevariable/length/ModifiableLengthField.java @@ -47,7 +47,7 @@ public void setOriginalValue(Integer originalValue) { @Override public String toString() { - return "ModifiableLengthField{" + "ref=" + ref + "} " + super.toString(); + return "ModifiableLengthField{" + "ref=" + ref + super.toString() + "} "; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index 9a377ba..4111534 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -80,7 +80,7 @@ public void setOriginalValue(Long originalValue) { @Override public String toString() { - return "ModifiableLong{" + "originalValue=" + originalValue + '}'; + return "ModifiableLong{" + "originalValue=" + originalValue + innerToString() + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java index 44252cb..aff4554 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -44,6 +44,7 @@ public String toString() { + "originalValue='" + backslashEscapeString(originalValue) + '\'' + + innerToString() + '}'; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index 3a76bd7..f492053 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -75,7 +75,7 @@ public void setOriginalValue(Byte originalValue) { @Override public String toString() { - return "ModifiableByte{" + "originalValue=" + originalValue + '}'; + return "ModifiableByte{" + "originalValue=" + originalValue + innerToString() + '}'; } @Override diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 742fb79..6b9c33c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -90,6 +90,7 @@ public String toString() { + "originalValue='" + backslashEscapeString(originalValue) + '\'' + + innerToString() + '}'; } From 272f6b60f765e82556335aa21877427cf8c4e66d Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 9 Dec 2024 15:31:05 +0100 Subject: [PATCH 38/50] Just some renaming of parameters --- .../modifiablevariable/util/Modifiable.java | 207 ++++++++++-------- 1 file changed, 113 insertions(+), 94 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index a950732..43c2812 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -89,112 +89,127 @@ private static ModifiablePath getModifiablePathWithModification( return modifiablePath; } - public static ModifiableBigInteger prepend(BigInteger i) { + public static ModifiableBigInteger prepend(BigInteger perpendValue) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.prependValue(i)); + BigIntegerModificationFactory.prependValue(perpendValue)); } - public static ModifiableByteArray prepend(byte[] b) { - return getModifiableByteArrayWithModification(ByteArrayModificationFactory.prependValue(b)); + public static ModifiableByteArray prepend(byte[] perpendValue) { + return getModifiableByteArrayWithModification( + ByteArrayModificationFactory.prependValue(perpendValue)); } - public static ModifiableInteger prepend(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.prependValue(i)); + public static ModifiableInteger prepend(Integer perpendValue) { + return getModifiableIntegerWithModification( + IntegerModificationFactory.prependValue(perpendValue)); } - public static ModifiableLong prepend(Long l) { - return getModifiableLongWithModification(LongModificationFactory.prependValue(l)); + public static ModifiableLong prepend(Long perpendValue) { + return getModifiableLongWithModification( + LongModificationFactory.prependValue(perpendValue)); } - public static ModifiableString prepend(String s) { - return getModifiableStringWithModification(StringModificationFactory.prependValue(s)); + public static ModifiableString prepend(String perpendValue) { + return getModifiableStringWithModification( + StringModificationFactory.prependValue(perpendValue)); } - public static ModifiablePath prependPath(String s) { - return getModifiablePathWithModification(PathModificationFactory.prependValue(s)); + public static ModifiablePath prependPath(String perpendValue) { + return getModifiablePathWithModification( + PathModificationFactory.prependValue(perpendValue)); } - public static ModifiableBigInteger append(BigInteger i) { + public static ModifiableBigInteger append(BigInteger appendValue) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.appendValue(i)); + BigIntegerModificationFactory.appendValue(appendValue)); } - public static ModifiableByteArray append(byte[] b) { - return getModifiableByteArrayWithModification(ByteArrayModificationFactory.appendValue(b)); + public static ModifiableByteArray append(byte[] appendValue) { + return getModifiableByteArrayWithModification( + ByteArrayModificationFactory.appendValue(appendValue)); } - public static ModifiableInteger append(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.appendValue(i)); + public static ModifiableInteger append(Integer appendValue) { + return getModifiableIntegerWithModification( + IntegerModificationFactory.appendValue(appendValue)); } - public static ModifiableLong append(Long l) { - return getModifiableLongWithModification(LongModificationFactory.appendValue(l)); + public static ModifiableLong append(Long appendValue) { + return getModifiableLongWithModification(LongModificationFactory.appendValue(appendValue)); } - public static ModifiableString append(String s) { - return getModifiableStringWithModification(StringModificationFactory.appendValue(s)); + public static ModifiableString append(String appendValue) { + return getModifiableStringWithModification( + StringModificationFactory.appendValue(appendValue)); } - public static ModifiablePath appendPath(String s) { - return getModifiablePathWithModification(PathModificationFactory.appendValue(s)); + public static ModifiablePath appendPath(String appendValue) { + return getModifiablePathWithModification(PathModificationFactory.appendValue(appendValue)); } - public static ModifiableByteArray explicit(byte[] b) { + public static ModifiableByteArray explicit(byte[] explicitValue) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.explicitValue(b)); + ByteArrayModificationFactory.explicitValue(explicitValue)); } - public static ModifiableByte explicit(Byte b) { - return getModifiableByteWithModification(ByteModificationFactory.explicitValue(b)); + public static ModifiableByte explicit(Byte explicitValue) { + return getModifiableByteWithModification( + ByteModificationFactory.explicitValue(explicitValue)); } - public static ModifiableInteger explicit(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.explicitValue(i)); + public static ModifiableInteger explicit(Integer explicitValue) { + return getModifiableIntegerWithModification( + IntegerModificationFactory.explicitValue(explicitValue)); } - public static ModifiableBigInteger explicit(BigInteger i) { + public static ModifiableBigInteger explicit(BigInteger explicitValue) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.explicitValue(i)); + BigIntegerModificationFactory.explicitValue(explicitValue)); } - public static ModifiableLong explicit(Long l) { - return getModifiableLongWithModification(LongModificationFactory.explicitValue(l)); + public static ModifiableLong explicit(Long explicitValue) { + return getModifiableLongWithModification( + LongModificationFactory.explicitValue(explicitValue)); } - public static ModifiableBoolean explicit(Boolean b) { - return getModifiableBooleanWithModification(BooleanModificationFactory.explicitValue(b)); + public static ModifiableBoolean explicit(Boolean explicitValue) { + return getModifiableBooleanWithModification( + BooleanModificationFactory.explicitValue(explicitValue)); } - public static ModifiableString explicit(String s) { - return getModifiableStringWithModification(StringModificationFactory.explicitValue(s)); + public static ModifiableString explicit(String explicitValue) { + return getModifiableStringWithModification( + StringModificationFactory.explicitValue(explicitValue)); } - public static ModifiableBigInteger insert(BigInteger i, int position) { + public static ModifiableBigInteger insert(BigInteger insertValue, int position) { return getModifiableBigIntegerWithModification( - BigIntegerModificationFactory.insertValue(i, position)); + BigIntegerModificationFactory.insertValue(insertValue, position)); } - public static ModifiableByteArray insert(byte[] b, int position) { + public static ModifiableByteArray insert(byte[] insertValue, int position) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.insertValue(b, position)); + ByteArrayModificationFactory.insertValue(insertValue, position)); } - public static ModifiableInteger insert(Integer i, int position) { + public static ModifiableInteger insert(Integer insertValue, int position) { return getModifiableIntegerWithModification( - IntegerModificationFactory.insertValue(i, position)); + IntegerModificationFactory.insertValue(insertValue, position)); } - public static ModifiableLong insert(Long l, int position) { - return getModifiableLongWithModification(LongModificationFactory.insertValue(l, position)); + public static ModifiableLong insert(Long insertValue, int position) { + return getModifiableLongWithModification( + LongModificationFactory.insertValue(insertValue, position)); } - public static ModifiableString insert(String s, int position) { + public static ModifiableString insert(String insertValue, int position) { return getModifiableStringWithModification( - StringModificationFactory.insertValue(s, position)); + StringModificationFactory.insertValue(insertValue, position)); } - public static ModifiablePath insertPath(String s, int position) { - return getModifiablePathWithModification(PathModificationFactory.insertValue(s, position)); + public static ModifiablePath insertPath(String insertValue, int position) { + return getModifiablePathWithModification( + PathModificationFactory.insertValue(insertValue, position)); } public static ModifiablePath insertDirectoryTraversal(int count, int position) { @@ -207,57 +222,58 @@ public static ModifiablePath insertDirectorySeperator(int count, int position) { PathModificationFactory.insertDirectorySeperator(count, position)); } - public static ModifiableByteArray xor(byte[] b, int position) { + public static ModifiableByteArray xor(byte[] xor, int position) { return getModifiableByteArrayWithModification( - ByteArrayModificationFactory.xor(b, position)); + ByteArrayModificationFactory.xor(xor, position)); } - public static ModifiableByte xor(Byte b) { - return getModifiableByteWithModification(ByteModificationFactory.xor(b)); + public static ModifiableByte xor(Byte xor) { + return getModifiableByteWithModification(ByteModificationFactory.xor(xor)); } - public static ModifiableInteger xor(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.xor(i)); + public static ModifiableInteger xor(Integer xor) { + return getModifiableIntegerWithModification(IntegerModificationFactory.xor(xor)); } - public static ModifiableBigInteger xor(BigInteger i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.xor(i)); + public static ModifiableBigInteger xor(BigInteger xor) { + return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.xor(xor)); } - public static ModifiableLong xor(Long l) { - return getModifiableLongWithModification(LongModificationFactory.xor(l)); + public static ModifiableLong xor(Long xor) { + return getModifiableLongWithModification(LongModificationFactory.xor(xor)); } - public static ModifiableByte add(Byte b) { - return getModifiableByteWithModification(ByteModificationFactory.add(b)); + public static ModifiableByte add(Byte summand) { + return getModifiableByteWithModification(ByteModificationFactory.add(summand)); } - public static ModifiableInteger add(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.add(i)); + public static ModifiableInteger add(Integer summand) { + return getModifiableIntegerWithModification(IntegerModificationFactory.add(summand)); } - public static ModifiableBigInteger add(BigInteger i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.add(i)); + public static ModifiableBigInteger add(BigInteger summand) { + return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.add(summand)); } - public static ModifiableLong add(Long l) { - return getModifiableLongWithModification(LongModificationFactory.add(l)); + public static ModifiableLong add(Long summand) { + return getModifiableLongWithModification(LongModificationFactory.add(summand)); } - public static ModifiableByte sub(Byte b) { - return getModifiableByteWithModification(ByteModificationFactory.sub(b)); + public static ModifiableByte sub(Byte subtrahend) { + return getModifiableByteWithModification(ByteModificationFactory.sub(subtrahend)); } - public static ModifiableInteger sub(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.sub(i)); + public static ModifiableInteger sub(Integer subtrahend) { + return getModifiableIntegerWithModification(IntegerModificationFactory.sub(subtrahend)); } - public static ModifiableBigInteger sub(BigInteger i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.sub(i)); + public static ModifiableBigInteger sub(BigInteger subtrahend) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.sub(subtrahend)); } - public static ModifiableLong sub(Long l) { - return getModifiableLongWithModification(LongModificationFactory.sub(l)); + public static ModifiableLong sub(Long subtrahend) { + return getModifiableLongWithModification(LongModificationFactory.sub(subtrahend)); } public static ModifiableByteArray delete(int startPosition, int count) { @@ -282,39 +298,42 @@ public static ModifiablePath toggleRoot() { return getModifiablePathWithModification(PathModificationFactory.toggleRoot()); } - public static ModifiableBigInteger shiftLeftBigInteger(Integer i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.shiftLeft(i)); + public static ModifiableBigInteger shiftLeftBigInteger(Integer shift) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.shiftLeft(shift)); } - public static ModifiableInteger shiftLeft(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.shiftLeft(i)); + public static ModifiableInteger shiftLeft(Integer shift) { + return getModifiableIntegerWithModification(IntegerModificationFactory.shiftLeft(shift)); } - public static ModifiableLong shiftLeftLong(Integer i) { - return getModifiableLongWithModification(LongModificationFactory.shiftLeft(i)); + public static ModifiableLong shiftLeftLong(Integer shift) { + return getModifiableLongWithModification(LongModificationFactory.shiftLeft(shift)); } - public static ModifiableBigInteger shiftRightBigInteger(Integer i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.shiftRight(i)); + public static ModifiableBigInteger shiftRightBigInteger(Integer shift) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.shiftRight(shift)); } - public static ModifiableBigInteger multiplyBigInteger(BigInteger i) { - return getModifiableBigIntegerWithModification(BigIntegerModificationFactory.multiply(i)); + public static ModifiableInteger shiftRight(Integer shift) { + return getModifiableIntegerWithModification(IntegerModificationFactory.shiftRight(shift)); } - public static ModifiableInteger multiply(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.multiply(i)); + public static ModifiableLong shiftRightLong(Integer shift) { + return getModifiableLongWithModification(LongModificationFactory.shiftRight(shift)); } - public static ModifiableLong multiply(Long l) { - return getModifiableLongWithModification(LongModificationFactory.multiply(l)); + public static ModifiableBigInteger multiplyBigInteger(BigInteger factor) { + return getModifiableBigIntegerWithModification( + BigIntegerModificationFactory.multiply(factor)); } - public static ModifiableInteger shiftRight(Integer i) { - return getModifiableIntegerWithModification(IntegerModificationFactory.shiftRight(i)); + public static ModifiableInteger multiply(Integer factor) { + return getModifiableIntegerWithModification(IntegerModificationFactory.multiply(factor)); } - public static ModifiableLong shiftRightLong(Integer i) { - return getModifiableLongWithModification(LongModificationFactory.shiftRight(i)); + public static ModifiableLong multiply(Long factor) { + return getModifiableLongWithModification(LongModificationFactory.multiply(factor)); } } From d613cdd1ba1489c156821cec399a91810da703bc Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 9 Dec 2024 16:04:01 +0100 Subject: [PATCH 39/50] Change behavior of ByteArrayXorModification. Allow arbitrary start position, that wraps around. And always apply xor, even if xor is to long for original value -> cut of to long part. This probably does not match the expected behavior of all users, so further improvements can be made in the future. --- .../BigIntegerModificationFactory.java | 2 +- .../ByteArrayShuffleModification.java | 2 +- .../bytearray/ByteArrayXorModification.java | 32 +++++++++--------- .../logging/ExtendedPatternLayout.java | 2 +- .../util/BadFixedRandom.java | 2 +- .../util/ReflectionHelper.java | 33 ------------------- .../util/SuppressingBooleanAdapter.java | 4 +-- .../bytearray/ModifiableByteArrayTest.java | 17 ++++++++-- 8 files changed, 35 insertions(+), 59 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index 53573fe..120067c 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -147,7 +147,7 @@ public static void setStandardInteractiveModification( standardInteractiveModification = modification; } - protected static BigIntegerInteractiveModification.InteractiveBigIntegerModification + static BigIntegerInteractiveModification.InteractiveBigIntegerModification getStandardInteractiveModification() { return standardInteractiveModification; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 852456a..4799015 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -54,7 +54,7 @@ public ByteArrayShuffleModification createCopy() { @Override protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { - return input; + return null; } byte[] result = input.clone(); int size = input.length; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index b26a5c8..f989c66 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -59,25 +59,23 @@ protected byte[] modifyImplementationHook(byte[] input) { input = new byte[0]; } byte[] result = input.clone(); - int start = startPosition; - if (start < 0) { - start += input.length; + + // Wrap around and also allow to xor at the end of the original value + int xorPosition = startPosition % input.length; + if (startPosition < 0) { + xorPosition += input.length - 1; } - int end = start + xor.length; - if (end > result.length) { - // result = new byte[end]; - // System.arraycopy(input, 0, result, 0, input.length); - LOGGER.debug( - "Input {{}} of length {} cannot be xor-ed with {{}} of length {} with start position {}", - input, - input.length, - xor, - xor.length, - startPosition); - return input; + int endPosition = xorPosition + xor.length; + if (endPosition > result.length) { + // Fix the end position to the length of the original value + // This may not match the expected behavior of a user + // But for fuzzing purpose, that's fine + // Todo: Add an option that expands the byte array instead + endPosition = result.length; } - for (int i = 0; i < xor.length; ++i) { - result[start + i] = (byte) (input[start + i] ^ xor[i]); + + for (int i = 0; i < endPosition - xorPosition; ++i) { + result[xorPosition + i] = (byte) (input[xorPosition + i] ^ xor[i]); } return result; } diff --git a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java index b293cc8..e35a58e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java +++ b/src/main/java/de/rub/nds/modifiablevariable/logging/ExtendedPatternLayout.java @@ -171,7 +171,7 @@ private static StringBuilder toText( public static PatternParser createPatternParser(Configuration config) { if (config == null) { - return new PatternParser(config, "Converter", LogEventPatternConverter.class); + return new PatternParser(null, "Converter", LogEventPatternConverter.class); } else { PatternParser parser = config.getComponent("Converter"); if (parser == null) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java b/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java index ccc3df9..b874a58 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/BadFixedRandom.java @@ -15,7 +15,7 @@ */ public class BadFixedRandom extends Random { - byte retVal; + private final byte retVal; public BadFixedRandom(byte retVal) { super(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java b/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java index ec2c8ec..699fc39 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ReflectionHelper.java @@ -77,39 +77,6 @@ public static List getValuesFromFieldList(Object object, List fie return list; } - // /** - // * - // * @param object - // * @param field - // * @return - // * @throws IllegalAccessException - // * @throws java.lang.reflect.InvocationTargetException - // */ - // public static Object getFieldValue(Object object, Field field) throws - // IllegalAccessException, IllegalArgumentException, - // InvocationTargetException { - // Method[] methods = object.getClass().getMethods(); - // for (Method method : methods) { - // String name = method.getName(); - // if (name.equalsIgnoreCase("get" + field.getName())) { - // return method.invoke(object); - // } - // } - // return null; - // } - // - // public static void setFieldValue(Object object, Field field, Object - // value) throws - // IllegalAccessException, IllegalArgumentException, - // InvocationTargetException { - // Method[] methods = object.getClass().getMethods(); - // for (Method method : methods) { - // String name = method.getName(); - // if (name.equalsIgnoreCase("set" + field.getName())) { - // method.invoke(object, value); - // } - // } - // } public static Type[] getParameterizedTypes(Object object) { Type superclassType = object.getClass().getGenericSuperclass(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/SuppressingBooleanAdapter.java b/src/main/java/de/rub/nds/modifiablevariable/util/SuppressingBooleanAdapter.java index 3a9c5dd..f16a0de 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/SuppressingBooleanAdapter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/SuppressingBooleanAdapter.java @@ -15,7 +15,7 @@ public abstract class SuppressingBooleanAdapter extends XmlAdapter modifier2 = ByteArrayModificationFactory.xor(modification2, 0); start.setModification(modifier2); - assertArrayEquals(originalValue, start.getValue()); + assertArrayEquals(expResult2, start.getValue()); } /** Test of setXorLastBytes method, of class ModifiableByteArray. */ @@ -103,10 +107,15 @@ public void testXorLastBytes() { LOGGER.debug("Computed: {}", () -> ArrayConverter.bytesToHexString(start.getValue())); assertArrayEquals(expResult, start.getValue()); + byte[] expResult2 = originalValue.clone(); + for (int i = 0; i < 2; i++) { + expResult2[first + i] = (byte) (originalValue[first + i] ^ modification2[i]); + } + VariableModification modifier2 = ByteArrayModificationFactory.xor(modification2, first); start.setModification(modifier2); - assertArrayEquals(originalValue, start.getValue()); + assertArrayEquals(expResult2, start.getValue()); } /** Test of setPrependBytes method, of class ModifiableByteArray. */ @@ -359,7 +368,9 @@ public void toStringTest() { toTest = ModifiableVariableFactory.safelySetValue( toTest, new byte[] {0x00, 0x11, 0x22, 0x33, 0x44}); - assertEquals("ModifiableByteArray{originalValue=00 11 22 33 44}", toTest.toString()); + assertEquals( + "ModifiableByteArray{originalValue=00 11 22 33 44, modification=null}", + toTest.toString()); } @Test From ad139d1d019028753daf9d171369cc97eeb219d2 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Thu, 12 Dec 2024 19:46:20 +0100 Subject: [PATCH 40/50] Change behaviour of reduceToOriginalValue() --- .../nds/modifiablevariable/ModifiableVariable.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index d64be33..67fcf6f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -225,9 +225,18 @@ public E getValue() { return getOriginalValue(); } + /** + * Sets the original value to the value changed by the modification. The modification is then + * set to null, to reduce the modifiable variable to the original value. + * + *

createRandomModification is ignored + */ public void reduceToOriginalValue(boolean evenWithNullOriginalValue) { if (evenWithNullOriginalValue || getOriginalValue() != null) { - setOriginalValue(getValue()); + if (modification != null) { + setOriginalValue(modification.modify(getOriginalValue())); + modification = null; + } } } From 564be8061d55cc7d53730189fc910a5dbb5e8b62 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 13 Dec 2024 15:11:47 +0100 Subject: [PATCH 41/50] Add Swap Endian Modifications for long and integer --- .../ModifiableVariable.java | 4 ++ .../integer/IntegerModificationFactory.java | 7 ++ .../IntegerSwapEndianModification.java | 64 +++++++++++++++++++ .../longint/LongModificationFactory.java | 7 ++ .../longint/LongSwapEndianModification.java | 64 +++++++++++++++++++ .../modifiablevariable/util/Modifiable.java | 8 +++ 6 files changed, 154 insertions(+) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/longint/LongSwapEndianModification.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 67fcf6f..2914dd4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -97,6 +97,9 @@ public abstract class ModifiableVariable implements Serializable { type = ByteArrayDuplicateModification.class, name = "ByteArrayDuplicateModification"), @XmlElement(type = ByteArrayDeleteModification.class, name = "ByteArrayDeleteModification"), + @XmlElement( + type = IntegerSwapEndianModification.class, + name = "IntegerSwapEndianModification"), @XmlElement(type = IntegerXorModification.class, name = "IntegerXorModification"), @XmlElement(type = IntegerSubtractModification.class, name = "IntegerSubtractModification"), @XmlElement(type = IntegerMultiplyModification.class, name = "IntegerMultiplyModification"), @@ -123,6 +126,7 @@ public abstract class ModifiableVariable implements Serializable { type = IntegerPrependValueModification.class, name = "IntegerPrependValueModification"), @XmlElement(type = LongXorModification.class, name = "LongXorModification"), + @XmlElement(type = LongSwapEndianModification.class, name = "LongSwapEndianModification"), @XmlElement(type = LongSubtractModification.class, name = "LongSubtractModification"), @XmlElement( type = LongExplicitValueFromFileModification.class, diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java index 8215f23..78b9d04 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java @@ -25,6 +25,7 @@ private enum ModificationType { SUBTRACT, MULTIPLY, XOR, + SWAP_ENDIAN, EXPLICIT, SHIFT_LEFT, SHIFT_RIGHT, @@ -92,6 +93,10 @@ public static VariableModification xor(Integer xor) { return new IntegerXorModification(xor); } + public static VariableModification swapEndian() { + return new IntegerSwapEndianModification(); + } + public static VariableModification explicitValue(String value) { return explicitValue(Integer.parseInt(value)); } @@ -162,6 +167,8 @@ public static VariableModification createRandomModification() { random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); case XOR: return new IntegerXorModification(modification); + case SWAP_ENDIAN: + return new IntegerSwapEndianModification(); case EXPLICIT: return new IntegerExplicitValueModification(modification); case SHIFT_LEFT: diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java new file mode 100644 index 0000000..601b9ab --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerSwapEndianModification.java @@ -0,0 +1,64 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.integer; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + +@XmlRootElement +@XmlType(propOrder = "modificationFilter") +public class IntegerSwapEndianModification extends VariableModification { + + public IntegerSwapEndianModification() { + super(); + } + + public IntegerSwapEndianModification(IntegerSwapEndianModification other) { + super(other); + } + + @Override + public IntegerSwapEndianModification createCopy() { + return new IntegerSwapEndianModification(this); + } + + @Override + protected Integer modifyImplementationHook(Integer input) { + if (input == null) { + return null; + } + return Integer.reverseBytes(input); + } + + @Override + public VariableModification getModifiedCopy() { + return new IntegerSwapEndianModification(); + } + + @Override + public int hashCode() { + return 7; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + return getClass() == obj.getClass(); + } + + @Override + public String toString() { + return "IntegerSwapEndianModification{" + '}'; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index 0b22db1..11050eb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -26,6 +26,7 @@ private enum ModificationType { SUBTRACT, MULTIPLY, XOR, + SWAP_ENDIAN, EXPLICIT, SHIFT_LEFT, SHIFT_RIGHT, @@ -77,6 +78,10 @@ public static VariableModification xor(Long xor) { return new LongXorModification(xor); } + public static VariableModification swapEndian() { + return new LongSwapEndianModification(); + } + public static VariableModification explicitValue(String value) { return explicitValue(Long.parseLong(value)); } @@ -155,6 +160,8 @@ public static VariableModification createRandomModification() { (long) random.nextInt(MAX_MODIFICATION_MULTIPLY_VALUE)); case XOR: return new LongXorModification(modification); + case SWAP_ENDIAN: + return new LongSwapEndianModification(); case EXPLICIT: return new LongExplicitValueModification(modification); case SHIFT_LEFT: diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongSwapEndianModification.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSwapEndianModification.java new file mode 100644 index 0000000..980b4b8 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongSwapEndianModification.java @@ -0,0 +1,64 @@ +/* + * ModifiableVariable - A Variable Concept for Runtime Modifications + * + * Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH + * + * Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 + */ +package de.rub.nds.modifiablevariable.longint; + +import de.rub.nds.modifiablevariable.VariableModification; +import jakarta.xml.bind.annotation.XmlRootElement; +import jakarta.xml.bind.annotation.XmlType; + +@XmlRootElement +@XmlType(propOrder = "modificationFilter") +public class LongSwapEndianModification extends VariableModification { + + public LongSwapEndianModification() { + super(); + } + + public LongSwapEndianModification(LongSwapEndianModification other) { + super(other); + } + + @Override + public LongSwapEndianModification createCopy() { + return new LongSwapEndianModification(this); + } + + @Override + protected Long modifyImplementationHook(Long input) { + if (input == null) { + return null; + } + return Long.reverseBytes(input); + } + + @Override + public VariableModification getModifiedCopy() { + return new LongSwapEndianModification(); + } + + @Override + public int hashCode() { + return 7; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + return getClass() == obj.getClass(); + } + + @Override + public String toString() { + return "LongSwapEndianModification{" + '}'; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java index 43c2812..cf1e237 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/Modifiable.java @@ -243,6 +243,14 @@ public static ModifiableLong xor(Long xor) { return getModifiableLongWithModification(LongModificationFactory.xor(xor)); } + public static ModifiableInteger swapEndianIntger() { + return getModifiableIntegerWithModification(IntegerModificationFactory.swapEndian()); + } + + public static ModifiableLong swapEndianLong() { + return getModifiableLongWithModification(LongModificationFactory.swapEndian()); + } + public static ModifiableByte add(Byte summand) { return getModifiableByteWithModification(ByteModificationFactory.add(summand)); } From 6a0d506a8f810d95dfcc40bbb0b874a3708cb2ef Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 13 Dec 2024 16:52:51 +0100 Subject: [PATCH 42/50] Allow multiple modifications on one modifiable variable --- .../ModifiableVariable.java | 81 ++++++++++++++----- .../bytearray/ModifiableByteArrayTest.java | 4 +- 2 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 2914dd4..1cdafd3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -16,14 +16,11 @@ import de.rub.nds.modifiablevariable.path.*; import de.rub.nds.modifiablevariable.singlebyte.*; import de.rub.nds.modifiablevariable.string.*; -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.LinkedList; import java.util.Objects; +import java.util.stream.Collectors; /** * The base abstract class for modifiable variables, including the getValue function.The class needs @@ -37,6 +34,7 @@ @XmlAccessorType(XmlAccessType.FIELD) public abstract class ModifiableVariable implements Serializable { + @XmlElementWrapper @XmlElements({ @XmlElement(type = BigIntegerXorModification.class, name = "BigIntegerXorModification"), @XmlElement( @@ -190,7 +188,7 @@ public abstract class ModifiableVariable implements Serializable { type = PathToggleRootModification.class, name = "PathToggleRootValueModification"), }) - private VariableModification modification; + private LinkedList> modifications; private Boolean createRandomModification; @@ -202,19 +200,52 @@ protected ModifiableVariable() { protected ModifiableVariable(ModifiableVariable other) { super(); + if (other.modifications != null) { + modifications = new LinkedList<>(); + for (VariableModification item : other.modifications) { + modifications.add(item != null ? item.createCopy() : null); + } + } createRandomModification = other.createRandomModification; - modification = other.modification != null ? other.modification.createCopy() : null; // Warning: Make sure to copy assertEquals in subclass correctly assertEquals = other.assertEquals; } + /** Set a single modification, all previously set modifications are removed */ public void setModification(VariableModification modification) { - this.modification = modification; + if (modification != null) { + modifications = new LinkedList<>(); + modifications.add(modification); + } else { + modifications = null; + } + } + + /** Adds a modification to this modifiable variable */ + public void addModification(VariableModification modification) { + if (modification != null) { + if (modifications == null) { + modifications = new LinkedList<>(); + } + modifications.add(modification); + } } - @XmlTransient + /** + * Returns the first modification that was set for this modifiable variable, if one exists. + * + *

Use {@code getModifications()} to get all modifications + */ public VariableModification getModification() { - return modification; + if (modifications == null || modifications.isEmpty()) { + return null; + } + return modifications.getFirst(); + } + + /** Returns all modifications that are set for this modifiable variable */ + public LinkedList> getModifications() { + return modifications; } public E getValue() { @@ -223,10 +254,17 @@ public E getValue() { createRandomModification = false; } - if (modification != null) { - return modification.modify(getOriginalValue()); + return getModifiedValue(); + } + + private E getModifiedValue() { + E resultValue = getOriginalValue(); + if (modifications != null) { + for (VariableModification modification : modifications) { + resultValue = modification.modify(resultValue); + } } - return getOriginalValue(); + return resultValue; } /** @@ -237,9 +275,9 @@ public E getValue() { */ public void reduceToOriginalValue(boolean evenWithNullOriginalValue) { if (evenWithNullOriginalValue || getOriginalValue() != null) { - if (modification != null) { - setOriginalValue(modification.modify(getOriginalValue())); - modification = null; + if (modifications != null) { + setOriginalValue(getModifiedValue()); + modifications = null; } } } @@ -270,7 +308,14 @@ public Boolean isCreateRandomModification() { public String innerToString() { StringBuilder result = new StringBuilder(); - result.append(", modification=").append(modification); + if (modifications != null) { + result.append(", modifications=[") + .append( + modifications.stream() + .map(Object::toString) + .collect(Collectors.joining(", "))) + .append("]"); + } if (createRandomModification != null) { result.append(", createRandomModification=").append(createRandomModification); diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 62287d9..37563bf 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -368,9 +368,7 @@ public void toStringTest() { toTest = ModifiableVariableFactory.safelySetValue( toTest, new byte[] {0x00, 0x11, 0x22, 0x33, 0x44}); - assertEquals( - "ModifiableByteArray{originalValue=00 11 22 33 44, modification=null}", - toTest.toString()); + assertEquals("ModifiableByteArray{originalValue=00 11 22 33 44}", toTest.toString()); } @Test From 3a3a2adf975f3a3927583277da60187535f02ff5 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 16 Dec 2024 09:58:18 +0100 Subject: [PATCH 43/50] Fi some overflows --- .../biginteger/BigIntegerModificationFactory.java | 5 ++--- .../bytearray/ByteArrayDeleteModification.java | 3 +++ .../bytearray/ByteArrayModificationFactory.java | 3 +-- .../bytearray/ByteArrayXorModification.java | 3 +++ .../integer/IntegerModificationFactory.java | 5 ++--- .../modifiablevariable/longint/LongModificationFactory.java | 5 ++--- .../singlebyte/ByteModificationFactory.java | 5 ++--- .../modifiablevariable/string/StringDeleteModification.java | 3 +++ 8 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java index 120067c..57e3ba7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerModificationFactory.java @@ -103,10 +103,9 @@ public static VariableModification explicitValue(BigInteger value) { return new BigIntegerExplicitValueModification(value); } - public static VariableModification explicitValueFromFile(int value) { + public static VariableModification explicitValueFromFile(int pos) { List> modifications = modificationsFromFile(); - int pos = value % modifications.size(); - return modifications.get(pos); + return modifications.get(pos % modifications.size()); } public static VariableModification appendValue(BigInteger value) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index a841355..88b25d5 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -53,6 +53,9 @@ protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { input = new byte[0]; } + if (input.length == 0) { + return input; + } // Wrap around and also allow to delete at the end of the original value int deleteStartPosition = startPosition % input.length; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java index c458ad4..ee603cf 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayModificationFactory.java @@ -100,8 +100,7 @@ public static VariableModification explicitValue(byte[] explicitValue) { public static VariableModification explicitValueFromFile(int value) { List> modifications = modificationsFromFile(); - int pos = value % modifications.size(); - return modifications.get(pos); + return modifications.get(value % modifications.size()); } /** diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index f989c66..3471b3e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -58,6 +58,9 @@ protected byte[] modifyImplementationHook(byte[] input) { if (input == null) { input = new byte[0]; } + if (input.length == 0) { + return input; + } byte[] result = input.clone(); // Wrap around and also allow to xor at the end of the original value diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java index 78b9d04..9acd71e 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/IntegerModificationFactory.java @@ -105,10 +105,9 @@ public static VariableModification explicitValue(Integer value) { return new IntegerExplicitValueModification(value); } - public static VariableModification explicitValueFromFile(int value) { + public static VariableModification explicitValueFromFile(int pos) { List> modifications = modificationsFromFile(); - int pos = value % modifications.size(); - return modifications.get(pos); + return modifications.get(pos % modifications.size()); } public static VariableModification appendValue(Integer value) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java index 11050eb..546db55 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/LongModificationFactory.java @@ -90,10 +90,9 @@ public static VariableModification explicitValue(Long value) { return new LongExplicitValueModification(value); } - public static VariableModification explicitValueFromFile(int value) { + public static VariableModification explicitValueFromFile(int pos) { List> modifications = modificationsFromFile(); - int pos = value % modifications.size(); - return modifications.get(pos); + return modifications.get(pos % modifications.size()); } public static VariableModification appendValue(Long value) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java index 91627a4..5159377 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ByteModificationFactory.java @@ -66,10 +66,9 @@ public static VariableModification explicitValue(Byte value) { return new ByteExplicitValueModification(value); } - public static VariableModification explicitValueFromFile(int value) { + public static VariableModification explicitValueFromFile(int pos) { List> modifications = modificationsFromFile(); - int pos = value % modifications.size(); - return modifications.get(pos); + return modifications.get(pos % modifications.size()); } public static synchronized List> modificationsFromFile() { diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java index 85dee06..aea4e26 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringDeleteModification.java @@ -50,6 +50,9 @@ protected String modifyImplementationHook(String input) { if (input == null) { return null; } + if (input.isEmpty()) { + return input; + } // Wrap around and also allow to delete at the end of the original value int deleteStartPosition = startPosition % input.length(); From dc19dd427b2d24789d4f2a6c3c83ac006ac3cb33 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 18 Dec 2024 16:54:54 +0100 Subject: [PATCH 44/50] Add softlySetValue methods for all modifiable variables. --- .../ModifiableVariableFactory.java | 104 ++++++++++++++++++ .../biginteger/ModifiableBigInteger.java | 5 + .../bytearray/ModifiableByteArray.java | 5 + .../integer/ModifiableInteger.java | 5 + .../longint/ModifiableLong.java | 5 + .../path/ModifiablePath.java | 4 + .../singlebyte/ModifiableByte.java | 5 + .../string/ModifiableString.java | 5 + 8 files changed, 138 insertions(+) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java index 08fe41b..9e80039 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java @@ -59,6 +59,19 @@ public static ModifiableBigInteger safelySetValue(ModifiableBigInteger mv, BigIn return mv; } + /** + * Returns only a ModifiableBigInteger with the value, if the given mv is null or the original + * value of the mv is null + */ + public static ModifiableBigInteger softlySetValue(ModifiableBigInteger mv, BigInteger value) { + if (mv == null) { + return new ModifiableBigInteger(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableString safelySetValue(ModifiableString mv, String value) { if (mv == null) { mv = new ModifiableString(); @@ -67,6 +80,19 @@ public static ModifiableString safelySetValue(ModifiableString mv, String value) return mv; } + /** + * Returns only a ModifiableString with the value, if the given mv is null or the original value + * of the mv is null + */ + public static ModifiableString softlySetValue(ModifiableString mv, String value) { + if (mv == null) { + return new ModifiableString(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableInteger safelySetValue(ModifiableInteger mv, Integer value) { if (mv == null) { mv = new ModifiableInteger(); @@ -75,6 +101,19 @@ public static ModifiableInteger safelySetValue(ModifiableInteger mv, Integer val return mv; } + /** + * Returns only a ModifiableInteger with the value, if the given mv is null or the original + * value of the mv is null + */ + public static ModifiableInteger softlySetValue(ModifiableInteger mv, Integer value) { + if (mv == null) { + return new ModifiableInteger(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableByte safelySetValue(ModifiableByte mv, Byte value) { if (mv == null) { mv = new ModifiableByte(); @@ -83,6 +122,19 @@ public static ModifiableByte safelySetValue(ModifiableByte mv, Byte value) { return mv; } + /** + * Returns only a ModifiableByte with the value, if the given mv is null or the original value + * of the mv is null + */ + public static ModifiableByte softlySetValue(ModifiableByte mv, Byte value) { + if (mv == null) { + return new ModifiableByte(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableByteArray safelySetValue(ModifiableByteArray mv, byte[] value) { if (mv == null) { mv = new ModifiableByteArray(); @@ -91,6 +143,19 @@ public static ModifiableByteArray safelySetValue(ModifiableByteArray mv, byte[] return mv; } + /** + * Returns only a ModifiableByteArray with the value, if the given mv is null or the original + * value of the mv is null + */ + public static ModifiableByteArray softlySetValue(ModifiableByteArray mv, byte[] value) { + if (mv == null) { + return new ModifiableByteArray(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableLong safelySetValue(ModifiableLong mv, Long value) { if (mv == null) { mv = new ModifiableLong(); @@ -99,6 +164,19 @@ public static ModifiableLong safelySetValue(ModifiableLong mv, Long value) { return mv; } + /** + * Returns only a ModifiableLong with the value, if the given mv is null or the original value + * of the mv is null + */ + public static ModifiableLong softlySetValue(ModifiableLong mv, Long value) { + if (mv == null) { + return new ModifiableLong(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableBoolean safelySetValue(ModifiableBoolean mv, Boolean value) { if (mv == null) { mv = new ModifiableBoolean(); @@ -107,6 +185,19 @@ public static ModifiableBoolean safelySetValue(ModifiableBoolean mv, Boolean val return mv; } + /** + * Returns only a ModifiableBoolean with the value, if the given mv is null or the original + * value of the mv is null + */ + public static ModifiableBoolean softlySetValue(ModifiableBoolean mv, Boolean value) { + if (mv == null) { + return new ModifiableBoolean(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiablePath safelySetValue(ModifiablePath mv, String value) { if (mv == null) { mv = new ModifiablePath(); @@ -115,6 +206,19 @@ public static ModifiablePath safelySetValue(ModifiablePath mv, String value) { return mv; } + /** + * Returns only a ModifiablePath with the value, if the given mv is null or the original value + * of the mv is null + */ + public static ModifiablePath softlySetValue(ModifiablePath mv, String value) { + if (mv == null) { + return new ModifiablePath(value); + } else if (mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + private ModifiableVariableFactory() { super(); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index 5967ca6..b801daa 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -25,6 +25,11 @@ public ModifiableBigInteger() { super(); } + public ModifiableBigInteger(BigInteger originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableBigInteger(ModifiableBigInteger other) { super(other); originalValue = other.originalValue; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index 44ee354..cdcfbcc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -27,6 +27,11 @@ public ModifiableByteArray() { super(); } + public ModifiableByteArray(byte[] originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableByteArray(ModifiableByteArray other) { super(other); originalValue = other.originalValue != null ? other.originalValue.clone() : null; diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index e983e33..11189a9 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -24,6 +24,11 @@ public ModifiableInteger() { super(); } + public ModifiableInteger(Integer originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableInteger(ModifiableInteger other) { super(other); originalValue = other.originalValue; diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index 4111534..b5cc778 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -24,6 +24,11 @@ public ModifiableLong() { super(); } + public ModifiableLong(Long originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableLong(ModifiableLong other) { super(other); originalValue = other.originalValue; diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java index aff4554..f618ce7 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -23,6 +23,10 @@ public ModifiablePath() { super(); } + public ModifiablePath(String originalValue) { + super(originalValue); + } + public ModifiablePath(ModifiablePath other) { super(other); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index f492053..2676c99 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -23,6 +23,11 @@ public ModifiableByte() { super(); } + public ModifiableByte(Byte originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableByte(ModifiableByte other) { super(other); originalValue = other.originalValue; diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 6b9c33c..848b70a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -30,6 +30,11 @@ public ModifiableString() { super(); } + public ModifiableString(String originalValue) { + super(); + this.originalValue = originalValue; + } + public ModifiableString(ModifiableString other) { super(other); originalValue = other.originalValue; From e4237b528437b43838092022624e4e400f74bc03 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Wed, 18 Dec 2024 17:03:05 +0100 Subject: [PATCH 45/50] Add softlySetValue with alwaysSet option --- .../ModifiableVariableFactory.java | 126 ++++++++++++++++-- 1 file changed, 118 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java index 9e80039..3c0d2f1 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java @@ -53,7 +53,7 @@ public static ModifiablePath createPathModifiableVariable() { public static ModifiableBigInteger safelySetValue(ModifiableBigInteger mv, BigInteger value) { if (mv == null) { - mv = new ModifiableBigInteger(); + return new ModifiableBigInteger(value); } mv.setOriginalValue(value); return mv; @@ -72,9 +72,23 @@ public static ModifiableBigInteger softlySetValue(ModifiableBigInteger mv, BigIn return mv; } + /** + * Returns only a ModifiableBigInteger with the value, if the given mv is null or the original + * value of the mv is null or alwaysSet is true + */ + public static ModifiableBigInteger softlySetValue( + ModifiableBigInteger mv, BigInteger value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableBigInteger(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableString safelySetValue(ModifiableString mv, String value) { if (mv == null) { - mv = new ModifiableString(); + return new ModifiableString(value); } mv.setOriginalValue(value); return mv; @@ -93,9 +107,23 @@ public static ModifiableString softlySetValue(ModifiableString mv, String value) return mv; } + /** + * Returns only a ModifiableString with the value, if the given mv is null or the original value + * of the mv is null or alwaysSet is true + */ + public static ModifiableString softlySetValue( + ModifiableString mv, String value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableString(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableInteger safelySetValue(ModifiableInteger mv, Integer value) { if (mv == null) { - mv = new ModifiableInteger(); + return new ModifiableInteger(value); } mv.setOriginalValue(value); return mv; @@ -114,9 +142,23 @@ public static ModifiableInteger softlySetValue(ModifiableInteger mv, Integer val return mv; } + /** + * Returns only a ModifiableInteger with the value, if the given mv is null or the original + * value of the mv is null or alwaysSet is true + */ + public static ModifiableInteger softlySetValue( + ModifiableInteger mv, Integer value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableInteger(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableByte safelySetValue(ModifiableByte mv, Byte value) { if (mv == null) { - mv = new ModifiableByte(); + return new ModifiableByte(value); } mv.setOriginalValue(value); return mv; @@ -135,9 +177,22 @@ public static ModifiableByte softlySetValue(ModifiableByte mv, Byte value) { return mv; } + /** + * Returns only a ModifiableByte with the value, if the given mv is null or the original value + * of the mv is null or alwaysSet is true + */ + public static ModifiableByte softlySetValue(ModifiableByte mv, Byte value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableByte(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableByteArray safelySetValue(ModifiableByteArray mv, byte[] value) { if (mv == null) { - mv = new ModifiableByteArray(); + return new ModifiableByteArray(value); } mv.setOriginalValue(value); return mv; @@ -156,9 +211,23 @@ public static ModifiableByteArray softlySetValue(ModifiableByteArray mv, byte[] return mv; } + /** + * Returns only a ModifiableByteArray with the value, if the given mv is null or the original + * value of the mv is null or alwaysSet is true + */ + public static ModifiableByteArray softlySetValue( + ModifiableByteArray mv, byte[] value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableByteArray(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableLong safelySetValue(ModifiableLong mv, Long value) { if (mv == null) { - mv = new ModifiableLong(); + return new ModifiableLong(value); } mv.setOriginalValue(value); return mv; @@ -177,9 +246,22 @@ public static ModifiableLong softlySetValue(ModifiableLong mv, Long value) { return mv; } + /** + * Returns only a ModifiableLong with the value, if the given mv is null or the original value + * of the mv is null or alwaysSet is true + */ + public static ModifiableLong softlySetValue(ModifiableLong mv, Long value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableLong(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiableBoolean safelySetValue(ModifiableBoolean mv, Boolean value) { if (mv == null) { - mv = new ModifiableBoolean(); + return new ModifiableBoolean(value); } mv.setOriginalValue(value); return mv; @@ -198,9 +280,23 @@ public static ModifiableBoolean softlySetValue(ModifiableBoolean mv, Boolean val return mv; } + /** + * Returns only a ModifiableBoolean with the value, if the given mv is null or the original + * value of the mv is null or alwaysSet is true + */ + public static ModifiableBoolean softlySetValue( + ModifiableBoolean mv, Boolean value, boolean alwaysSet) { + if (mv == null) { + return new ModifiableBoolean(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + public static ModifiablePath safelySetValue(ModifiablePath mv, String value) { if (mv == null) { - mv = new ModifiablePath(); + return new ModifiablePath(value); } mv.setOriginalValue(value); return mv; @@ -219,6 +315,20 @@ public static ModifiablePath softlySetValue(ModifiablePath mv, String value) { return mv; } + /** + * Returns only a ModifiablePath with the value, if the given mv is null or the original value + * of the mv is null or alwaysSet is true + */ + public static ModifiablePath softlySetValue( + ModifiablePath mv, String value, boolean alwaysSet) { + if (mv == null) { + return new ModifiablePath(value); + } else if (alwaysSet || mv.getOriginalValue() == null) { + mv.setOriginalValue(value); + } + return mv; + } + private ModifiableVariableFactory() { super(); } From 8684f65b4b29493d2536d18c91d66bdabfd650f6 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Fri, 20 Dec 2024 14:43:17 +0100 Subject: [PATCH 46/50] Rename createRandomModification to setRandomModification, and make it public. --- .../de/rub/nds/modifiablevariable/ModifiableVariable.java | 7 ++++--- .../biginteger/ModifiableBigInteger.java | 2 +- .../rub/nds/modifiablevariable/bool/ModifiableBoolean.java | 2 +- .../modifiablevariable/bytearray/ModifiableByteArray.java | 2 +- .../nds/modifiablevariable/integer/ModifiableInteger.java | 2 +- .../rub/nds/modifiablevariable/longint/ModifiableLong.java | 2 +- .../de/rub/nds/modifiablevariable/path/ModifiablePath.java | 2 +- .../nds/modifiablevariable/singlebyte/ModifiableByte.java | 2 +- .../nds/modifiablevariable/string/ModifiableString.java | 2 +- .../biginteger/ModifiableBigIntegerTest.java | 2 +- .../nds/modifiablevariable/bool/ModifiableBooleanTest.java | 2 +- .../modifiablevariable/integer/ModifiableIntegerTest.java | 6 +++--- .../nds/modifiablevariable/mlong/ModifiableLongTest.java | 2 +- .../modifiablevariable/singlebyte/ModifiableByteTest.java | 2 +- 14 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java index 1cdafd3..d9ad5ae 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java @@ -250,7 +250,7 @@ public LinkedList> getModifications() { public E getValue() { if (Objects.equals(createRandomModification, Boolean.TRUE)) { - createRandomModification(); + setRandomModification(); createRandomModification = false; } @@ -286,9 +286,10 @@ public void reduceToOriginalValue(boolean evenWithNullOriginalValue) { public abstract void setOriginalValue(E originalValue); - protected abstract void createRandomModification(); + /** Set a single random modification, all previously set modifications are removed */ + public abstract void setRandomModification(); - protected abstract ModifiableVariable createCopy(); + public abstract ModifiableVariable createCopy(); public void createRandomModificationAtRuntime() { createRandomModification = true; diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java index b801daa..0788cdc 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigInteger.java @@ -41,7 +41,7 @@ public ModifiableBigInteger createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = BigIntegerModificationFactory.createRandomModification(); setModification(vm); diff --git a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java index 0db7a52..b6c2e97 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bool/ModifiableBoolean.java @@ -49,7 +49,7 @@ public void setOriginalValue(Boolean originalValue) { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = BooleanModificationFactory.createRandomModification(); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java index cdcfbcc..9601e69 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArray.java @@ -44,7 +44,7 @@ public ModifiableByteArray createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = ByteArrayModificationFactory.createRandomModification(originalValue); setModification(vm); diff --git a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java index 11189a9..d9612ec 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java +++ b/src/main/java/de/rub/nds/modifiablevariable/integer/ModifiableInteger.java @@ -40,7 +40,7 @@ public ModifiableInteger createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = IntegerModificationFactory.createRandomModification(); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java index b5cc778..44c233a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java +++ b/src/main/java/de/rub/nds/modifiablevariable/longint/ModifiableLong.java @@ -40,7 +40,7 @@ public ModifiableLong createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = LongModificationFactory.createRandomModification(); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java index f618ce7..b3566ea 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java +++ b/src/main/java/de/rub/nds/modifiablevariable/path/ModifiablePath.java @@ -37,7 +37,7 @@ public ModifiablePath createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = PathModificationFactory.createRandomModification(null); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java index 2676c99..ee54327 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java +++ b/src/main/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByte.java @@ -39,7 +39,7 @@ public ModifiableByte createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = ByteModificationFactory.createRandomModification(); setModification(vm); } diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java index 848b70a..fd18bbb 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -46,7 +46,7 @@ public ModifiableString createCopy() { } @Override - protected void createRandomModification() { + public void setRandomModification() { VariableModification vm = StringModificationFactory.createRandomModification(null); setModification(vm); } diff --git a/src/test/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigIntegerTest.java b/src/test/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigIntegerTest.java index 2c39103..620d291 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigIntegerTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/biginteger/ModifiableBigIntegerTest.java @@ -32,7 +32,7 @@ public void setUp() { /** Test of createRandomModification method, of class ModifiableBigInteger. */ @Disabled("Not yet implemented") @Test - public void testCreateRandomModification() {} + public void testSetRandomModification() {} /** Test of getAssertEquals method, of class ModifiableBigInteger. */ @Disabled("Not yet implemented") diff --git a/src/test/java/de/rub/nds/modifiablevariable/bool/ModifiableBooleanTest.java b/src/test/java/de/rub/nds/modifiablevariable/bool/ModifiableBooleanTest.java index c95fc2c..994b489 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bool/ModifiableBooleanTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bool/ModifiableBooleanTest.java @@ -41,7 +41,7 @@ public void testSetOriginalValue() {} /** Test of createRandomModification method, of class ModifiableBoolean. */ @Disabled("Not yet implemented") @Test - public void testCreateRandomModification() {} + public void testSetRandomModification() {} /** Test of isOriginalValueModified method, of class ModifiableBoolean. */ @Disabled("Not yet implemented") diff --git a/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java b/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java index a92f59a..adc5360 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/integer/ModifiableIntegerTest.java @@ -28,9 +28,9 @@ public void setUp() { /** Test of createRandomModification method, of class ModifiableInteger. */ @Test - public void testCreateRandomModification() { + public void testSetRandomModification() { assertNull(integer1.getModification()); - integer1.createRandomModification(); + integer1.setRandomModification(); assertNotNull(integer1.getModification()); } @@ -53,7 +53,7 @@ public void testSetAssertEquals() { @Test public void testIsOriginalValueModified() { assertFalse(integer1.isOriginalValueModified()); - integer1.createRandomModification(); + integer1.setRandomModification(); assertTrue(integer1.isOriginalValueModified()); } diff --git a/src/test/java/de/rub/nds/modifiablevariable/mlong/ModifiableLongTest.java b/src/test/java/de/rub/nds/modifiablevariable/mlong/ModifiableLongTest.java index f16d641..7c53baa 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/mlong/ModifiableLongTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/mlong/ModifiableLongTest.java @@ -32,7 +32,7 @@ public void setUp() { /** Test of createRandomModification method, of class ModifiableLong. */ @Disabled("Not yet implemented") @Test - public void testCreateRandomModification() {} + public void testSetRandomModification() {} /** Test of getAssertEquals method, of class ModifiableLong. */ @Disabled("Not yet implemented") diff --git a/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByteTest.java b/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByteTest.java index 173aef2..0bf0fff 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByteTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/singlebyte/ModifiableByteTest.java @@ -30,7 +30,7 @@ public void setUp() { /** Test of createRandomModification method, of class ModifiableByte. */ @Disabled("Not yet implemented") @Test - public void testCreateRandomModification() {} + public void testSetRandomModification() {} /** Test of getAssertEquals method, of class ModifiableByte. */ @Disabled("Not yet implemented") From ff01b27c22d1f40255240364797d795541ae2a6d Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 30 Dec 2024 19:06:28 +0100 Subject: [PATCH 47/50] Rename longToUint64Bytes to longToEightBytes since it can also be used to convert long to int64, this sounds more general. Also renamed longToUint48Bytes to longToSixBytes and longToUint32Bytes to intToFourBytes. Added helper methods: eigthBytesToLong and fourBytesToInt --- .../util/ArrayConverter.java | 79 +++++++++++-------- .../util/ArrayConverterTest.java | 10 +-- 2 files changed, 51 insertions(+), 38 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java index 799c741..731c951 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java @@ -23,37 +23,67 @@ private ArrayConverter() { * Takes a long value and converts it to 8 bytes (needed for example to convert SQN numbers in * TLS records) * - * @param l long value + * @param value long value * @return long represented by 8 bytes */ - public static byte[] longToUint64Bytes(long l) { + public static byte[] longToEightBytes(long value) { byte[] result = new byte[8]; - result[0] = (byte) (l >>> 56); - result[1] = (byte) (l >>> 48); - result[2] = (byte) (l >>> 40); - result[3] = (byte) (l >>> 32); - result[4] = (byte) (l >>> 24); - result[5] = (byte) (l >>> 16); - result[6] = (byte) (l >>> 8); - result[7] = (byte) l; + result[0] = (byte) (value >>> 56); + result[1] = (byte) (value >>> 48); + result[2] = (byte) (value >>> 40); + result[3] = (byte) (value >>> 32); + result[4] = (byte) (value >>> 24); + result[5] = (byte) (value >>> 16); + result[6] = (byte) (value >>> 8); + result[7] = (byte) value; return result; } + /** Note: This will truncate the long */ + public static byte[] longToSixBytes(long value) { + byte[] output = new byte[6]; + output[0] = (byte) (value >>> 40); + output[1] = (byte) (value >>> 32); + output[2] = (byte) (value >>> 24); + output[3] = (byte) (value >>> 16); + output[4] = (byte) (value >>> 8); + output[5] = (byte) value; + return output; + } + /** - * Takes a long value and converts it to 4 bytes + * Takes an int value and converts it to 4 bytes * - * @param l long value - * @return long represented by 4 bytes + * @param value int value + * @return int represented by 4 bytes */ - public static byte[] longToUint32Bytes(long l) { + public static byte[] intToFourBytes(int value) { byte[] result = new byte[4]; - result[0] = (byte) (l >>> 24); - result[1] = (byte) (l >>> 16); - result[2] = (byte) (l >>> 8); - result[3] = (byte) l; + result[0] = (byte) (value >>> 24); + result[1] = (byte) (value >>> 16); + result[2] = (byte) (value >>> 8); + result[3] = (byte) value; return result; } + public static long eigthBytesToLong(byte[] bytes) { + return (long) (bytes[0] & 0xFF) << 56 + | (long) (bytes[1] & 0xFF) << 48 + | (long) (bytes[2] & 0xFF) << 40 + | (long) (bytes[3] & 0xFF) << 32 + | (long) (bytes[4] & 0xFF) << 24 + | (long) (bytes[5] & 0xFF) << 16 + | (long) (bytes[6] & 0xFF) << 8 + | (long) (bytes[7] & 0xFF); + } + + public static long fourBytesToInt(byte[] bytes) { + return (long) (bytes[4] & 0xFF) << 24 + | (long) (bytes[5] & 0xFF) << 16 + | (long) (bytes[6] & 0xFF) << 8 + | (long) (bytes[7] & 0xFF); + } + /** * Takes an integer value and stores its last bytes into a byte array * @@ -386,19 +416,6 @@ public static byte[] bigIntegerToNullPaddedByteArray(BigInteger input, int outpu return output; } - public static byte[] longToUint48Bytes(long input) { - byte[] output = new byte[6]; - - output[0] = (byte) (input >>> 40); - output[1] = (byte) (input >>> 32); - output[2] = (byte) (input >>> 24); - output[3] = (byte) (input >>> 16); - output[4] = (byte) (input >>> 8); - output[5] = (byte) input; - - return output; - } - /** * Reverses the order of a byte array: So, [0x00,0x01,0x02,0x03] will be returned as * [0x03,0x02,0x01,0x00] diff --git a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java index 429e68d..7cf5d20 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java @@ -228,22 +228,18 @@ public void testBigIntegerToNullPaddedByteArray() { } @Test - public void testLongToUint48Bytes() { + public void testLongToSixBytes() { long testValue = 0x0000123456789ABCL; byte[] expectedResult = ArrayConverter.hexStringToByteArray("123456789ABC"); assertArrayEquals( - expectedResult, - ArrayConverter.longToUint48Bytes(testValue), - "Assert correct output"); + expectedResult, ArrayConverter.longToSixBytes(testValue), "Assert correct output"); testValue = 0x0000000000000001L; expectedResult = ArrayConverter.hexStringToByteArray("000000000001"); assertArrayEquals( - expectedResult, - ArrayConverter.longToUint48Bytes(testValue), - "Assert correct output"); + expectedResult, ArrayConverter.longToSixBytes(testValue), "Assert correct output"); } /** From c0fb8253e1782c66237bc4c13caaff29e0aeff60 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 30 Dec 2024 19:07:58 +0100 Subject: [PATCH 48/50] run linter --- .../util/ArrayConverterTest.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java index 7cf5d20..b9568e1 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/util/ArrayConverterTest.java @@ -7,8 +7,7 @@ */ package de.rub.nds.modifiablevariable.util; -import static org.junit.jupiter.api.Assertions.assertArrayEquals; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.*; import de.rub.nds.modifiablevariable.ModifiableVariableFactory; import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray; @@ -98,7 +97,7 @@ public void testBytesToLong() { /** Test of bytesToHexString method, of class ArrayConverter. */ @Test public void testBytesToHexString_byteArr() { - byte[] toTest = new byte[] {0x00, 0x11, 0x22, 0x33, 0x44}; + byte[] toTest = {0x00, 0x11, 0x22, 0x33, 0x44}; assertEquals("00 11 22 33 44", ArrayConverter.bytesToHexString(toTest)); toTest = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; assertEquals("00 01 02 03 04 05 06 07 08", ArrayConverter.bytesToHexString(toTest)); @@ -126,12 +125,11 @@ public void testBytesToHexString_byteArr() { /** Test of bytesToHexString method, of class ArrayConverter. */ @Test public void testBytesToHexString_byteArr_boolean() { - byte[] toTest = - new byte[] { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 - }; + byte[] toTest = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 + }; assertEquals( "00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07", ArrayConverter.bytesToHexString(toTest, false)); @@ -148,12 +146,11 @@ public void testBytesToHexString_3args() {} /** Test ArrayConverter.bytesToRawHexString(). */ @Test public void testBytesToRawHexString() { - byte[] toTest = - new byte[] { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, - 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 - }; + byte[] toTest = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, + 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 + }; assertEquals( "0001020304050607000102030405060700010203040506070001020304050607", ArrayConverter.bytesToRawHexString(toTest)); @@ -294,7 +291,7 @@ public void testBytesToHexString_ModifiableByteArray() { /** Test of reverseByteOrder method, of class ArrayConverter. */ @Test public void testReverseByteOrder() { - byte[] array = new byte[] {0x00, 0x01, 0x02, 0x03, 0x04}; + byte[] array = {0x00, 0x01, 0x02, 0x03, 0x04}; assertArrayEquals( new byte[] {0x04, 0x03, 0x02, 0x01, 0x00}, @@ -333,7 +330,7 @@ public void testIndexOf() { byte[] innerArray3 = ArrayConverter.hexStringToByteArray("FF"); assertEquals(1, ArrayConverter.indexOf(outerArray, innerArray1)); - assertEquals(null, ArrayConverter.indexOf(outerArray, innerArray2)); - assertEquals(null, ArrayConverter.indexOf(outerArray, innerArray3)); + assertNull(ArrayConverter.indexOf(outerArray, innerArray2)); + assertNull(ArrayConverter.indexOf(outerArray, innerArray3)); } } From 2ca2f90f2eda910367dd8458d2ef244975616626 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 30 Dec 2024 19:11:03 +0100 Subject: [PATCH 49/50] Fix fourBytesToInt --- .../nds/modifiablevariable/util/ArrayConverter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java index 731c951..ded589a 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java @@ -77,11 +77,11 @@ public static long eigthBytesToLong(byte[] bytes) { | (long) (bytes[7] & 0xFF); } - public static long fourBytesToInt(byte[] bytes) { - return (long) (bytes[4] & 0xFF) << 24 - | (long) (bytes[5] & 0xFF) << 16 - | (long) (bytes[6] & 0xFF) << 8 - | (long) (bytes[7] & 0xFF); + public static int fourBytesToInt(byte[] bytes) { + return (bytes[4] & 0xFF) << 24 + | (bytes[5] & 0xFF) << 16 + | (bytes[6] & 0xFF) << 8 + | bytes[7] & 0xFF; } /** From 01f2f20e6cba66c4c83c6c9b41eb14a154097295 Mon Sep 17 00:00:00 2001 From: c0d3d3v Date: Mon, 30 Dec 2024 19:46:32 +0100 Subject: [PATCH 50/50] Fix fourBytesToInt but for real -.- --- .../rub/nds/modifiablevariable/util/ArrayConverter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java index ded589a..7077f9b 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java +++ b/src/main/java/de/rub/nds/modifiablevariable/util/ArrayConverter.java @@ -78,10 +78,10 @@ public static long eigthBytesToLong(byte[] bytes) { } public static int fourBytesToInt(byte[] bytes) { - return (bytes[4] & 0xFF) << 24 - | (bytes[5] & 0xFF) << 16 - | (bytes[6] & 0xFF) << 8 - | bytes[7] & 0xFF; + return (bytes[0] & 0xFF) << 24 + | (bytes[1] & 0xFF) << 16 + | (bytes[2] & 0xFF) << 8 + | bytes[3] & 0xFF; } /**