java/src/org/openantivirus/engine/censor PositionFoundListener.java,NONE,1.1 PositionFoundEvent.java,NONE,1.1 StringFinder.java,NONE,1.1 StringSearch.java,NONE,1.1
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/engine/censor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1513/src/org/openantivirus/engine/censor Added Files: PositionFoundListener.java PositionFoundEvent.java StringFinder.java StringSearch.java Log Message: Added MatchArrayCensor Code cleanup Virus name without offset --- NEW FILE: PositionFoundEvent.java --- /* * $Id: PositionFoundEvent.java,v 1.1 2004/05/19 07:33:41 kurti Exp $ * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is OAV. * * The Initial Developer of the Original Code is Kurt Huwig <[email protected]>. * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ package org.openantivirus.engine.censor; import org.openantivirus.engine.vfs.*; /** * Indication the position within the file where something has been found * * Pattern-Roles: * @author Kurt Huwig <[email protected]> * @version $Revision: 1.1 $ */ public class PositionFoundEvent { public final byte[] buffer; public final VfsEntry entry; public final long fileOffset; public final int bufferOffset, length, prefix, suffix; /** * @param entry the entry containing the position * @param fileOffset offset within the file * @param buffer the (ring) buffer containing the string found * @param bufferOffset offset of the start of the string within the buffer * @param length length of the string found * @param prefixLength number of valid bytes before the offset byte * @param suffixLength number of valid bytes after the offset byte */ public PositionFoundEvent(VfsEntry entry, long fileOffset, byte[] buffer, int bufferOffset, int length, int prefix, int suffix) { this.entry = entry; this.fileOffset = fileOffset; this.buffer = buffer; this.bufferOffset = bufferOffset; this.length = length; this.prefix = prefix; this.suffix = suffix; } } --- NEW FILE: StringSearch.java --- /* * $Id: StringSearch.java,v 1.1 2004/05/19 07:33:41 kurti Exp $ * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is OAV. * * The Initial Developer of the Original Code is Kurt Huwig <[email protected]>. * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ package org.openantivirus.engine.censor; /** * Searches for strings * * Pattern-Roles: * @author Kurt Huwig <[email protected]> * @version $Revision: 1.1 $ */ public interface StringSearch { void addString(byte[] abPattern, PositionFoundListener pfl); /** * Prepares the search for usage. This method has to be called before the * it can be used */ void prepare(); Censor getCensor(); } --- NEW FILE: PositionFoundListener.java --- /* * $Id: PositionFoundListener.java,v 1.1 2004/05/19 07:33:41 kurti Exp $ * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is OAV. * * The Initial Developer of the Original Code is Kurt Huwig <[email protected]>. * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ package org.openantivirus.engine.censor; /** * Listener for events meaning that something has been found * * Pattern-Roles: * @author Kurt Huwig <[email protected]> * @version $Revision: 1.1 $ */ public interface PositionFoundListener { void positionFound(PositionFoundEvent pfe) throws MalwareFoundException; } --- NEW FILE: StringFinder.java --- /* * $Id: StringFinder.java,v 1.1 2004/05/19 07:33:41 kurti Exp $ * * ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is OAV. * * The Initial Developer of the Original Code is Kurt Huwig <[email protected]>. * Portions created by the Initial Developer are Copyright (C) 2001-2003 * the Initial Developer. All Rights Reserved. * * Contributor(s): * * ***** END LICENSE BLOCK ***** */ package org.openantivirus.engine.censor; /** * Can add strings to the stringsearch and adds itself as a listener to it * * Pattern-Roles: * @author Kurt Huwig <[email protected]> * @version $Revision: 1.1 $ */ public class StringFinder { private StringSearch stringSearch; public StringFinder(StringSearch stringSearch) { this.stringSearch = stringSearch; } public void addString(byte[] abPattern, int[] skipList, int offset, PositionFoundListener pfl) { final byte[] searchPattern = new byte[abPattern.length - offset]; System.arraycopy(abPattern, offset, searchPattern, 0, searchPattern.length); stringSearch.addString(searchPattern, new PartialStringFoundListener(abPattern, skipList, offset, pfl)); } private static class PartialStringFoundListener implements PositionFoundListener { private byte[] abPattern; private int [] skipList; private int offset; private PositionFoundListener pfl; public PartialStringFoundListener(byte[] abPattern, int[] skipList, int offset, PositionFoundListener pfl) { this.abPattern = abPattern; this.skipList = skipList; this.offset = offset; this.pfl = pfl; } public void positionFound(PositionFoundEvent pfe) throws MalwareFoundException { if (pfe.fileOffset < offset) { return; } byte[] abBuffer = pfe.buffer; int iBufferPos = pfe.bufferOffset - offset; if (iBufferPos < 0) { iBufferPos += abBuffer.length; } 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; } skipCount--; if (!skip && abPattern[i] != abBuffer[iBufferPos]) { return; } iBufferPos++; } pfl.positionFound(pfe); } } } ------------------------------------------------------- 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