Skip to content

Pretty xml #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.rub.nds</groupId>
<artifactId>ModifiableVariable</artifactId>
<version>2.2</version>
<version>2.3</version>
<packaging>jar</packaging>

<name>ModifiableVariable</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public E modify(E input) {

protected abstract E modifyImplementationHook(E input);

public abstract VariableModification<E> getModifiedCopy();

/**
* Debugging modified variables. Getting stack trace can be time consuming,
* thus we use isDebugEnabled() function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "summand", "modificationFilter", "postModification" })
public class BigIntegerAddModification extends VariableModification<BigInteger> {

private final static int MAX_ADD_LENGTH = 8;

private BigInteger summand;

public BigIntegerAddModification() {
Expand All @@ -39,4 +42,9 @@ public BigInteger getSummand() {
public void setSummand(BigInteger summand) {
this.summand = summand;
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
return new BigIntegerAddModification(summand.add(new BigInteger(MAX_ADD_LENGTH, new Random())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
public class BigIntegerExplicitValueModification extends VariableModification<BigInteger> {

private final static int MAX_EXPLICIT_LENGTH = 8;

private BigInteger explicitValue;

public BigIntegerExplicitValueModification() {
Expand All @@ -38,4 +41,15 @@ public BigInteger getExplicitValue() {
public void setExplicitValue(BigInteger explicitValue) {
this.explicitValue = explicitValue;
}
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
Random r = new Random();
if (r.nextBoolean()) {
return new BigIntegerExplicitValueModification(explicitValue.add(new BigInteger(MAX_EXPLICIT_LENGTH, r)));
} else {
return new BigIntegerExplicitValueModification(
explicitValue.subtract(new BigInteger(MAX_EXPLICIT_LENGTH, r)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ public interface InteractiveBigIntegerModification {

BigInteger modify(BigInteger oldVal);
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
throw new UnsupportedOperationException("This method is not supported for interactive Modifactions");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "shift", "modificationFilter", "postModification" })
public class BigIntegerShiftLeftModification extends VariableModification<BigInteger> {

private final static int MAX_SHIFT_LENGTH = 32;

private int shift;

public BigIntegerShiftLeftModification() {
Expand All @@ -42,4 +45,9 @@ public int getShift() {
public void setShift(int shift) {
this.shift = shift;
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
return new BigIntegerShiftLeftModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "shift", "modificationFilter", "postModification" })
public class BigIntegerShiftRightModification extends VariableModification<BigInteger> {

private final static int MAX_SHIFT_LENGTH = 32;

private int shift;

public BigIntegerShiftRightModification() {
Expand All @@ -42,4 +45,9 @@ public int getShift() {
public void setShift(int shift) {
this.shift = shift;
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
return new BigIntegerShiftRightModification(shift + new Random().nextInt(MAX_SHIFT_LENGTH));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "subtrahend", "modificationFilter", "postModification" })
public class BigIntegerSubtractModification extends VariableModification<BigInteger> {

private final static int MAX_SUBTRACT_LENGTH = 8;

private BigInteger subtrahend;

public BigIntegerSubtractModification() {
Expand All @@ -42,4 +45,9 @@ public BigInteger getSubtrahend() {
public void setSubtrahend(BigInteger subtrahend) {
this.subtrahend = subtrahend;
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
return new BigIntegerSubtractModification(subtrahend.add(new BigInteger(MAX_SUBTRACT_LENGTH, new Random())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@

import de.rub.nds.modifiablevariable.VariableModification;
import java.math.BigInteger;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "xor", "modificationFilter", "postModification" })
public class BigIntegerXorModification extends VariableModification<BigInteger> {

private final static int MAX_XOR_LENGTH = 8;

private BigInteger xor;

public BigIntegerXorModification() {
Expand All @@ -42,4 +45,9 @@ public BigInteger getXor() {
public void setXor(BigInteger xor) {
this.xor = xor;
}

@Override
public VariableModification<BigInteger> getModifiedCopy() {
return new BigIntegerXorModification(xor.add(new BigInteger(MAX_XOR_LENGTH, new Random())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,9 @@ public boolean isExplicitValue() {
public void setExplicitValue(boolean explicitValue) {
this.explicitValue = explicitValue;
}

@Override
public VariableModification<Boolean> getModifiedCopy() {
return new BooleanExplicitValueModification(!explicitValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ protected Boolean modifyImplementationHook(Boolean input) {
}
return !input;
}

@Override
public VariableModification<Boolean> getModifiedCopy() {
return new BooleanToogleModification();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
import de.rub.nds.modifiablevariable.util.ArrayConverter;
import static de.rub.nds.modifiablevariable.util.ArrayConverter.bytesToHexString;
import java.util.Arrays;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

@XmlRootElement
@XmlType(propOrder = { "count", "startPosition", "modificationFilter", "postModification" })
public class ByteArrayDeleteModification extends VariableModification<byte[]> {

private final static int MAX_MODIFIER_LENGTH = 32;

private int count;

private int startPosition;
Expand Down Expand Up @@ -78,4 +81,26 @@ public int getCount() {
public void setCount(int count) {
this.count = count;
}

@Override
public VariableModification<byte[]> getModifiedCopy() {
Random r = new Random();
int modifier = r.nextInt(MAX_MODIFIER_LENGTH);
if (r.nextBoolean()) {
modifier *= -1;
}
if (r.nextBoolean()) {
modifier = startPosition + modifier;
if (modifier <= 0) {
modifier = 0;
}
return new ByteArrayDeleteModification(modifier, count);
} else {
modifier = startPosition + count;
if (modifier <= 0) {
modifier = 1;
}
return new ByteArrayDeleteModification(startPosition, modifier);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,10 @@ protected byte[] modifyImplementationHook(byte[] input) {
}
return ArrayConverter.concatenate(input, input);
}

@Override
public VariableModification<byte[]> getModifiedCopy() {
return new ByteArrayDuplicateModification();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import de.rub.nds.modifiablevariable.VariableModification;
import de.rub.nds.modifiablevariable.util.ArrayConverter;
import de.rub.nds.modifiablevariable.util.ByteArrayAdapter;
import java.util.Arrays;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
Expand All @@ -19,6 +21,8 @@
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
public class ByteArrayExplicitValueModification extends VariableModification<byte[]> {

private final static int MAX_EXPLICIT_VALUE = 256;

private byte[] explicitValue;

public ByteArrayExplicitValueModification() {
Expand Down Expand Up @@ -49,4 +53,15 @@ public String toString() {
+ ArrayConverter.bytesToHexString(explicitValue) + '}';
}

@Override
public VariableModification<byte[]> getModifiedCopy() {
Random r = new Random();
if (explicitValue.length == 0) {
return this;
}
int index = r.nextInt(explicitValue.length);
byte[] newValue = Arrays.copyOf(explicitValue, explicitValue.length);
newValue[index] = (byte) r.nextInt(MAX_EXPLICIT_VALUE);
return new ByteArrayExplicitValueModification(newValue);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import de.rub.nds.modifiablevariable.util.ArrayConverter;
import de.rub.nds.modifiablevariable.util.ByteArrayAdapter;
import java.util.Arrays;
import java.util.Random;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
Expand All @@ -20,6 +21,10 @@
@XmlType(propOrder = { "bytesToInsert", "startPosition", "modificationFilter", "postModification" })
public class ByteArrayInsertModification extends VariableModification<byte[]> {

private final static int MAX_EXPLICIT_VALUE = 256;

private final static int MAX_INSERT_MODIFIER = 32;

private byte[] bytesToInsert;

private int startPosition;
Expand Down Expand Up @@ -76,4 +81,27 @@ public int getStartPosition() {
public void setStartPosition(int startPosition) {
this.startPosition = startPosition;
}

@Override
public VariableModification<byte[]> getModifiedCopy() {
Random r = new Random();

if (r.nextBoolean()) {
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);
} else {
byte[] newValue = Arrays.copyOf(bytesToInsert, bytesToInsert.length);
int modifier = r.nextInt(MAX_INSERT_MODIFIER);
if (r.nextBoolean()) {
modifier *= -1;
}
modifier = startPosition + modifier;
if (modifier <= 0) {
modifier = 1;
}
return new ByteArrayInsertModification(newValue, modifier);
}
}
}
Loading