Skip to content
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ sudo: false

jdk:
- oraclejdk8
- oraclejdk7
- openjdk7
- openjdk8

#branches:
# only:
Expand All @@ -15,4 +15,4 @@ notifications:
email:
recipients:
- juraj.somorovsky@hackmanit.de
- robert.merget@rub.de
- robert.merget@rub.de
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.rub.nds.modifiablevariable.length.ModifiableLengthField;
import de.rub.nds.modifiablevariable.mlong.ModifiableLong;
import de.rub.nds.modifiablevariable.singlebyte.ModifiableByte;
import de.rub.nds.modifiablevariable.string.ModifiableString;
import java.math.BigInteger;

/**
Expand Down Expand Up @@ -50,6 +51,14 @@ public static ModifiableBigInteger safelySetValue(ModifiableBigInteger mv, BigIn
return mv;
}

public static ModifiableString safelySetValue(ModifiableString mv, String value) {
if (mv == null) {
mv = new ModifiableString();
}
mv.setOriginalValue(value);
return mv;
}

public static ModifiableInteger safelySetValue(ModifiableInteger mv, Integer value) {
if (mv == null) {
mv = new ModifiableInteger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
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.string.StringExplicitValueModification;
import de.rub.nds.modifiablevariable.util.ArrayConverter;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;
Expand All @@ -57,12 +58,11 @@
IntegerShiftLeftModification.class, IntegerShiftRightModification.class, ByteArrayDeleteModification.class,
ByteArrayExplicitValueModification.class, ByteArrayInsertModification.class, ByteArrayXorModification.class,
ByteArrayDuplicateModification.class, ByteArrayShuffleModification.class, ByteAddModification.class,
ByteExplicitValueModification.class, ByteSubtractModification.class, ByteXorModification.class

})
ByteExplicitValueModification.class, ByteSubtractModification.class, ByteXorModification.class,
StringExplicitValueModification.class })
public abstract class VariableModification<E> {

private static final Logger LOGGER = LogManager.getLogger(VariableModification.class);
protected static final Logger LOGGER = LogManager.getLogger(VariableModification.class);

/**
* post modification for next modification executed on the given variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class BigIntegerExplicitValueModification extends VariableModification<Bi
private BigInteger explicitValue;

public BigIntegerExplicitValueModification() {

}

public BigIntegerExplicitValueModification(BigInteger bi) {
Expand All @@ -42,4 +41,4 @@ public BigInteger getExplicitValue() {
public void setExplicitValue(BigInteger explicitValue) {
this.explicitValue = explicitValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

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.util.RandomHelper;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -123,13 +124,13 @@ public static synchronized List<VariableModification<BigInteger>> modificationsF
try {
if (modificationsFromFile == null) {
modificationsFromFile = new LinkedList<>();
ClassLoader classLoader = IntegerModificationFactory.class.getClassLoader();

File file = new File(classLoader.getResource(IntegerModificationFactory.FILE_NAME).getFile());
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
String value = line.trim().split(" ")[0];
ClassLoader classLoader = ByteArrayModificationFactory.class.getClassLoader();
InputStream is = classLoader.getResourceAsStream(IntegerModificationFactory.FILE_NAME);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
String value = line.trim().split(" ")[0];
if (!value.equals("")) {
modificationsFromFile.add(explicitValue(value));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,19 @@ protected byte[] modifyImplementationHook(byte[] input) {
if (start < 0) {
start += input.length;
if (start < 0) {
throw new IllegalArgumentException("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) {
throw new ArrayIndexOutOfBoundsException(String.format(
"Bytes %d..%d cannot be deleted from {%s} of length %d", start, endPosition,
LOGGER.debug(String.format("Bytes %d..%d cannot be deleted from {%s} of length %d", start, endPosition,
bytesToHexString(input), input.length));
return input;
}
if (count <= 0) {
throw new IllegalArgumentException("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);
byte[] ret2 = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ protected byte[] modifyImplementationHook(byte[] input) {
if (start < 0) {
start += input.length;
if (start < 0) {
throw new IllegalArgumentException("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) {
throw new ArrayIndexOutOfBoundsException("Trying to insert behind the Array. ArraySize:" + input.length
+ " Insert Position:" + startPosition);
LOGGER.debug("Trying to insert behind the Array. ArraySize:" + input.length + " Insert Position:"
+ startPosition);
return input;
}
byte[] ret1 = Arrays.copyOf(input, start);
byte[] ret3 = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Shuffles the byte array, using a pre-defined array of array pointers
* (#shuffle). Array pointers are currently defined as bytes, since we are
* modifying rather smaller arrays.
*
*
* @author Juraj Somorovsky - juraj.somorovsky@rub.de
*/
@XmlRootElement
Expand All @@ -37,6 +37,9 @@ public ByteArrayShuffleModification(byte[] shuffle) {

@Override
protected byte[] modifyImplementationHook(final byte[] input) {
if (input == null) {
return input;
}
byte[] result = input.clone();
int size = input.length;
for (int i = 0; i < shuffle.length - 1; i += 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ protected byte[] modifyImplementationHook(byte[] input) {
if (end > result.length) {
// result = new byte[end];
// System.arraycopy(input, 0, result, 0, input.length);
throw new ArrayIndexOutOfBoundsException(String.format(
LOGGER.debug(String.format(
"Input {%s} of length %d cannot be xored with {%s} of length %d with start position %d",
ArrayConverter.bytesToHexString(input), input.length, ArrayConverter.bytesToHexString(xor),
xor.length, startPosition));
return input;
}
for (int i = 0; i < xor.length; ++i) {
result[start + i] = (byte) (input[start + i] ^ xor[i]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2017 Robert Merget <robert.merget@rub.de>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.rub.nds.modifiablevariable.string;

import de.rub.nds.modifiablevariable.ModifiableVariable;
import de.rub.nds.modifiablevariable.VariableModification;
import de.rub.nds.modifiablevariable.mlong.LongAddModification;
import de.rub.nds.modifiablevariable.mlong.LongExplicitValueModification;
import de.rub.nds.modifiablevariable.mlong.LongModificationFactory;
import de.rub.nds.modifiablevariable.mlong.LongSubtractModification;
import de.rub.nds.modifiablevariable.mlong.LongXorModification;
import de.rub.nds.modifiablevariable.mlong.ModifiableLong;
import de.rub.nds.modifiablevariable.util.ArrayConverter;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;

/**
*
* @author Robert Merget <robert.merget@rub.de>
*/
@XmlRootElement
@XmlSeeAlso({ StringExplicitValueModification.class })
@XmlType(propOrder = { "originalValue", "modification", "assertEquals" })
public class ModifiableString extends ModifiableVariable<String> implements Serializable {

private String originalValue;

public ModifiableString() {
}

@Override
protected void createRandomModification() {
VariableModification<String> vm = StringModificationFactory.createRandomModification();
setModification(vm);
}

public String getAssertEquals() {
return assertEquals;
}

public void setAssertEquals(String assertEquals) {
this.assertEquals = assertEquals;
}

@Override
public boolean isOriginalValueModified() {
return originalValue != null && originalValue.compareTo(getValue()) != 0;
}

public byte[] getByteArray(int size) {
return getValue().getBytes();
}

@Override
public boolean validateAssertions() {
boolean valid = true;
if (assertEquals != null) {
if (assertEquals.compareTo(getValue()) != 0) {
valid = false;
}
}
return valid;
}

@Override
public String getOriginalValue() {
return originalValue;
}

@Override
public void setOriginalValue(String originalValue) {
this.originalValue = originalValue;
}

@Override
public String toString() {
return "ModifiableString{" + "originalValue=" + originalValue + '}';
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ModifiableString)) {
return false;
}

ModifiableString that = (ModifiableString) o;

return getValue() != null ? getValue().equals(that.getValue()) : that.getValue() == null;
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (getValue() != null ? getValue().hashCode() : 0);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2017 Robert Merget <robert.merget@rub.de>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package de.rub.nds.modifiablevariable.string;

import de.rub.nds.modifiablevariable.VariableModification;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
*
* @author Robert Merget <robert.merget@rub.de>
*/
@XmlRootElement
@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" })
public class StringExplicitValueModification extends VariableModification<String> {

private String explicitValue;

public StringExplicitValueModification() {
}

public StringExplicitValueModification(String explicitValue) {
this.explicitValue = explicitValue;
}

@Override
protected String modifyImplementationHook(String input) {
return explicitValue;
}

public String getExplicitValue() {
return explicitValue;
}

public void setExplicitValue(String explicitValue) {
this.explicitValue = explicitValue;
}
}
Loading