@@ -10,35 +10,98 @@ The best way to present the functionality of this concept is by means of a simpl
10
10
``` java
11
11
ModifiableInteger i = new ModifiableInteger ();
12
12
i. setOriginalValue(30 );
13
- i. setModification(new AddModification (20 ));
13
+ VariableModification<Integer > modifier = IntegerModificationFactory . add(20 );
14
+ i. setModification(modifier);
14
15
System . out. println(i. getValue()); // 50
15
16
```
16
17
17
18
In this example, we defined a new ModifiableInteger and set its value to 30. Next, we defined a new modification AddModification which simply returns a sum of two integers. We set its value to 20. If we execute the above program, the result 50 is printed.
18
19
19
20
You can use further modifications to an integer value, for example subtract, xor or shift.
20
21
21
- # Modifiable variables in Java
22
- If you use a modifiable variable in your Java code, use the modification factories, for example:
22
+ In byte arrays you can use further modifications like shuffling or inserting bytes:
23
+
24
+ ``` java
25
+ ModifiableByteArray ba = new ModifiableByteArray ();
26
+ VariableModification<byte[]> modifier = ByteArrayModificationFactory . insert(new byte [] {2 , 3 }, 1 );
27
+ ba. setOriginalValue(new byte []{1 , 4 });
28
+ ba. setModification(modifier);
29
+ System . out. println(ArrayConverter . bytesToHexString(ba)); // 01 02 03 04
30
+ ```
31
+
32
+ If you want to use modifiable variables in your maven projects, you can include the following dependency in your pom file:
33
+ ``` xml
34
+ <dependency >
35
+ <groupId >de.rub.nds</groupId >
36
+ <artifactId >ModifiableVariable</artifactId >
37
+ <version >2.2</version >
38
+ </dependency >
39
+ ```
40
+
41
+ # Supported data types
42
+ The following modifiable variables are provided in this package with their modifications:
43
+ * ModifiableBigInteger: add, explicitValue, shiftLeft, shiftRight, subtract, xor
44
+ * ModifiableBoolean: explicitValue, toogle
45
+ * ModifiableByteArray: delete, duplicate, explicitValue, insert, suffle, xor
46
+ * ModifiableInteger: add, explicitValue, shiftLeft, shiftRight, subtract, xor
47
+ * ModifiableLong: add, explicitValue, subtract, xor
48
+ * ModifiableByte: add, explicitValue, subtract, xor
49
+ * ModifiableString: explicitValue
50
+
51
+ # Creating modifications
52
+ If you use a modifiable variables in your Java code, use the modification factories, for example:
23
53
``` java
24
54
VariableModification<Integer > modifier = IntegerModificationFactory . explicitValue(7 );
25
55
VariableModification<BigInteger > modifier = BigIntegerModificationFactory . add(BigInteger . ONE );
26
- VariableModification<byte[]> modifier = ByteArrayModificationFactory . xor(modification, 0 );
27
- VariableModification<byte[]> modifier = ByteArrayModificationFactory . insert(modification, 0 );
56
+ VariableModification<byte[]> modifier = ByteArrayModificationFactory . xor(new byte [] {2 , 3 }, 0 );
28
57
```
29
58
30
59
# Modifiable variables in XML
31
- Modifiable variables are serializable with JAXB into XML.
60
+ Modifiable variables are serializable with JAXB into XML. You can use the following code to do that:
61
+
62
+ ``` java
63
+ ModifiableByteArray mba = new ModifiableByteArray ();
64
+ mba. setOriginalValue(new byte []{1 , 2 , 3 });
65
+ StringWriter writer = new StringWriter ();
66
+
67
+ // we have to create a jaxb context a put there all the classes we are going to use for serialization
68
+ JAXBContext context = JAXBContext . newInstance(ModifiableByteArray . class, ByteArrayDeleteModification . class,
69
+ ByteArrayExplicitValueModification . class, ByteArrayInsertModification . class,
70
+ ByteArrayXorModification . class);
71
+ Marshaller m = context. createMarshaller();
72
+ m. setProperty(Marshaller . JAXB_FORMATTED_OUTPUT , true );
73
+
74
+ // we marshall the array into xml
75
+ m. marshal(mba, writer);
76
+ String xmlString = writer. toString();
77
+ System . out. println(xmlString);
78
+
79
+ // we can use the xml to create a modifiable byte array variable again
80
+ Unmarshaller um = context. createUnmarshaller();
81
+ ModifiableByteArray test = (ModifiableByteArray ) um. unmarshal(new StringReader (xmlString));
82
+ System . out. println(ArrayConverter . bytesToHexString(test));
83
+ ```
84
+
85
+ The result of the serialized modifiable byte array looks as follows:
86
+
32
87
``` xml
33
- <SomeVariable >
34
- <integerAddModification >
35
- <summand >2000</summand >
36
- </integerAddModification >
37
- </SomeVariable >
38
-
88
+ <modifiableByteArray >
89
+ <originalValue >01 02 03</originalValue >
90
+ </modifiableByteArray >
91
+ ```
92
+
93
+ If you would use modification from the previous example, the result would look as follows:
94
+ ``` xml
95
+ <modifiableByteArray >
96
+ <originalValue >01 02 03</originalValue >
97
+ <byteArrayInsertModification >
98
+ <bytesToInsert >02 03</bytesToInsert >
99
+ <startPosition >1</startPosition >
100
+ </byteArrayInsertModification >
101
+ </modifiableByteArray >
39
102
```
40
103
41
- The following examples should give you a useful list of modifiable variables:
104
+ The following examples should give you a useful list of modifications in modifiable variables:
42
105
43
106
## Integer
44
107
- Explicit value:
@@ -69,6 +132,13 @@ The following examples should give you a useful list of modifiable variables:
69
132
</integerShiftRightModification >
70
133
```
71
134
135
+ - Left shift:
136
+ ``` xml
137
+ <integerShiftLeftModification >
138
+ <shift >13</shift >
139
+ </integerShiftLeftModification >
140
+ ```
141
+
72
142
- XOR:
73
143
``` xml
74
144
<integerXorModification >
@@ -82,15 +152,14 @@ You can use the same operations for BigInteger data types, for example:
82
152
<summand >1</summand >
83
153
</bigIntegerAddModification >
84
154
```
155
+ ModifiableLong and ModifiableBytes support the following operations: add, explicitValue, subtract, xor
85
156
86
- ## Byte Arrays
157
+ ## Byte Array
87
158
- Explicit value:
88
159
``` xml
89
160
<byteArrayExplicitValueModification >
90
161
<explicitValue >
91
- 4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0 B3
92
- 02 79 74 1F 8B 8A F6 D0 1E AC 59 53 7B 87 DE 89
93
- C4 13 28 69 3C 18 F8 3A C7 3E 30 44 C9 61 D4
162
+ 4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0
94
163
</explicitValue >
95
164
</byteArrayExplicitValueModification >
96
165
```
@@ -102,7 +171,6 @@ You can use the same operations for BigInteger data types, for example:
102
171
<startPosition >1</startPosition >
103
172
</byteArrayXorModification >
104
173
```
105
- Here, we XOR the original value with the xor value, starting with the startPosition:
106
174
107
175
- Insert:
108
176
``` xml
@@ -121,3 +189,31 @@ Here, we XOR the original value with the xor value, starting with the startPosit
121
189
<startPosition >0</startPosition >
122
190
</byteArrayDeleteModification >
123
191
```
192
+
193
+ - Shuffle:
194
+ ``` xml
195
+ <byteArrayShuffleModification >
196
+ <shuffle >02 03</shuffle >
197
+ </byteArrayShuffleModification >
198
+ ```
199
+
200
+ # Boolean
201
+ - Explicit value:
202
+ ``` xml
203
+ <booleanExplicitValueModification >
204
+ <explicitValue >true</explicitValue >
205
+ </booleanExplicitValueModification >
206
+ ```
207
+
208
+ - Toogle:
209
+ ``` xml
210
+ <booleanToogleModification />
211
+ ```
212
+
213
+ # String
214
+ - Explicit value:
215
+ ``` xml
216
+ <stringExplicitValueModification >
217
+ <explicitValue >abc</explicitValue >
218
+ </stringExplicitValueModification >
219
+ ```
0 commit comments