-
Notifications
You must be signed in to change notification settings - Fork 140
Modifiable Variables
Modifiable variable allows one to set modifications to basic types, e.g. Integers, and modify their values by executing their getter methods.
The best way to present the functionality of this concept is by means of a simple example:
ModifiableInteger i = new ModifiableInteger();
i.setOriginalValue(30);
i.setModification(new AddModification(20));
System.out.println(i.getValue()); // 50
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.
You can see further details to the ModifiableVariables concept at //TODO REF
If you use a modifiable variable in your Java code, use the modification factories, e.g.:
VariableModification<Integer> modifier = IntegerModificationFactory.explicitValue(7);
VariableModification<BigInteger> modifier = BigIntegerModificationFactory.add(BigInteger.ONE);
VariableModification<byte[]> modifier = ByteArrayModificationFactory.xor(modification1, 0);
VariableModification<byte[]> modifier = ByteArrayModificationFactory.insert(modification1, 0);
Thanks to serialization, you can also use the same concept of modifiable variables directly from XML. This helps you to create modifications in TLS messages and records, e.g.:
<Heartbeat>
<messageIssuer>CLIENT</messageIssuer>
<payloadLength>
<integerAddModification>
<summand>2000</summand>
</integerAddModification>
</payloadLength>
</Heartbeat>
The following examples should give you a useful list of modifiable variables:
- Explicit value:
<integerExplicitValueModification>
<explicitValue>25872</explicitValue>
</integerExplicitValueModification>
- Subtract:
<integerSubtractModification>
<subtrahend>30959</subtrahend>
</integerSubtractModification>
- Add:
<integerAddModification>
<summand>960</summand>
</integerAddModification>
- Right shift:
<integerShiftRightModification>
<shift>13</shift>
</integerShiftRightModification>
- XOR:
<integerXorModification>
<xor>22061</xor>
</integerXorModification>
You can use the same operations for BigInteger data types, for example:
<bigIntegerAddModification>
<summand>1</summand>
</bigIntegerAddModification>
- Explicit value:
<byteArrayExplicitValueModification>
<explicitValue>
4F 3F 8C FC 17 8E 66 0A 53 DF 4D 4E E9 0B D0 B3
02 79 74 1F 8B 8A F6 D0 1E AC 59 53 7B 87 DE 89
C4 13 28 69 3C 18 F8 3A C7 3E 30 44 C9 61 D4
</explicitValue>
</byteArrayExplicitValueModification>
- XOR:
<byteArrayXorModification>
<xor>11 22</xor>
<startPosition>1</startPosition>
</byteArrayXorModification>
Here, we XOR the original value with the xor value, starting with the startPosition:
- Insert:
<byteArrayInsertModification>
<bytesToInsert>
3D 9F 3B 77 65 03 F9 8A 93 6D 94 CD 7E 4A C5 1B
</bytesToInsert>
<startPosition>0</startPosition>
</byteArrayInsertModification>
- Delete:
<byteArrayDeleteModification>
<count>2</count>
<startPosition>0</startPosition>
</byteArrayDeleteModification>
- Shuffle:
<byteArrayShuffleModification>
<shuffle>
05 01 02 03
</shuffle>
</byteArrayDeleteModification>
- Duplicate:
<byteArrayDuplicateModification/>
- Explicit value:
<byteExplicitValueModification>
<explicitValue>
4F
</explicitValue>
</byteExplicitValueModification>
- XOR:
<byteXorModification>
<xor>01</xor>
</byteXorModification>
- Add:
<byteAddModification>
<summand>01</summand>
</byteAddModification>
- Subtract:
<byteSubtractModification>
<subtrahend>01</subtrahend>
</byteSubtractModification>
- Explicit:
<stringExplicitValueModification>
<explicitValue>replacedString</explicitValue>
</stringExplicitValueModification>