From 9bb66b4235a7b64fec5845654dea76a8145aa335 Mon Sep 17 00:00:00 2001 From: Robert Merget Date: Mon, 24 Jul 2017 23:08:27 +0200 Subject: [PATCH 1/4] Fixed BigIntegerExplicitValue modification Made ModifiableVariables fault resistent. If the Modification cannot be applied, the looger now logs a debug message and the modification is not applied removed spaces from integer.vec adjusted tests to new behaviour --- .../VariableModification.java | 2 +- .../BigIntegerExplicitValueModification.java | 3 +- .../BigIntegerModificationFactory.java | 19 ++-- .../ByteArrayDeleteModification.java | 11 +-- .../ByteArrayInsertModification.java | 9 +- .../ByteArrayShuffleModification.java | 5 +- .../bytearray/ByteArrayXorModification.java | 3 +- .../modifiablevariable/explicit/integer.vec | 54 ++++++------ .../bytearray/ModifiableByteArrayTest.java | 88 ++----------------- 9 files changed, 65 insertions(+), 129 deletions(-) diff --git a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java index f2936a49..06f152b4 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java @@ -62,7 +62,7 @@ }) public abstract class VariableModification { - 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 diff --git a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java index c738e548..5530fe8f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerExplicitValueModification.java @@ -23,7 +23,6 @@ public class BigIntegerExplicitValueModification extends VariableModification> 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)); } } diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java index 03f03ce6..f8366da3 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayDeleteModification.java @@ -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; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java index 3beb2087..c720f04f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayInsertModification.java @@ -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; diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java index 71446b70..80d6f05f 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayShuffleModification.java @@ -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 @@ -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) { diff --git a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java index 91a0cfe6..4d298e30 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/bytearray/ByteArrayXorModification.java @@ -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]); diff --git a/src/main/resources/de/rub/nds/modifiablevariable/explicit/integer.vec b/src/main/resources/de/rub/nds/modifiablevariable/explicit/integer.vec index 07ccbf3a..fd8de618 100644 --- a/src/main/resources/de/rub/nds/modifiablevariable/explicit/integer.vec +++ b/src/main/resources/de/rub/nds/modifiablevariable/explicit/integer.vec @@ -1,27 +1,27 @@ - -128 /* Overflow signed 8-bit when decremented */ - -1 /* */ - 0 /* */ - 1 /* */ - 16 /* One-off with common buffer size */ - 32 /* One-off with common buffer size */ - 64 /* One-off with common buffer size */ - 100 /* One-off with common buffer size */ - 127 /* Overflow signed 8-bit when incremented */ - -32768 /* Overflow signed 16-bit when decremented */ - -129 /* Overflow signed 8-bit */ - 128 /* Overflow signed 8-bit */ - 255 /* Overflow unsig 8-bit when incremented */ - 256 /* Overflow unsig 8-bit */ - 512 /* One-off with common buffer size */ - 1000 /* One-off with common buffer size */ - 1024 /* One-off with common buffer size */ - 4096 /* One-off with common buffer size */ - 32767 /* Overflow signed 16-bit when incremented */ - -2147483648 /* Overflow signed 32-bit when decremented */ - -100663046 /* Large negative number (endian-agnostic) */ - -32769 /* Overflow signed 16-bit */ - 32768 /* Overflow signed 16-bit */ - 65535 /* Overflow unsig 16-bit when incremented */ - 65536 /* Overflow unsig 16 bit */ - 100663045 /* Large positive number (endian-agnostic) */ - 2147483647 /* Overflow signed 32-bit when incremented */ \ No newline at end of file +-128 /* Overflow signed 8-bit when decremented */ +-1 /* */ +0 /* */ +1 /* */ +16 /* One-off with common buffer size */ +32 /* One-off with common buffer size */ +64 /* One-off with common buffer size */ +100 /* One-off with common buffer size */ +127 /* Overflow signed 8-bit when incremented */ +-32768 /* Overflow signed 16-bit when decremented */ +-129 /* Overflow signed 8-bit */ +128 /* Overflow signed 8-bit */ +255 /* Overflow unsig 8-bit when incremented */ +256 /* Overflow unsig 8-bit */ +512 /* One-off with common buffer size */ +1000 /* One-off with common buffer size */ +1024 /* One-off with common buffer size */ +4096 /* One-off with common buffer size */ +32767 /* Overflow signed 16-bit when incremented */ +-2147483648 /* Overflow signed 32-bit when decremented */ +-100663046 /* Large negative number (endian-agnostic) */ +-32769 /* Overflow signed 16-bit */ +32768 /* Overflow signed 16-bit */ +65535 /* Overflow unsig 16-bit when incremented */ +65536 /* Overflow unsig 16 bit */ +100663045 /* Large positive number (endian-agnostic) */ +2147483647 /* Overflow signed 32-bit when incremented */ diff --git a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java index 6a62513f..e81dffb2 100644 --- a/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java +++ b/src/test/java/de/rub/nds/modifiablevariable/bytearray/ModifiableByteArrayTest.java @@ -88,15 +88,7 @@ public void testXorFirstBytes() { VariableModification modifier2 = ByteArrayModificationFactory.xor(modification2, 0); start.setModification(modifier2); - - Exception e = null; - try { - start.getValue(); - } catch (ArrayIndexOutOfBoundsException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(originalValue, start.getValue()); } /** @@ -121,15 +113,7 @@ public void testXorLastBytes() { VariableModification modifier2 = ByteArrayModificationFactory.xor(modification2, first); start.setModification(modifier2); - - Exception e = null; - try { - start.getValue(); - } catch (ArrayIndexOutOfBoundsException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(originalValue, start.getValue()); } /** @@ -246,69 +230,31 @@ public void testDeleteBytes() { modifier = ByteArrayModificationFactory.delete(0, len + 1); start.setModification(modifier); - Exception e = null; - try { - start.getValue(); - } catch (ArrayIndexOutOfBoundsException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete negative amount"); modifier = ByteArrayModificationFactory.delete(0, -1); start.setModification(modifier); - e = null; - try { - start.getValue(); - } catch (IllegalArgumentException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete 0 Bytes"); modifier = ByteArrayModificationFactory.delete(0, 0); start.setModification(modifier); - e = null; - try { - start.getValue(); - } catch (IllegalArgumentException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from negative Start position"); modifier = ByteArrayModificationFactory.delete(len * -2, modification1.length); start.setModification(modifier); - - e = null; - try { - start.getValue(); - } catch (Exception ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Testing Delete from to big Start Position"); modifier = ByteArrayModificationFactory.delete(len * 2, modification1.length); start.setModification(modifier); - - e = null; - try { - start.getValue(); - } catch (ArrayIndexOutOfBoundsException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); - + assertArrayEquals(start.getValue(), originalValue); } /** @@ -323,14 +269,7 @@ public void testInsertBytes() { VariableModification modifier = ByteArrayModificationFactory.insert(modification1, -2 * originalValue.length); start.setModification(modifier); - Exception e = null; - try { - start.getValue(); - } catch (IllegalArgumentException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); + assertArrayEquals(start.getValue(), originalValue); start = new ModifiableByteArray(); start.setOriginalValue(originalValue); LOGGER.debug("Inserting empty Array"); @@ -344,16 +283,7 @@ public void testInsertBytes() { LOGGER.debug("Inserting to big Start position"); modifier = ByteArrayModificationFactory.insert(modification1, originalValue.length * 2); start.setModification(modifier); - - e = null; - try { - start.getValue(); - } catch (ArrayIndexOutOfBoundsException ae) { - e = ae; - LOGGER.debug(ae.getLocalizedMessage()); - } - assertNotNull(e); - + assertArrayEquals(originalValue, start.getValue()); } /** From c9dcb1118170e6419ce1601932007ee689cd6cbf Mon Sep 17 00:00:00 2001 From: ic0ns Date: Thu, 31 Aug 2017 15:05:57 +0200 Subject: [PATCH 2/4] Added support for ModifiableStrings --- .../ModifiableVariableFactory.java | 9 ++ .../VariableModification.java | 6 +- .../string/ModifiableString.java | 116 ++++++++++++++++++ .../StringExplicitValueModification.java | 51 ++++++++ .../string/StringModificationFactory.java | 40 ++++++ 5 files changed, 219 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java create mode 100644 src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java diff --git a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java index 6e0ebdcb..bdf4dc59 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java +++ b/src/main/java/de/rub/nds/modifiablevariable/ModifiableVariableFactory.java @@ -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; /** @@ -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(); diff --git a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java index 06f152b4..061bbb4d 100644 --- a/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java +++ b/src/main/java/de/rub/nds/modifiablevariable/VariableModification.java @@ -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; @@ -57,9 +58,8 @@ 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 { protected static final Logger LOGGER = LogManager.getLogger(VariableModification.class); diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java new file mode 100644 index 00000000..d41485d0 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/ModifiableString.java @@ -0,0 +1,116 @@ +/* + * Copyright 2017 Robert Merget . + * + * 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 + */ +@XmlRootElement +@XmlSeeAlso({ StringExplicitValueModification.class }) +@XmlType(propOrder = { "originalValue", "modification", "assertEquals" }) +public class ModifiableString extends ModifiableVariable implements Serializable { + + private String originalValue; + + public ModifiableString() { + } + + @Override + protected void createRandomModification() { + VariableModification 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; + } + +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java new file mode 100644 index 00000000..7f184d81 --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringExplicitValueModification.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 Robert Merget . + * + * 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 + */ +@XmlRootElement +@XmlType(propOrder = { "explicitValue", "modificationFilter", "postModification" }) +public class StringExplicitValueModification extends VariableModification { + + 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; + } +} diff --git a/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java new file mode 100644 index 00000000..cae9273f --- /dev/null +++ b/src/main/java/de/rub/nds/modifiablevariable/string/StringModificationFactory.java @@ -0,0 +1,40 @@ +/* + * Copyright 2017 Robert Merget . + * + * 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 de.rub.nds.modifiablevariable.mlong.LongExplicitValueModification; +import de.rub.nds.modifiablevariable.util.RandomHelper; + +/** + * + * @author Robert Merget + */ +public class StringModificationFactory { + + private static final int MAX_BYTE_LENGTH = 1000; + + public static VariableModification explicitValue(final String value) { + return new StringExplicitValueModification(value); + } + + public static VariableModification createRandomModification() { + int i = RandomHelper.getRandom().nextInt(1000); + byte[] randomBytes = new byte[i]; + RandomHelper.getRandom().nextBytes(randomBytes); + return explicitValue(new String(randomBytes)); + } +} From b57ab49c5db0688c3996fc2707bd16fde3ef71ae Mon Sep 17 00:00:00 2001 From: ic0ns Date: Tue, 5 Sep 2017 17:17:41 +0200 Subject: [PATCH 3/4] Added openjdk 8 to travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5f30776a..09e2b4d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,6 +6,7 @@ jdk: - oraclejdk8 - oraclejdk7 - openjdk7 + - openjdk8 #branches: # only: @@ -15,4 +16,4 @@ notifications: email: recipients: - juraj.somorovsky@hackmanit.de - - robert.merget@rub.de \ No newline at end of file + - robert.merget@rub.de From 4feb068f8de33bfc7de43842e2d714ee00a14f73 Mon Sep 17 00:00:00 2001 From: ic0ns Date: Tue, 5 Sep 2017 17:23:47 +0200 Subject: [PATCH 4/4] Removed oracle jdk7 from travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 09e2b4d4..862b3e4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,6 @@ sudo: false jdk: - oraclejdk8 - - oraclejdk7 - openjdk7 - openjdk8