Skip to content

Commit aba5edf

Browse files
committed
Merge modifiedCopy into prettyXml2
2 parents 594d522 + bc8de54 commit aba5edf

File tree

89 files changed

+1867
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1867
-460
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ release.properties
77
dependency-reduced-pom.xml
88
buildNumber.properties
99
.mvn/timing.properties
10+
/nbproject/

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ sudo: false
44

55
jdk:
66
- oraclejdk8
7-
- oraclejdk7
87
- openjdk7
8+
- openjdk8
99

1010
#branches:
1111
# only:
1212
# - master
13+
install: mvn install
1314

1415
notifications:
1516
email:
1617
recipients:
1718
18-
19+

README.md

Lines changed: 114 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,98 @@ The best way to present the functionality of this concept is by means of a simpl
1010
```java
1111
ModifiableInteger i = new ModifiableInteger();
1212
i.setOriginalValue(30);
13-
i.setModification(new AddModification(20));
13+
VariableModification<Integer> modifier = IntegerModificationFactory.add(20);
14+
i.setModification(modifier);
1415
System.out.println(i.getValue()); // 50
1516
```
1617

1718
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.
1819

1920
You can use further modifications to an integer value, for example subtract, xor or shift.
2021

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:
2353
```java
2454
VariableModification<Integer> modifier = IntegerModificationFactory.explicitValue(7);
2555
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);
2857
```
2958

3059
# 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+
3287
```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>
39102
```
40103

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:
42105

43106
## Integer
44107
- Explicit value:
@@ -69,6 +132,13 @@ The following examples should give you a useful list of modifiable variables:
69132
</integerShiftRightModification>
70133
```
71134

135+
- Left shift:
136+
```xml
137+
<integerShiftLeftModification>
138+
<shift>13</shift>
139+
</integerShiftLeftModification>
140+
```
141+
72142
- XOR:
73143
```xml
74144
<integerXorModification>
@@ -82,15 +152,14 @@ You can use the same operations for BigInteger data types, for example:
82152
<summand>1</summand>
83153
</bigIntegerAddModification>
84154
```
155+
ModifiableLong and ModifiableBytes support the following operations: add, explicitValue, subtract, xor
85156

86-
## Byte Arrays
157+
## Byte Array
87158
- Explicit value:
88159
```xml
89160
<byteArrayExplicitValueModification>
90161
<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
94163
</explicitValue>
95164
</byteArrayExplicitValueModification>
96165
```
@@ -102,7 +171,6 @@ You can use the same operations for BigInteger data types, for example:
102171
<startPosition>1</startPosition>
103172
</byteArrayXorModification>
104173
```
105-
Here, we XOR the original value with the xor value, starting with the startPosition:
106174

107175
- Insert:
108176
```xml
@@ -121,3 +189,31 @@ Here, we XOR the original value with the xor value, starting with the startPosit
121189
<startPosition>0</startPosition>
122190
</byteArrayDeleteModification>
123191
```
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+
```

pom.xml

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>de.rub.nds</groupId>
55
<artifactId>ModifiableVariable</artifactId>
6-
<version>2.0</version>
6+
<version>2.3</version>
77
<packaging>jar</packaging>
88

9-
<name>${project.groupId}:${project.artifactId}</name>
9+
<name>ModifiableVariable</name>
1010
<description>A Modifiable Variable concept allows for easy runtime modifications of basic data types like integers, booleans, or byte arrays</description>
1111
<url>https://github.com/RUB-NDS/ModifiableVariable</url>
1212

@@ -17,6 +17,17 @@
1717
<distribution>repo</distribution>
1818
</license>
1919
</licenses>
20+
21+
<distributionManagement>
22+
<snapshotRepository>
23+
<id>ossrh</id>
24+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
25+
</snapshotRepository>
26+
<repository>
27+
<id>ossrh</id>
28+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
29+
</repository>
30+
</distributionManagement>
2031

2132
<developers>
2233
<developer>
@@ -44,6 +55,7 @@
4455
</developer>
4556
</developers>
4657

58+
<!-- Information to version control system -->
4759
<scm>
4860
<connection>scm:git:git://github.com/RUB-NDS/ModifiableVariable.git</connection>
4961
<developerConnection>scm:git:ssh://github.com/RUB-NDS/ModifiableVariable.git</developerConnection>
@@ -87,12 +99,71 @@
8799
</execution>
88100
</executions>
89101
</plugin>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-source-plugin</artifactId>
105+
<version>3.0.1</version>
106+
<executions>
107+
<execution>
108+
<id>attach-sources</id>
109+
<goals>
110+
<goal>jar-no-fork</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-javadoc-plugin</artifactId>
118+
<version>2.10.4</version>
119+
<executions>
120+
<execution>
121+
<id>attach-javadocs</id>
122+
<goals>
123+
<goal>jar</goal>
124+
</goals>
125+
</execution>
126+
</executions>
127+
</plugin>
128+
<plugin>
129+
<groupId>org.apache.maven.plugins</groupId>
130+
<artifactId>maven-gpg-plugin</artifactId>
131+
<version>1.6</version>
132+
<executions>
133+
<execution>
134+
<id>sign-artifacts</id>
135+
<phase>verify</phase>
136+
<goals>
137+
<goal>sign</goal>
138+
</goals>
139+
</execution>
140+
</executions>
141+
<configuration>
142+
<skip>${skip.signature}</skip>
143+
</configuration>
144+
</plugin>
145+
<plugin>
146+
<groupId>org.sonatype.plugins</groupId>
147+
<artifactId>nexus-staging-maven-plugin</artifactId>
148+
<version>1.6.8</version>
149+
<extensions>true</extensions>
150+
<configuration>
151+
<serverId>ossrh</serverId>
152+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
153+
<!-- deploy with the following command: mvn nexus-staging:release -->
154+
<autoReleaseAfterClose>false</autoReleaseAfterClose>
155+
</configuration>
156+
</plugin>
90157
</plugins>
91158
</build>
159+
92160
<properties>
93161
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
94162
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
95163
<maven.compiler.source>1.7</maven.compiler.source>
96164
<maven.compiler.target>1.7</maven.compiler.target>
165+
<!-- We redefine the signature generation process, whic is enabled by default,
166+
but cannot be performed by typical users. Enable it using -Dskip.signature=false -->
167+
<skip.signature>true</skip.signature>
97168
</properties>
98169
</project>

src/main/java/de/rub/nds/modifiablevariable/FileConfigurationException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
*/
99
package de.rub.nds.modifiablevariable;
1010

11-
/**
12-
*
13-
* @author Juraj Somorovsky - [email protected]
14-
*/
1511
public class FileConfigurationException extends RuntimeException {
1612

1713
public FileConfigurationException() {

src/main/java/de/rub/nds/modifiablevariable/HoldsModifiableVariable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Annotation interface for modifiable variables holders. A modifiable variable
1818
* holder is for example a TLS protocol message.
1919
*
20-
* @author Juraj Somorovsky - [email protected]
2120
*/
2221
@Target(ElementType.FIELD)
2322
@Retention(RetentionPolicy.RUNTIME)

src/main/java/de/rub/nds/modifiablevariable/ModifiableVariable.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
package de.rub.nds.modifiablevariable;
1010

11+
import java.io.Serializable;
1112
import javax.xml.bind.annotation.XmlAnyElement;
1213
import javax.xml.bind.annotation.XmlRootElement;
1314
import javax.xml.bind.annotation.XmlTransient;
@@ -20,12 +21,10 @@
2021
* subclasses, see:
2122
* http://blog.bdoughan.com/2011/06/ignoring-inheritance-with-xmltransient.html
2223
*
23-
* @author Juraj Somorovsky <[email protected]>
24-
* @param <E>
2524
*/
2625
@XmlRootElement
2726
@XmlTransient
28-
public abstract class ModifiableVariable<E> {
27+
public abstract class ModifiableVariable<E> implements Serializable {
2928

3029
private VariableModification<E> modification = null;
3130

@@ -75,4 +74,8 @@ public void createRandomModificationAtRuntime() {
7574
public boolean containsAssertion() {
7675
return (assertEquals != null);
7776
}
77+
78+
public boolean isCreateRandomModification() {
79+
return createRandomModification;
80+
}
7881
}

0 commit comments

Comments
 (0)