java/src/org/openantivirus/util PatternOptimizer.java,1.1,1.2

Kurt Huwig <[email protected]> Wed, 19 May 2004 07:33:44 +0000
Newsgroups gmane.comp.security.virus.openantivirus.cvs
Message-ID <[email protected]>
Update of /cvsroot/openantivirus/java/src/org/openantivirus/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1513/src/org/openantivirus/util

Modified Files:
	PatternOptimizer.java 
Log Message:
Added MatchArrayCensor
Code cleanup
Virus name without offset

Index: PatternOptimizer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/util/PatternOptimizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- PatternOptimizer.java	18 May 2004 09:03:31 -0000	1.1
+++ PatternOptimizer.java	19 May 2004 07:33:42 -0000	1.2
@@ -43,16 +43,17 @@
         final InputStream is = new FileInputStream("/home/kurt/test.bin");
         final byte[] buffer = new byte[16384];
         
-        final int[] count = new int[1 << 24];
+        final int[] count = new int[1 << 16];
+        final int[] used  = new int[1 << 16];
         
         System.err.println("Zaehle...");
         int length;
-        is.read(buffer, 0, 2);
-        int triple = ((buffer[0] & 0xff) << 8) | (buffer[1] & 0xff);
+        is.read(buffer, 0, 1);
+        int triple = buffer[0] & 0xff;
         while ((length = is.read(buffer)) != -1) {
             
             for (int i = 0; i < length; i++) {
-                triple &= 0xffff;
+                triple &= 0xff;
                 triple <<= 8;
                 triple |= buffer[i] & 0xff;
                 
@@ -78,15 +79,15 @@
             int min = Integer.MAX_VALUE;
             int minPos = 0;
             int pos = 0;
+            int minTriple = 0;
             for (int j = 0; j < wp.skipList.length; j++) {
                 final int skipCount = wp.skipList[j];
                 
-                if (j % 2 == 0 && skipCount >= 3) {
-                    triple = ((wp.pattern[pos] & 0xff) << 8)
-                             | (wp.pattern[pos + 1] & 0xff);
+                if (j % 2 == 0 && skipCount >= 2) {
+                    triple = wp.pattern[pos] & 0xff;
                     
-                    for (int i = 2; i < skipCount; i++) {
-                        triple &= 0xffff;
+                    for (int i = 1; i < skipCount; i++) {
+                        triple &= 0xff;
                         triple <<= 8;
                         triple |= wp.pattern[pos + i] & 0xff;
                         
@@ -94,6 +95,7 @@
                         if (tripleCount <= min) {
                             min = tripleCount;
                             minPos = pos + i;
+                            minTriple = triple;
                         }
                     }
                 }
@@ -107,8 +109,9 @@
             }
             
             System.out.println(
-                    line.substring(0, equalPos) + "[" + (minPos - 2) + "]=" +
+                    line.substring(0, equalPos) + "[" + (minPos - 1) + "]=" +
                     sPattern);
+            used[minTriple] += min;
         }
         br.close();
         



-------------------------------------------------------
This SF.Net email is sponsored by: SourceForge.net Broadband
Sign-up now for SourceForge Broadband and get the fastest
6.0/768 connection for only $19.95/mo for the first 3 months!
http://ads.osdn.com/?ad_id=2562&alloc_id=6184&op=click