|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jmatchparser.util.BinaryExpression
public class BinaryExpression
An expression that can be used to build or match binary byte arrays.
This is useful when binary data (like encryption keys) should be configurable in a text file, where the user can decide which format (hex, base64, etc.) he wants to use to provide the data.
Therefore, the user can give a list of transformations (separated by colons), followed by data to be transformed. Each transformation is applied on the result of the previous transformation. Therefore, hex:base64:NzQ2NTczNzQ= will result in test.
An empty transformation name will stop parsing transformations; therefore, to match the literal (UTF-8) bytes C:\>, the expression :C:\> can be used. If no encoding is given, everything is encoded as UTF-8. An explicit encoding can be given by using the encode- <encoding>: transformation.
Optionally, a secondary expression can be parsed at the same time, for
example an initialization vector for an encryption key or a mask for matching
data. In case of a mask, MaskedBinaryExpression might have been the
better choice.
The following tranformations are supported:
| Constructor Summary | |
|---|---|
BinaryExpression(String expression,
String secondaryName,
boolean secondaryRandom)
Create a new binary expression with optional secondary expressions |
|
| Method Summary | |
|---|---|
boolean[] |
getMarkedSecondaryBytes()
Return the bytes marked (as optional or random) in the secondary value, if any. |
byte[] |
getRandomSecondaryValue(Random randomSource)
Compute a new random secondary value. |
byte[] |
getSecondaryValue()
Return the secondary value, if any. |
byte[] |
getValue()
Return the value of the parsed expression. |
static byte[] |
parseBinaryExpression(String expression)
Parse a binary expression with no secondary expression. |
static String |
unescape(String string,
String literalChars)
Unescape Java escape sequences like \n or octal or unicode escapes. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BinaryExpression(String expression,
String secondaryName,
boolean secondaryRandom)
throws IOException
expression - Expression to parsesecondaryName - Name used in the expression to denote secondary expression
(like mask or iv)secondaryRandom - Whether the secondary expression may contain random bytes
(like an iv); if not, the marked bytes are optional instead of
random
IOException| Method Detail |
|---|
public static byte[] parseBinaryExpression(String expression)
throws IOException
IOException
public static String unescape(String string,
String literalChars)
throws IOException
string - The string to unescapeliteralChars - List of characters (like quotation marks) that should return
themselves instead of producing an error. A backslash will
always return itself regardless whether it is in this list or
not.
IOExceptionpublic byte[] getValue()
public byte[] getSecondaryValue()
public boolean[] getMarkedSecondaryBytes()
public byte[] getRandomSecondaryValue(Random randomSource)
randomSource - source for the randomness
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||