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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class ByteArrayModificationFactory {
public static final String FILE_NAME = "de/rub/nds/modifiablevariable/explicit/array.vec";

/**
*
*
* @param xor
* bytes to xor
* @param startPosition
Expand All @@ -72,7 +72,7 @@ public static VariableModification<byte[]> payload(final byte[] payload) {

/**
* *
*
*
* @param bytesToInsert
* bytes to xor
* @param startPosition
Expand All @@ -85,7 +85,7 @@ public static VariableModification<byte[]> insert(final byte[] bytesToInsert, fi

/**
* * Deletes $count bytes from the input array beginning at $startPosition
*
*
* @param startPosition
* negative numbers mean that the position is taken from the end
* @param count
Expand All @@ -98,7 +98,7 @@ public static VariableModification<byte[]> delete(final int startPosition, final

/**
* Duplicates the byte array
*
*
* @return duplicate variable modification
*/
public static VariableModification<byte[]> duplicate() {
Expand All @@ -117,7 +117,7 @@ public static VariableModification<byte[]> explicitValueFromFile(int value) {

/**
* Shuffles the bytes in the array, given a specified array of positions.
*
*
* @param shuffle
* positions that define shuffling
* @return shuffling variable modification
Expand Down Expand Up @@ -162,13 +162,19 @@ public static VariableModification<byte[]> createRandomModification(byte[] origi
switch (r) {
case BYTE_ARRAY_XOR_MODIFICATION:
int modificationArrayLength = random.nextInt(modifiedArrayLength);
if (modificationArrayLength == 0) {
modificationArrayLength++;
}
byte[] xor = new byte[modificationArrayLength];
random.nextBytes(xor);
int startPosition = random.nextInt(modifiedArrayLength - modificationArrayLength);
vm = new ByteArrayXorModification(xor, startPosition);
return vm;
case BYTE_ARRAY_INSERT_MODIFICATION:
modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER);
if (modificationArrayLength == 0) {
modificationArrayLength++;
}
byte[] bytesToInsert = new byte[modificationArrayLength];
random.nextBytes(bytesToInsert);
int insertPosition = random.nextInt(modifiedArrayLength);
Expand All @@ -182,6 +188,9 @@ public static VariableModification<byte[]> createRandomModification(byte[] origi
return vm;
case BYTE_ARRAY_EXPLICIT_VALUE_MODIFICATION:
modificationArrayLength = random.nextInt(MAX_CONFIG_PARAMETER);
if (modificationArrayLength == 0) {
modificationArrayLength++;
}
byte[] explicitValue = new byte[modificationArrayLength];
random.nextBytes(explicitValue);
vm = new ByteArrayExplicitValueModification(explicitValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ public static void makeArrayNonZero(final byte[] array) {
* @return big integer represented in bytes, padded to a specific block size
*/
public static byte[] bigIntegerToByteArray(BigInteger value, int blockSize, boolean removeSignByte) {
if (blockSize == 0) {
return new byte[0];
}
byte[] array = value.toByteArray();
int remainder = array.length % blockSize;
byte[] result = array;
Expand Down