java/src/org/openantivirus/util SignatureKeyGenerator.java,1.2,1.3 PatternFinder.java,1.14,1.15
Kurt Huwig <[email protected]>
| 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-serv20313/src/org/openantivirus/util
Modified Files:
SignatureKeyGenerator.java PatternFinder.java
Log Message:
Removed unused imports
Fixed problems found by FindBugs
Index: SignatureKeyGenerator.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/util/SignatureKeyGenerator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SignatureKeyGenerator.java 10 Apr 2002 16:29:27 -0000 1.2
+++ SignatureKeyGenerator.java 1 May 2004 14:36:11 -0000 1.3
@@ -23,7 +23,6 @@
package org.openantivirus.util;
import java.io.*;
-import java.math.*;
import java.security.*;
import java.security.interfaces.*;
import java.security.spec.*;
Index: PatternFinder.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/util/PatternFinder.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- PatternFinder.java 8 Mar 2002 09:53:39 -0000 1.14
+++ PatternFinder.java 1 May 2004 14:36:11 -0000 1.15
@@ -206,16 +206,28 @@
System.err.println(' ');
if (infections.size() > 0 ) {
- InputStream isVirus = new FileInputStream(sFilename);
- OutputStream osInfected = new FileOutputStream(sFilename
- + INFECTED_SUFFIX);
- OutputStream osCleared = new FileOutputStream(sFilename
- + CLEARED_SUFFIX);
- printInfections(virusName, infections, fileLength,
- isVirus, osInfected, osCleared);
- isVirus.close();
- osInfected.close();
- osCleared.close();
+ InputStream isVirus = null;
+ OutputStream osInfected = null;
+ OutputStream osCleared = null;
+ try {
+ isVirus = new FileInputStream(sFilename);
+ osInfected = new FileOutputStream(sFilename
+ + INFECTED_SUFFIX);
+ osCleared = new FileOutputStream(sFilename
+ + CLEARED_SUFFIX);
+ printInfections(virusName, infections, fileLength,
+ isVirus, osInfected, osCleared);
+ } finally {
+ if (isVirus != null) {
+ isVirus.close();
+ }
+ if (osInfected != null) {
+ osInfected.close();
+ }
+ if (osCleared != null) {
+ osCleared.close();
+ }
+ }
}
cleanUp();
}
@@ -225,23 +237,27 @@
* creates the files for all workers
*/
protected void createWorkerFiles() throws IOException {
- InputStream is = new FileInputStream(sFilename);
-
OutputStream[] aOs = new OutputStream[workerCount];
- for (int i = 0; i < workerCount; i++) {
- aOs[i] = new FileOutputStream(workFileNames[i]);
- }
-
- byte[] abBuffer = new byte[BUFFER_LENGTH];
- int iLength;
- while ((iLength = is.read(abBuffer)) != -1) {
+ InputStream is = new FileInputStream(sFilename);
+ try {
for (int i = 0; i < workerCount; i++) {
- aOs[i].write(abBuffer, 0, iLength);
+ aOs[i] = new FileOutputStream(workFileNames[i]);
}
- }
-
- for (int i = 0; i < workerCount; i++) {
- aOs[i].close();
+
+ byte[] abBuffer = new byte[BUFFER_LENGTH];
+ int iLength;
+ while ((iLength = is.read(abBuffer)) != -1) {
+ for (int i = 0; i < workerCount; i++) {
+ aOs[i].write(abBuffer, 0, iLength);
+ }
+ }
+ } finally {
+ for (int i = 0; i < workerCount; i++) {
+ if (aOs[i] != null) {
+ aOs[i].close();
+ }
+ }
+ is.close();
}
}
@@ -294,104 +310,110 @@
private void clearArea(long lStart, long lEnd, String clearFile,
String testfile) throws IOException {
InputStream is = new FileInputStream(clearFile);
- OutputStream os = new FileOutputStream(testfile);
-
- byte[] ab = new byte[BUFFER_LENGTH];
- long lPos = 0;
- int iLength;
-
- while (lPos < lStart
- && (iLength = is.read(ab, 0, Math.min(BUFFER_LENGTH,
- (int) (lStart - lPos))))
- != -1) {
- os.write(ab, 0, iLength);
- lPos += iLength;
- }
-
- while (lPos < lEnd
- && (iLength = is.read(ab, 0, Math.min(BUFFER_LENGTH,
- (int) (lEnd - lPos))))
- != -1) {
- boolean bArrayChanged = false;
- for (int i = Math.min(BUFFER_LENGTH - 1, (int) (lEnd - lPos)) - 1;
- i >= 0; i--) {
- if (ab[i] == FILLBYTE1) {
- abOverwrite[i] = FILLBYTE2;
- bArrayChanged = true;
+ try {
+ OutputStream os = new FileOutputStream(testfile);
+ try {
+ byte[] ab = new byte[BUFFER_LENGTH];
+ long lPos = 0;
+ int iLength;
+
+ while (lPos < lStart
+ && (iLength = is.read(ab, 0, Math.min(BUFFER_LENGTH,
+ (int) (lStart - lPos))))
+ != -1) {
+ os.write(ab, 0, iLength);
+ lPos += iLength;
}
- }
- os.write(abOverwrite, 0, iLength);
- if (bArrayChanged) {
- for (int i = Math.min(BUFFER_LENGTH - 1, (int) (lEnd - lPos)) - 1;
- i >= 0; i--) {
- abOverwrite[i] = FILLBYTE1;
+
+ while (lPos < lEnd
+ && (iLength = is.read(ab, 0, Math.min(BUFFER_LENGTH,
+ (int) (lEnd - lPos))))
+ != -1) {
+ boolean bArrayChanged = false;
+ for (int i = Math.min(BUFFER_LENGTH - 1, (int) (lEnd - lPos)) - 1;
+ i >= 0; i--) {
+ if (ab[i] == FILLBYTE1) {
+ abOverwrite[i] = FILLBYTE2;
+ bArrayChanged = true;
+ }
+ }
+ os.write(abOverwrite, 0, iLength);
+ if (bArrayChanged) {
+ for (int i = Math.min(BUFFER_LENGTH - 1, (int) (lEnd - lPos)) - 1;
+ i >= 0; i--) {
+ abOverwrite[i] = FILLBYTE1;
+ }
+ bArrayChanged = false;
+ }
+ lPos += iLength;
}
- bArrayChanged = false;
+
+ while ((iLength = is.read(ab)) != -1) {
+ os.write(ab, 0, iLength);
+ }
+ } finally {
+ os.close();
}
- lPos += iLength;
- }
-
- while ((iLength = is.read(ab)) != -1) {
- os.write(ab, 0, iLength);
+ } finally {
+ is.close();
}
-
- os.close();
- is.close();
}
/**
- * checks files for virii
+ * checks files for viruses
*
* @return array containing the infection-status of the file
*/
protected boolean[] checkFiles(String[] scanArgs, int checkWorkerCount,
String virusName) {
try {
- Process p = runtime.exec(scanArgs);
- int iExit = p.waitFor();
- BufferedReader br = new BufferedReader(new InputStreamReader(
- p.getInputStream()));
-
- boolean[] result = new boolean[checkWorkerCount];
- String sLine;
- while ((sLine = br.readLine()) != null) {
- for (int worker = 0; worker < checkWorkerCount; worker++) {
- if (sLine.indexOf(testFileNames[worker]) != -1) {
- for (int line = 0; line < skipLines; line++) {
- sLine = br.readLine();
- }
- int iStartPos = sLine.indexOf(virusNamePrefix);
- int iEndPos = sLine.lastIndexOf(virusNamePostfix);
- if (iStartPos != -1 && iEndPos != -1) {
- final String newVirusName = sLine.substring(
- iStartPos + virusNamePostfix.length(),
- iEndPos);
- if (newVirusName.equals(virusName)) {
- result[worker] = true;
- } else {
- if (newVirii.get(newVirusName) == null
- && knownVirii.get(newVirusName)
- == null) {
- final String virusFileName =
- VIRUS_FILE + (virusCount++);
- newVirii.put(newVirusName, virusFileName);
- copyFile(testFileNames[worker],
- virusFileName);
+ final Process p = runtime.exec(scanArgs);
+ p.waitFor();
+ final BufferedReader br = new BufferedReader(
+ new InputStreamReader(p.getInputStream()));
+ boolean[] result;
+ try {
+ result = new boolean[checkWorkerCount];
+ String sLine;
+ while ((sLine = br.readLine()) != null) {
+ for (int worker = 0; worker < checkWorkerCount; worker++) {
+ if (sLine.indexOf(testFileNames[worker]) != -1) {
+ for (int line = 0; line < skipLines; line++) {
+ sLine = br.readLine();
+ }
+ int iStartPos = sLine.indexOf(virusNamePrefix);
+ int iEndPos = sLine.lastIndexOf(virusNamePostfix);
+ if (iStartPos != -1 && iEndPos != -1) {
+ final String newVirusName = sLine.substring(
+ iStartPos + virusNamePostfix.length(),
+ iEndPos);
+ if (newVirusName.equals(virusName)) {
+ result[worker] = true;
+ } else {
+ if (newVirii.get(newVirusName) == null
+ && knownVirii.get(newVirusName)
+ == null) {
+ final String virusFileName =
+ VIRUS_FILE + (virusCount++);
+ newVirii.put(newVirusName, virusFileName);
+ copyFile(testFileNames[worker],
+ virusFileName);
+ }
}
}
}
}
}
+ } finally {
+ br.close();
}
-
- br.close();
p.getOutputStream().close();
p.getErrorStream().close();
return result;
} catch( Exception e ) {
e.printStackTrace();
- return null;
+ return new boolean[0];
}
}
@@ -524,15 +546,20 @@
protected void copyFile(String source, String destination)
throws IOException {
final InputStream is = new FileInputStream(source);
- final OutputStream os = new FileOutputStream(destination);
-
- byte[] abBuffer = new byte[BUFFER_LENGTH];
- int iLength;
- while((iLength = is.read(abBuffer)) != -1) {
- os.write(abBuffer, 0, iLength);
+ try {
+ final OutputStream os = new FileOutputStream(destination);
+ try {
+ byte[] abBuffer = new byte[BUFFER_LENGTH];
+ int iLength;
+ while((iLength = is.read(abBuffer)) != -1) {
+ os.write(abBuffer, 0, iLength);
+ }
+ } finally {
+ os.close();
+ }
+ } finally {
+ is.close();
}
- is.close();
- os.close();
}
public static void main(String[] asParams) {
-------------------------------------------------------
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