public class Decoded {
int flowId;
- String data;
+ byte[] data;
public Decoded() {}
}
MAP_T fragmentedMapPtr; /* contains list of packet_t* */
Queue_t decodedQueuePtr; /* contains decoded_t* */
+ int cnt;
public Decoder() {}
System.exit(1);
}
+ decoderPtr.cnt = 0;
+
}
return decoderPtr;
System.exit(1);
}
+ System.out.print("");
Packet firstFragmentPtr = (Packet)it.next(fragmentListPtr);
+
int expectedNumFragment = firstFragmentPtr.numFragment;
System.exit(1);
}
-
+
/*
* If we have all thefragments we can reassemble them
}
return er.INCOMPLETE; /* should be sequential */
}
- numBytes += fragmentPtr.length;
- i++;
+ numBytes = numBytes + fragmentPtr.length;
+ i++;
+
}
- String data = new String();
+ byte[] data = new byte[numBytes];
it.reset(fragmentListPtr);
+ int index=0;
while(it.hasNext(fragmentListPtr)) {
Packet fragmentPtr = (Packet)it.next(fragmentListPtr);
- data +=(fragmentPtr.data);
+
+ for(i=0;i<fragmentPtr.length;i++) {
+ data[index++] = fragmentPtr.data[i];
+ }
}
+
Decoded decodedPtr = new Decoded();
if(decodedPtr == null) {
}
decodedPtr.flowId = flowId;
- decodedPtr.data = new String(data);
+ decodedPtr.data = data;
status = decodedQueuePtr.queue_push(decodedPtr);
}
}else {
+
/*
* This is the only fragment, so it is ready
*/
return er.FRAGMENTID;
}
- String data = new String(packetPtr.data);
+ byte[] data = packetPtr.data;
+
if(data == null) {
System.out.println("Assertion in proces9");
System.exit(1);
}
}
+// cnt++;
+// System.out.println("method call Count = " + cnt);
+
return er.NONE;
* -- If none, returns NULL
* =============================================================================
char* decoder_getComplete (decoder_t* decoderPtr, long* decodedFlowIdPtr); */
- public String getComplete(int[] decodedFlowId) {
- String data;
+ public byte[] getComplete(int[] decodedFlowId) {
+ byte[] data;
Decoded decodedPtr = (Decoded)decodedQueuePtr.queue_pop();
if(decodedPtr != null) {
decodedFlowId[0] = decodedPtr.flowId;
data = decodedPtr.data;
+
} else {
decodedFlowId[0] = -1;
data= null;
}
+
return data;
}
* =============================================================================
* error_t detector_process (detector_t* detectorPtr, char* str);
*/
- public int process(String str)
+ public int process(byte[] str)
{
/*
* Apply preprocessors
int p;
int numPreprocessor = preprocessorVectorPtr.vector_getSize();
+ int i;
for(p = 0; p < numPreprocessor; p++) {
Integer preprocessor = (Integer)preprocessorVectorPtr.vector_at(p);
if(preprocessor.intValue() == 1) {
System.out.println("NOOOOOOOOOOOOO");
}
else if(preprocessor.intValue() == 2) {
- str = str.toLowerCase();
+ for(i=0;i<str.length;i++)
+ {
+ if(str[i] >'A' && str[i] < 'Z')
+ {
+ str[i] = (byte)(str[i] + (byte)32);
+ }
+ }
+
+
}
else {
System.out.println("NOOOOOOOOOOOOO");
ERROR err = new ERROR();
// System.out.print("str = \"" + str+ "\"");
- String signature = dictionaryPtr.match(str);
+ String signature = dictionaryPtr.match(new String(str));
// System.out.println("\tSign = \"" + signature+ "\"");
if(signature != null) {
return err.SIGNATURE;
detectorPtr.addPreprocessor(2);
Vector_t errorVectorPtr = errorVectors[threadID];
- int cnt =0;
while(true) {
Packet packetPtr;
+
+ System.out.println("Before atomic Brace");
// TM_BEGIN();
atomic {
+ System.out.println("In the atomic");
packetPtr = streamPtr.getPacket();
}
+
+ System.out.println("After atomic");
// TM_END();
//
}
// TM_END();
//
+ //
if (error != 0) {
/*
System.out.println("Here?");
System.exit(1);
}
- String data;
+ byte[] data;
int[] decodedFlowId = new int[1];
- cnt++;
// TM_BEGIN();
atomic {
data = decoderPtr.getComplete(decodedFlowId);
}
+
// TM_END();
if(data != null) {
int err = detectorPtr.process(data);
Vector_t errorVectorPtr = errorVectors[i];
int e;
int numError = errorVectorPtr.vector_getSize();
+ System.out.println("numError = " + numError);
numFound += numError;
for (e = 0; e< numError; e++) {
int flowId = ((Integer)errorVectorPtr.vector_at(e)).intValue();
int fragmentId;
int numFragment;
int length;
- String data;
+ byte[] data;
public Packet(int numDataBytes)
{
- char c[] = new char[numDataBytes];
- data = new String(c);
+ data = new byte[numDataBytes];
}
public static int compareFlowID(Packet aPtr, Packet bPtr)
+++ /dev/null
-public class Preprocessor {
- public Preprocessor() {}
-
- public void process(String str) {
-
- }
-
-
- /*
- public static void main(String[] argv) {
-
- System.out.println("Starting...");
-
- String hex = new String("This%20is %41 test%3F%3f");
-
- Preprocessor.convertURNHex(hex);
-
- System.out.println(hex);
-
- String caps = new String("ThiS is A tEsT??");
-
- Preprocessor.toLower(caps);
- System.out.println(caps);
-
- System.out.println("All tests passed.");
-
- }
- */
-
-}
* -- Packets will be equal-size chunks except for last one, which will have
* all extra bytes
*/
- private void splitIntoPackets(String str, int flowId, Random randomPtr,
+ private void splitIntoPackets(byte[] str,int flowId, Random randomPtr,
Vector_t allocVectorPtr, Queue_t packetQueuePtr)
{
- int numByte = str.length();
+ int numByte = str.length;
int numPacket = randomPtr.random_generate() % numByte + 1;
int numDataByte = numByte / numPacket;
+ int i;
int p;
boolean status;
int beginIndex = 0;
int endIndex;
-
+ int z;
for (p = 0; p < (numPacket - 1); p++) {
Packet bytes = new Packet(numDataByte);
if (bytes == null) {
bytes.numFragment = numPacket;
bytes.length = numDataByte;
endIndex = beginIndex + numDataByte;
- String tmpstr = str.subString(beginIndex, endIndex);
- bytes.data = new String(tmpstr);
+
+
+ for(i=beginIndex,z=0;i <endIndex;z++,i++) {
+ bytes.data[z] = str[i];
+ }
+
status = packetQueuePtr.queue_push(bytes);
if (status == false) {
System.out.printString("Error: Queue push failed\n");
System.exit(0);
}
beginIndex = endIndex;
+
}
int lastNumDataByte = numDataByte + numByte % numPacket;
- Packet bytes = new Packet(0);
+ Packet bytes = new Packet(lastNumDataByte);
if (bytes == null) {
System.out.printString("Error: Packet class allocation failed\n");
System.exit(0);
bytes.flowId = flowId;
bytes.fragmentId = p;
bytes.numFragment = numPacket;
- bytes.length = str.length();
- endIndex = numByte -1;
- String tmpstr = str.subString(beginIndex);
- bytes.data = new String(tmpstr);
+ bytes.length = lastNumDataByte;
+ endIndex = numByte;
+
+ for(i=beginIndex,z=0;i<endIndex;z++,i++) {
+ bytes.data[z] = str[i];
+ }
status = packetQueuePtr.queue_push(bytes);
+
if (status == false) {
System.out.printString("Error: Queue push failed\n");
System.exit(0);
int f;
boolean status;
for (f = 1; f <= numFlow; f++) {
- String str;
+ byte[] c;
if ((randomPtr.random_generate() % 100) < percentAttack) {
int s = randomPtr.random_generate() % dictionaryPtr.global_numDefaultSignature;
- str = dictionaryPtr.get(s);
- status = MAP_INSERT(attackMapPtr, f, str);
+ String str = dictionaryPtr.get(s);
+ c = str.getBytes();
+
+ status = MAP_INSERT(attackMapPtr, f, c);
if (status == false) {
System.out.printString("Assert failed: status is false\n");
System.exit(0);
int length = (randomPtr.random_generate() % maxLength) + 1;
int l;
- char c[] = new char[length+1];
+ c = new byte[length+1];
for (l = 0; l < length; l++) {
- c[l] =(char) (' ' + (char) (randomPtr.random_generate() % range));
+ c[l] =(byte) (' ' + (char) (randomPtr.random_generate() % range));
}
- c[l] = '\0';
- str = new String(c);
- String str2 = new String(c);
- status = allocVectorPtr.vector_pushBack(str);
+ status = allocVectorPtr.vector_pushBack(c);
if(!status) {
System.out.println("Assert faiiled status is null.");
}
- int err = detectorPtr.process(str2);
+ int err = detectorPtr.process(c);
if (err == error.SIGNATURE) {
- status = MAP_INSERT(attackMapPtr, f, str);
+ status = MAP_INSERT(attackMapPtr, f, c);
System.out.println("Never here");
if (!status) {
numAttack++;
}
}
- splitIntoPackets(str, f, randomPtr, allocVectorPtr, packetQueuePtr);
+
+ splitIntoPackets(c, f, randomPtr, allocVectorPtr, packetQueuePtr);
}
packetQueuePtr.queue_shuffle(randomPtr);
+++ /dev/null
-
-
-public class convertURNHex extends Preprocessor
-{
- public convertURNHex() {
- super();
- }
- public static void process(String str)
- {
- char[] str_char = str.toCharArray();
- int src = 0;
- int dst = 0;
- char c;
-
- while((c = str_char[src]) != '\0') {
- if (c == '%') {
- char[] hex = new char[3];
- hex[0] = toLowerCase((int)str_char[src+1]);
- hex[1] = toLowerCase((int)str_char[src+2]);
- hex[2] = '\0';
-
- String a = String.valueOf(hex);
- int i = Integer.parseInt(a,16);
- src+=2;
- str_char[src] = (char)i;
- }
- str_char[dst] = str_char[src];
- dst++;
- src++;
- }
- str_char[dst] = '\0';
-
- str = new String(str_char);
- }
-
- private static char toLowerCase(int a) {
-
- if(a >= 65 && a <= 90)
- {
- return (char)(a + 32); // difference 'a'(97) - 'A'(65) = 32
- }
- else return (char)a;
-
-
- }
-}
ttttmpStream.java \
ttttmpDecoder.java \
ttttmpRBTree.java \
- Preprocessor.java \
Detector.java \
Decoded.java \
ERROR.java \
rm tmp*.java
rm ttt*.java
rm -rf tmpbuilddirectory
- rm *.bin
+++ /dev/null
-
-public class toLower extends Preprocessor
-{
- public toLower() {
- super();
- }
- public static String process(String str)
- {
- str= str.toLowerCase();
-
- return str;
- }
-
-}