-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the Moodifications from SSH-Fuzzer to ModifiableVaraible.
SSH-Fuzzer hat defined some modificiations using the explicitValueModificationGenerator() method. It makes not much sense for me to define them not well structured in the SSH-Fuzzer (and abusing explicit modifications for this). The Mutations that got moved over are: - Append - Insert - Prepend for Integer, BigInteger, ByteArray and Long These Modifications do currently produce no usefull values for negative parameters, but if someone needs this, he should revise this. For our work, we mostly need only positiv values. I also added the missing modifications for long, since SFTP uses longs. And also added multiply modifiaction to integer.
- Loading branch information
Showing
37 changed files
with
1,660 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerAppendValueModification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* ModifiableVariable - A Variable Concept for Runtime Modifications | ||
* | ||
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
* | ||
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package de.rub.nds.modifiablevariable.biginteger; | ||
|
||
import de.rub.nds.modifiablevariable.VariableModification; | ||
import jakarta.xml.bind.annotation.XmlAccessType; | ||
import jakarta.xml.bind.annotation.XmlAccessorType; | ||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
import jakarta.xml.bind.annotation.XmlType; | ||
import java.math.BigInteger; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
|
||
@XmlRootElement | ||
@XmlType(propOrder = {"appendValue", "modificationFilter"}) | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class BigIntegerAppendValueModification extends VariableModification<BigInteger> { | ||
|
||
private static final int MAX_APPEND_LENGTH = 8; | ||
|
||
private BigInteger appendValue; | ||
|
||
public BigIntegerAppendValueModification() {} | ||
|
||
public BigIntegerAppendValueModification(BigInteger bi) { | ||
this.appendValue = bi; | ||
} | ||
|
||
@Override | ||
protected BigInteger modifyImplementationHook(BigInteger input) { | ||
if (input == null) { | ||
input = BigInteger.ZERO; | ||
} | ||
return input.shiftLeft(appendValue.bitLength()).add(appendValue); | ||
} | ||
|
||
public BigInteger getAppendValue() { | ||
return appendValue; | ||
} | ||
|
||
public void setAppendValue(BigInteger appendValue) { | ||
this.appendValue = appendValue; | ||
} | ||
|
||
@Override | ||
public VariableModification<BigInteger> getModifiedCopy() { | ||
return new BigIntegerAppendValueModification(appendValue.add(new BigInteger(MAX_APPEND_LENGTH, new Random()))); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 59 * hash + Objects.hashCode(this.appendValue); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final BigIntegerAppendValueModification other = (BigIntegerAppendValueModification) obj; | ||
return Objects.equals(this.appendValue, other.appendValue); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...main/java/de/rub/nds/modifiablevariable/biginteger/BigIntegerInsertValueModification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* ModifiableVariable - A Variable Concept for Runtime Modifications | ||
* | ||
* Ruhr University Bochum, Paderborn University, Technology Innovation Institute, and Hackmanit GmbH | ||
* | ||
* Licensed under Apache License 2.0 http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package de.rub.nds.modifiablevariable.biginteger; | ||
|
||
import de.rub.nds.modifiablevariable.VariableModification; | ||
import jakarta.xml.bind.annotation.XmlAccessType; | ||
import jakarta.xml.bind.annotation.XmlAccessorType; | ||
import jakarta.xml.bind.annotation.XmlRootElement; | ||
import jakarta.xml.bind.annotation.XmlType; | ||
import java.math.BigInteger; | ||
import java.util.Objects; | ||
import java.util.Random; | ||
|
||
@XmlRootElement | ||
@XmlType(propOrder = {"insertValue", "startPosition", "modificationFilter"}) | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class BigIntegerInsertValueModification extends VariableModification<BigInteger> { | ||
|
||
private static final int MAX_INSERT_LENGTH = 8; | ||
private static final int MAX_POSITION_MODIFIER = 32; | ||
|
||
private BigInteger insertValue; | ||
private int startPosition; | ||
|
||
public BigIntegerInsertValueModification() {} | ||
|
||
public BigIntegerInsertValueModification(BigInteger bi, int startPosition) { | ||
this.insertValue = bi; | ||
this.startPosition = startPosition; | ||
} | ||
|
||
@Override | ||
protected BigInteger modifyImplementationHook(BigInteger input) { | ||
if (input == null) { | ||
input = BigInteger.ZERO; | ||
} | ||
int originalValueLength = input.bitLength(); | ||
int insertValueLength = insertValue.bitLength(); | ||
int insertPosition = startPosition; | ||
if (startPosition > originalValueLength) { | ||
insertPosition = originalValueLength; | ||
} else if (startPosition < 0) { | ||
insertPosition = 0; | ||
} | ||
BigInteger mask = BigInteger.valueOf((1L << insertPosition) - 1); | ||
|
||
return input.shiftRight(insertPosition) | ||
.shiftLeft(insertValueLength) | ||
.and(insertValue) | ||
.shiftLeft(insertPosition) | ||
.add(mask.and(input)); | ||
} | ||
|
||
public BigInteger getInsertValue() { | ||
return insertValue; | ||
} | ||
|
||
public void setInsertValue(BigInteger insertValue) { | ||
this.insertValue = insertValue; | ||
} | ||
|
||
public int getStartPosition() { | ||
return startPosition; | ||
} | ||
|
||
public void setStartPosition(int startPosition) { | ||
this.startPosition = startPosition; | ||
} | ||
|
||
@Override | ||
public VariableModification<BigInteger> getModifiedCopy() { | ||
Random r = new Random(); | ||
|
||
if (r.nextBoolean()) { | ||
return new BigIntegerInsertValueModification( | ||
insertValue.add(new BigInteger(MAX_INSERT_LENGTH, r)), startPosition); | ||
} else { | ||
int modifier = r.nextInt(MAX_POSITION_MODIFIER); | ||
if (r.nextBoolean()) { | ||
modifier *= -1; | ||
} | ||
modifier = startPosition + modifier; | ||
if (modifier <= 0) { | ||
modifier = 1; | ||
} | ||
return new BigIntegerInsertValueModification(insertValue, modifier); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 58 * hash + Objects.hashCode(this.insertValue); | ||
hash = 58 * hash + Objects.hashCode(this.startPosition); | ||
return hash; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final BigIntegerInsertValueModification other = (BigIntegerInsertValueModification) obj; | ||
if (this.startPosition != other.startPosition) { | ||
return false; | ||
} | ||
return Objects.equals(this.insertValue, other.insertValue); | ||
} | ||
} |
Oops, something went wrong.