java/src/org/openantivirus/engine/censor StringFinder.java,1.1,1.2
Kurt Huwig <[email protected]> Thu, 20 May 2004 13:02:28 +0000
| Newsgroups | gmane.comp.security.virus.openantivirus.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openantivirus/java/src/org/openantivirus/engine/censor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5059/src/org/openantivirus/engine/censor
Modified Files:
StringFinder.java
Log Message:
Added multipart string finder
Speed improvements
Index: StringFinder.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/censor/StringFinder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- StringFinder.java 19 May 2004 07:33:41 -0000 1.1
+++ StringFinder.java 20 May 2004 13:02:25 -0000 1.2
@@ -26,6 +26,8 @@
*/
package org.openantivirus.engine.censor;
+import org.openantivirus.engine.credo.*;
+
/**
* Can add strings to the stringsearch and adds itself as a listener to it
*
@@ -40,18 +42,17 @@
this.stringSearch = stringSearch;
}
- public void addString(byte[] abPattern,
- int[] skipList,
+ public void addString(WildcardPattern wp,
int offset,
PositionFoundListener pfl) {
- final byte[] searchPattern = new byte[abPattern.length - offset];
- System.arraycopy(abPattern, offset,
+ final byte[] searchPattern = new byte[wp.pattern.length - offset];
+ System.arraycopy(wp.pattern, offset,
searchPattern, 0, searchPattern.length);
stringSearch.addString(searchPattern,
- new PartialStringFoundListener(abPattern,
- skipList,
- offset,
- pfl));
+ new PartialStringFoundListener(wp.pattern,
+ wp.skipList,
+ offset,
+ pfl));
}
private static class PartialStringFoundListener
@@ -77,35 +78,42 @@
return;
}
- byte[] abBuffer = pfe.buffer;
+ final byte[] abBuffer = pfe.buffer;
int iBufferPos = pfe.bufferOffset - offset;
if (iBufferPos < 0) {
iBufferPos += abBuffer.length;
}
- int iSuffixEnd = pfe.bufferOffset + pfe.suffix;
+ final int iSuffixEnd = pfe.bufferOffset + pfe.suffix;
- boolean skip = false;
int skipIndex = 0;
int skipCount = skipList[0];
for (int i = 0; i < abPattern.length; i++) {
- iBufferPos %= abBuffer.length;
if (iBufferPos == iSuffixEnd) {
return;
}
if (skipCount == 0) {
skipCount = skipList[++skipIndex];
- skip = !skip;
+ i += skipCount;
+ iBufferPos += skipCount;
+ if (iBufferPos >= abBuffer.length) {
+ iBufferPos -= abBuffer.length;
+ }
+ skipCount = skipList[++skipIndex];
}
skipCount--;
- if (!skip && abPattern[i] != abBuffer[iBufferPos]) {
+ if (abPattern[i] != abBuffer[iBufferPos]) {
return;
}
+
iBufferPos++;
+ if (iBufferPos == abBuffer.length) {
+ iBufferPos -= abBuffer.length;
+ }
}
pfl.positionFound(pfe);
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click