From 0fbfe5263f8776a21e6d9ff26c2370298d699658 Mon Sep 17 00:00:00 2001 From: jihoonl Date: Wed, 1 Jul 2009 00:56:41 +0000 Subject: [PATCH] Intruder!! --- .../Benchmarks/SingleTM/Intruder/Decoded.java | 9 + .../Benchmarks/SingleTM/Intruder/Decoder.java | 367 ++++++++++++++++++ .../Benchmarks/SingleTM/Intruder/ERROR.java | 88 +++++ .../SingleTM/Intruder/List_Iter.java | 38 ++ .../SingleTM/Intruder/List_Node.java | 10 + .../Benchmarks/SingleTM/Intruder/List_t.java | 312 +++++++++++++++ .../Benchmarks/SingleTM/Intruder/Queue_t.java | 324 ++++++++++++++++ .../Benchmarks/SingleTM/Intruder/Random.java | 93 +++++ .../SingleTM/Intruder/Vector_t.java | 156 ++++++++ .../SingleTM/Intruder/convertURNHex.java | 35 ++ .../Benchmarks/SingleTM/Intruder/toLower.java | 12 + 11 files changed, 1444 insertions(+) create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/ERROR.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/List_Iter.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/List_Node.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/List_t.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/Random.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/Vector_t.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/convertURNHex.java create mode 100644 Robust/src/Benchmarks/SingleTM/Intruder/toLower.java diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java b/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java new file mode 100644 index 00000000..ec71a2f4 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Decoded.java @@ -0,0 +1,9 @@ + +/* structure in Deocder + */ + +public class Decoded { + int flowId; + String data; +} + diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java b/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java new file mode 100644 index 00000000..9374bcaa --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Decoder.java @@ -0,0 +1,367 @@ +/* ============================================================================= + * + * decoder.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * ============================================================================= + * + * For the license of bayes/sort.h and bayes/sort.c, please see the header + * of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of kmeans, please see kmeans/LICENSE.kmeans + * + * ------------------------------------------------------------------------ + * + * For the license of ssca2, please see ssca2/COPYRIGHT + * + * ------------------------------------------------------------------------ + * + * For the license of lib/mt19937ar.c and lib/mt19937ar.h, please see the + * header of the files. + * + * ------------------------------------------------------------------------ + * + * For the license of lib/rbtree.h and lib/rbtree.c, please see + * lib/LEGALNOTICE.rbtree and lib/LICENSE.rbtree + * + * ------------------------------------------------------------------------ + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + + +#define MAP_T RBTree +#define MAP_ALLOC(hash, cmp) RBTree.alloc(cmp) +#define MAP_INSERT(map, key, data) map.insert(key, data) +#define MAP_CONTAINS(map, key) map.contains(key); +#define MAP_FIND(map,key) map.get(key); +#define MAP_INSERT(map,key,data) map.insert(key,data); +#define MAP_REMOVE(map,key) map.deleteNode(key); + +public class Decoder { + + MAP_T fragmentedMapPtr; /* contains list of packet_t* */ + Queue_t decodedQueuePtr; /* contains decoded_t* */ + + public Decoder() {} + +/* ============================================================================= + * decoder_alloc + * ============================================================================= + decoder_t* decoder_alloc (); + */ + public static Decoder alloc() { + Decoder decoderPtr; + + decoderPtr = new Decoder(); + if(decoderPtr) { + decoderPtr.fragementedMapPtr = MAP_ALLOC(0,0); + + if(decoderPtr.fragementedMapPtr == null) + { + System.out.println("Assert in Decoder.alloc"); + System.exit(1); + } + + decoderPtr.decodedQueuePtr = Queue_t.alloc(1024); + if(decoderPtr.decodedQueuePtr == null) + { + System.out.println("Assert in Decoder.alloc"); + System.exit(1); + } + + return decoderPtr; + } + + +/* ============================================================================= + * decoder_free + * ============================================================================= + void decoder_free (decoder_t* decoderPtr); + */ + public free(Decoder decoderPtr) { + fragmentedMapPtr = null; + decodedQueuePtr = null; + decoderPtr = null; + } + + +/* ============================================================================= + * decoder_process + * ============================================================================= + error_t decoder_process (decoder_t* decoderPtr, char* bytes, long numByte); + */ + public int process(Packet bytes,int numByte) + { + boolean status; + + /* + * Basic error checing + */ + + if (numByte < PACKET_HEADER_LENGTH) { + return ERROR.SHORT; + } + + /* need to look into it later */ + Packet packetPtr = (Packet)bytes; + int flowId = packetPtr.flowId; + int fragmentId = packetPtr.fragmentId; + int numFragment = packetPtr.numFragment; + int length = packetPtr.length; + + if (flowId < 0) { + return ERROR.FLOWID; + } + + if ((fragmentedId < 0) || (fragmentId >= numFragment)) { + return ERROR.FRAGMENTID; + } + + if (length < 0) { + return ERROR.LENGTH; + } + + /* + * Add to fragmented map for reassembling + */ + + if (numFragment > 1) { + + List_t fragmentListPtr = (List_t)MAP_FIND(fragmentedMapPtr,flowId); + + if (fragmentListPtr == null) { + + fragmentListPtr = List_t.alloc(1); // packet_compareFragmentId + if(fragmentListPtr == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + + status = MAP_INSERT(fragmentedMapPtr,flowId,fragmentListPtr); + if(status == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + } else { + + List_Iter it; + it.reset(fragmentListPtr); + + if(it.hasNext(fragmentListPtr) == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + + Packet firstFragmentPtr = (Packet)it.next(fragmentListPtr); + int expectedNumFragment = firstFragmentPtr.numFragment; + + if (numFragment != expectedNumFragment) { + status = MAP_REMOVE(fragmentedMapPtr,flowId); + if(status == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + + status = fragmentListPtr.insert(packetPtr); + if(status == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + + /* + * If we have all thefragments we can reassemble them + */ + + if(fragmentListPtr.getSize() == numFragment) { + + int numByte = 0; + int i = 0; + it.reset(fragmentListPtr); + + while (it.hasNext(fragmentListPtr)) { + Packet fragmentPtr = (Packet)it.next(fragmentListPtr); + + if(fragmentPtr.fragmentId != i) { + status = MAP_REMOVE(fragmentedMapPtr,(flowId); + + if(status == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + return ERROR.INCOMPLETE; /* should be sequential */ + } + numByte += fragmentPtr.length; + i++; + } + + char[] data = new char[numByte+1]; + if(data == null) { + System.out.println("Assertion in process"); + System.exit(1); + } + + data[numByte] = '\0'; + int dst = 0; // index of data + int i; + it.reset(fragmentListPtr); + while(it.hasNext(fragmentLIstPtr)) { + Packet fragmentPtr = (Packet)it.next(fragmentListPtr); + + for(i=0;i= 0) { + return prevPtr; + } + prevPtr = nodePtr; + } + + return prevPtr; + } + + /* ============================================================================= + * list_find + * -- Returns NULL if not found, else returns pointer to data + * ============================================================================= + * void* list_find (list_t* listPtr, void* dataPtr); + */ + public Object find(Object dataPtr) { + List_Node nodePtr; + List_Node prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr == null) || + (compare(nodePtr.dataPtr,dataPtr) != 0)) { + return null; + } + + return (nodePtr.dataPtr); + } + + public int compare(Object obj1,Object obj2) + { + if(flag == 1) + { + return Packet.compareFragmentID(obj1,obj2); + } + else + return compareObject(obj1,obj2); + } + +/* ============================================================================= + * list_insert + * -- Return TRUE on success, else FALSE + * ============================================================================= + * bool_t list_insert (list_t* listPtr, void* dataPtr); + */ + public boolean insert(Object dataPtr) { + List_Node prevPtr; + List_Node nodePtr; + List_Node currPtr; + + prevPtr = findPrevious(dataPtr); + currPtr = prevPtr.nextPtr; + + nodePtr = allocNode(dataPtr); + if (nodePtr == null) { + return false; + } + + nodePtr.nextPtr = currPtr; + prevPtr.nextPtr = nodePtr; + size++; + + return true; + } + + +/* ============================================================================= + * list_remove + * -- Returns TRUE if successful, else FALSE + * ============================================================================= + * bool_t list_remove (list_t* listPtr, void* dataPtr); + */ + public boolean remove(Object dataPtr) + { + List_Node prevPtr; + List_Node nodePtr; + + prevPtr = findPrevious(dataPtr); + + nodePtr = prevPtr.nextPtr; + + if((nodePtr != null) && + (compare(nodePtr.dataPtr,dataPtr) == 0)) + { + prevPtr.nextPtr = nodePtr.nextPtr; + nodePtr.nextPtr = null; + nodePtr = null; + size--; + + return true; + } + + return false; + } + + int compareObject(Object obj1,Object obj2) { + return 1; + } + + +/* ============================================================================= + * list_clear + * -- Removes all elements + * ============================================================================= + * void list_clear (list_t* listPtr); + */ + public void clear() { + head = new List_Node(); + size = 0; + } + +/* ============================================================================= + * + * End of list.java + * + * ============================================================================= + */ + + /* Test list */ + + public static void main(String[] argv) { + List_t listPtr; + int[] data1 = new int[5]; + int[] data2 = new int[6]; + + int i; + + System.out.println("Starting..."); + } + +} + + + diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java b/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java new file mode 100644 index 00000000..0f30d35a --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Queue_t.java @@ -0,0 +1,324 @@ +/* ============================================================================= + * + * queue.java + * + * ============================================================================= + * + * Copyright (C) Stanford University, 2006. All Rights Reserved. + * Author: Chi Cao Minh + * + * Ported to Java + * Author:Alokika Dash + * University of California, Irvine + * + * ============================================================================= + * + * Unless otherwise noted, the following license applies to STAMP files: + * + * Copyright (c) 2007, Stanford University + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Stanford University nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY STANFORD UNIVERSITY ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL STANFORD UNIVERSITY BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + * + * ============================================================================= + */ + +#define QUEUE_GROWTH_FACTOR 2 + +public class Queue_t { + int pop; /* points before element to pop */ + int push; + int capacity; + Object[] elements; + + public Queue_t() { + } + + /* ============================================================================= + * queue_alloc + * ============================================================================= + */ + public static Queue_t queue_alloc (int initCapacity) + { + Queue_t queuePtr = new Queue_t(); + + int capacity = ((initCapacity < 2) ? 2 : initCapacity); + queuePtr.elements = new Object[capacity]; + if (queuePtr.elements == null) { + queuePtr = null; + return null; + } + queuePtr.pop = capacity - 1; + queuePtr.push = 0; + queuePtr.capacity = capacity; + + return queuePtr; + } + + + /* ============================================================================= + * Pqueue_alloc + * ============================================================================= + */ + public Queue_t + Pqueue_alloc (int initCapacity) + { + Queue_t queuePtr = new Queue_t(); + + int capacity = ((initCapacity < 2) ? 2 : initCapacity); + queuePtr.elements = new Object[capacity]; + if (queuePtr.elements == null) { + queuePtr = null; + return null; + } + queuePtr.pop = capacity - 1; + queuePtr.push = 0; + queuePtr.capacity = capacity; + + return queuePtr; + } + + /* ============================================================================= + * queue_free + * ============================================================================= + */ + public void + queue_free (Queue_t queuePtr) + { + queuePtr.elements = null; + queuePtr = null; + } + + + /* ============================================================================= + * Pqueue_free + * ============================================================================= + */ + public void + Pqueue_free (Queue_t queuePtr) + { + queuePtr.elements = null; + queuePtr = null; + } + + + /* ============================================================================= + * TMqueue_free + * ============================================================================= + * + public void + TMqueue_free (TM_ARGDECL Queue* queuePtr) + { + queuePtr.elements = null; + queuePtr = null; + } + +*/ + /* ============================================================================= + * queue_isEmpty + * ============================================================================= + */ + public boolean + queue_isEmpty () + { + //int pop = queuePtr.pop; + //int push = queuePtr.push; + //int capacity = queuePtr.capacity; + + return (((pop + 1) % capacity == push) ? true : false); + } + + + /* ============================================================================= + * queue_clear + * ============================================================================= + */ + public void + queue_clear () + { + pop = capacity - 1; + push = 0; + } + + + /* ============================================================================= + * TMqueue_isEmpty + * ============================================================================= + */ + + + + /* ============================================================================= + * queue_push + * ============================================================================= + */ + public boolean + queue_push (Object dataPtr) + { + + if(pop == push) { + + System.out.println("push == pop in Queue.java"); + return false; + } + + + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + Object[] newElements = new Object[newCapacity]; + if (newElements == null) { + return false; + } + + int dst = 0; + Object[] tmpelements = elements; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = elements[src]; + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } + + //elements = null; + elements = newElements; + pop = newCapacity - 1; + capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ + } + + elements[push] = dataPtr; + push = newPush; + + return true; + } + + + /* ============================================================================= + * Pqueue_push + * ============================================================================= + */ + public boolean + Pqueue_push (Queue_t queuePtr, Object dataPtr) + { + int pop = queuePtr.pop; + int push = queuePtr.push; + int capacity = queuePtr.capacity; + + if(pop == push) { + System.out.println("push == pop in Queue.java"); + return false; + } + + /* Need to resize */ + int newPush = (push + 1) % capacity; + if (newPush == pop) { + + int newCapacity = capacity * QUEUE_GROWTH_FACTOR; + Object[] newElements = new Object[newCapacity]; + if (newElements == null) { + return false; + } + + int dst = 0; + Object[] elements = queuePtr.elements; + if (pop < push) { + int src; + for (src = (pop + 1); src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } else { + int src; + for (src = (pop + 1); src < capacity; src++, dst++) { + newElements[dst] = elements[src]; + } + for (src = 0; src < push; src++, dst++) { + newElements[dst] = elements[src]; + } + } + + elements = null; + queuePtr.elements = newElements; + queuePtr.pop = newCapacity - 1; + queuePtr.capacity = newCapacity; + push = dst; + newPush = push + 1; /* no need modulo */ + + } + + queuePtr.elements[push] = dataPtr; + queuePtr.push = newPush; + + return true; + } + + /* ============================================================================= + * queue_pop + * ============================================================================= + */ + public Object + //queue_pop (Queue queuePtr) + queue_pop () + { + //int pop = queuePtr.pop; + //int push = queuePtr.push; + //int capacity = queuePtr.capacity; + + int newPop = (pop + 1) % capacity; + if (newPop == push) { + return null; + } + + //Object dataPtr = queuePtr.elements[newPop]; + //queuePtr.pop = newPop; + Object dataPtr = elements[newPop]; + pop = newPop; + + return dataPtr; + } + + +} +/* ============================================================================= + * + * End of queue.java + * + * ============================================================================= + */ diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Random.java b/Robust/src/Benchmarks/SingleTM/Intruder/Random.java new file mode 100644 index 00000000..2c601f48 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Random.java @@ -0,0 +1,93 @@ +public class Random { + long[] mt; + int mti; + long RANDOM_DEFAULT_SEED; + /* period parameter */ + int N; + int M; + long MATRIX_A; + long UPPER_MASK; + long LOWER_MASK; + + public Random() { + RANDOM_DEFAULT_SEED = 0L; + N = 624; + M = 397; + mt = new long[N]; + mti = N; + MATRIX_A = 0x9908b0dfL; /* constant vector a */ + UPPER_MASK = 0x80000000L; /* most significant w-r bits */ + LOWER_MASK = 0x7fffffffL; /* least significant r bits */ + } + + public void random_alloc() { + init_genrand(this.RANDOM_DEFAULT_SEED); + } + + /* initializes mt[N] with a seed */ + public void init_genrand(long s) { + int mti; + mt[0]= s & 0xFFFFFFFFL; + for (mti=1; mti> 30)) + mti); + /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ + /* In the previous versions, MSBs of the seed affect */ + /* only MSBs of the array mt[]. */ + /* 2002/01/09 modified by Makoto Matsumoto */ + mt[mti] &= 0xFFFFFFFFL; + /* for >32 bit machines */ + } + this.mti=mti; + } + + public void random_seed(long seed) { + init_genrand(seed); + } + + public long random_generate() { + return genrand_int32(); + } + + //public static long genrand_int32(long[] mt, long mtiPtr) { + public long genrand_int32() { + long y; + long[] mag01= new long[2]; + mag01[0] = 0x0L; + mag01[1] = MATRIX_A; + int mti = this.mti; + + /* mag01[x] = x * MATRIX_A for x=0,1 */ + + if (mti >= N) { /* generate N words at one time */ + int kk; + + if (mti == N+1) /* if init_genrand() has not been called, */ + init_genrand(5489L); /* a default initial seed is used */ + + for (kk=0;kk> 1) ^ mag01[(int)(y & 0x1L)]; + } + for (;kk> 1) ^ mag01[(int)(y & 0x1L)]; + } + y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); + mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[(int)(y & 0x1L)]; + + mti = 0; + } + + y = mt[mti++]; + + /* Tempering */ + y ^= (y >> 11); + y ^= (y << 7) & 0x9d2c5680L; + y ^= (y << 15) & 0xefc60000L; + y ^= (y >> 18); + + this.mti = mti; + + return y; + } +} diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/Vector_t.java b/Robust/src/Benchmarks/SingleTM/Intruder/Vector_t.java new file mode 100644 index 00000000..91138e73 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/Vector_t.java @@ -0,0 +1,156 @@ +public class Vector_t { + int size; + int capacity; + Object[] elements; +// QuickSort qsort; + + public Vector_t() { +// qsort = new QuickSort(); + } + + /* ============================================================================= + * Vector_alloc + * -- Returns null if failed + * ============================================================================= + */ + public static Vector_t vector_alloc (int initCapacity) { + int capacity = Math.imax(initCapacity, 1); + Vector_t vectorPtr = new Vector_t(); + if(vectorPtr != null) { + vectorPtr.size = 0; + vectorPtr.capacity = capacity; + vectorPtr.elements = new Object[capacity]; + if(vectorPtr.elements == null) + return null; + } + return vectorPtr; + } + + /* ============================================================================= + * Vector_free + * ============================================================================= + */ + public void + vector_free () + { + elements = null; + } + + /* ============================================================================= + * Vector_at + * -- Returns null if failed + * ============================================================================= + */ + public Object vector_at (int i) { + if ((i < 0) || (i >= size)) { + System.out.println("Illegal Vector.element\n"); + return null; + } + return (elements[i]); + } + + + /* ============================================================================= + * Vector_pushBack + * -- Returns false if fail, else true + * ============================================================================= + */ + public boolean vector_pushBack (Object dataPtr) { + if (size == capacity) { + int newCapacity = capacity * 2; + Object[] newElements = new Object[newCapacity]; + + //void** newElements = (void**)malloc(newCapacity * sizeof(void*)); + if (newElements == null) { + return false; + } + capacity = newCapacity; + for (int i = 0; i < size; i++) { + newElements[i] = elements[i]; + } + elements = null; + elements = newElements; + } + + elements[size++] = dataPtr; + + return true; + } + + /* ============================================================================= + * Vector_popBack + * -- Returns null if fail, else returns last element + * ============================================================================= + */ + public Object + vector_popBack () + { + if (size < 1) { + return null; + } + + return (elements[--(size)]); + } + + /* ============================================================================= + * Vector_getSize + * ============================================================================= + */ + public int + vector_getSize () + { + return (size); + } + + /* ============================================================================= + * Vector_clear + * ============================================================================= + */ + public void + vector_clear () + { + size = 0; + } + + /* ============================================================================= + * Vector_sort + * ============================================================================= + * + public void + vector_sort () + { + //qsort.sort(elements, 0, (elements.length - 1)); + qsort.sort(elements); + //qsort(elements, size, 4, compare); + } + + * ============================================================================= + * Vector_copy + * ============================================================================= + */ + public static boolean + vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr) + { + int dstCapacity = dstVectorPtr.capacity; + int srcSize = srcVectorPtr.size; + if (dstCapacity < srcSize) { + int srcCapacity = srcVectorPtr.capacity; + Object[] elements = new Object[srcCapacity]; + + if (elements == null) { + return false; + } + dstVectorPtr.elements = null; + dstVectorPtr.elements = elements; + dstVectorPtr.capacity = srcCapacity; + } + + for(int i = 0; i< srcSize; i++) { + dstVectorPtr.elements[i] = srcVectorPtr.elements[i]; + } + + dstVectorPtr.size = srcSize; + + return true; + } +} diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/convertURNHex.java b/Robust/src/Benchmarks/SingleTM/Intruder/convertURNHex.java new file mode 100644 index 00000000..15750b0b --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/convertURNHex.java @@ -0,0 +1,35 @@ + + +public class convertURNHex extends Preprocessor +{ + public convertURNHex() { + super(); + } + public 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] = Character.toLowerCase((str_char[src+1])); + hex[1] = Character.toLowerCase((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 = String.valueOf(str_char); + } +} diff --git a/Robust/src/Benchmarks/SingleTM/Intruder/toLower.java b/Robust/src/Benchmarks/SingleTM/Intruder/toLower.java new file mode 100644 index 00000000..b52cbe25 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/Intruder/toLower.java @@ -0,0 +1,12 @@ + +public class toLower extends Preprocessor +{ + public toLower() { + super(); + } + public void process(String str) + { + return str.toLowerCase(); + } + +} -- 2.34.1