java/src/org/openantivirus/engine/vfs/container DirectoryContainer.java,1.3,1.4 CompressedContainerFactory.java,1.5,1.6 ArchiveContainer.java,1.3,1.4 UpxContainer.java,1.2,1.3 SingleFileContainer.java,1.3,1.4
Kurt Huwig <[email protected]> Sat, 03 Sep 2005 16:16:42 +0000
| Newsgroups | gmane.comp.security.virus.openantivirus.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28211/src/org/openantivirus/engine/vfs/container
Modified Files:
DirectoryContainer.java CompressedContainerFactory.java
ArchiveContainer.java UpxContainer.java
SingleFileContainer.java
Log Message:
Code cleanup
Index: ArchiveContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/ArchiveContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ArchiveContainer.java 31 May 2004 10:18:08 -0000 1.3
+++ ArchiveContainer.java 3 Sep 2005 16:16:40 -0000 1.4
@@ -41,17 +41,17 @@
*/
public abstract class ArchiveContainer implements VfsContainer {
- private final VfsEntry entry;
+ protected final VfsEntry entry;
+ protected final TemporaryDirectory tempDir;
+
private final String type;
- private final TemporaryDirectory tempDir;
private DirectoryContainer directory;
private final ScanConfiguration scanConf;
private boolean initialized = false;
protected ArchiveContainer(VfsEntry entry,
String type,
- ScanConfiguration scanConf)
- throws IOException{
+ ScanConfiguration scanConf) {
this.entry = entry;
this.type = type;
this.scanConf = scanConf;
@@ -61,7 +61,7 @@
protected void init() throws IOException {
try {
- extractArchive(entry, tempDir.getDirectory());
+ extractArchive();
directory = new DirectoryContainer(
new FileVfsEntry(tempDir.getDirectory(),
entry.getName() + type),
@@ -76,8 +76,7 @@
initialized = true;
}
- public abstract void extractArchive(VfsEntry entry, File tempDir)
- throws IOException;
+ public abstract void extractArchive() throws IOException;
public boolean hasNext() throws IOException {
if (!initialized) {
@@ -100,24 +99,24 @@
}
protected void runCommand(String[] command,
- File directory) throws IOException {
- runCommand(command, directory, null);
+ File runDirectory) throws IOException {
+ runCommand(command, runDirectory, null);
}
protected void runCommand(String[] command,
- File directory,
+ File runDirectory,
OutputStream os) throws IOException {
- runCommand(command, directory, null, true);
+ runCommand(command, runDirectory, null, true);
}
protected void runCommand(String[] command,
- File directory,
+ File runDirectory,
OutputStream os,
boolean closeStdIn) throws IOException {
Process process = null;
try {
- process = Runtime.getRuntime().exec(command, null, directory);
+ process = Runtime.getRuntime().exec(command, null, runDirectory);
if (closeStdIn) {
process.getOutputStream().close();
}
Index: DirectoryContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/DirectoryContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- DirectoryContainer.java 26 May 2004 20:19:53 -0000 1.3
+++ DirectoryContainer.java 3 Sep 2005 16:16:40 -0000 1.4
@@ -135,14 +135,14 @@
protected File getNext() {
if (currentIndex < currentFiles.length) {
return currentFiles[currentIndex++];
- } else {
- if (directories.isEmpty()) {
- return null;
- } else {
- handleDirectory((File) directories.removeFirst());
- return getNext();
- }
}
+
+ if (directories.isEmpty()) {
+ return null;
+ }
+
+ handleDirectory((File) directories.removeFirst());
+ return getNext();
}
/**
Index: UpxContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/UpxContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- UpxContainer.java 23 May 2004 14:39:19 -0000 1.2
+++ UpxContainer.java 3 Sep 2005 16:16:40 -0000 1.3
@@ -52,10 +52,9 @@
init();
}
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
try {
- final OutputStream os = new FileOutputStream(tempFile);
+ final OutputStream os = new FileOutputStream(tempFile.getFile());
try {
upxDecompress.decompress(os);
@@ -73,7 +72,7 @@
if (Runtime.getRuntime().exec(new String[] {
"upx",
"-dq",
- "-o" + tempFile.getCanonicalPath(),
+ "-o" + tempFile.getFile().getCanonicalPath(),
entry.getFile().getCanonicalPath()}).waitFor()
!= 0) {
throw new IOException("Broken UPX file");
Index: CompressedContainerFactory.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/CompressedContainerFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- CompressedContainerFactory.java 31 May 2004 10:18:08 -0000 1.5
+++ CompressedContainerFactory.java 3 Sep 2005 16:16:40 -0000 1.6
@@ -107,13 +107,12 @@
if (scanConf.getBoolean("vfs.archive.bzip2")
&& startsWithMagic(start, BZIP2_MAGIC)) {
return new SingleFileContainer(entry, "bzip2", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
runCommand(new String[] {
"bunzip2",
"-c",
entry.getFile().getCanonicalPath()},
- tempFile);
+ tempFile.getFile());
}
};
}
@@ -122,10 +121,10 @@
if (scanConf.getBoolean("vfs.archive.gzip")
&& startsWithMagic(start, GZIP_MAGIC)) {
return new SingleFileContainer(entry, "gzip", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
- copyStream(new GZIPInputStream(new FileInputStream(entry.getFile())),
- new FileOutputStream(tempFile));
+ public void extractFile() throws IOException {
+ copyStream(new GZIPInputStream(
+ new FileInputStream(entry.getFile())),
+ new FileOutputStream(tempFile.getFile()));
}
};
}
@@ -134,13 +133,13 @@
if (scanConf.getBoolean("vfs.archive.tar")
&& containsMagic(start, TAR_MAGIC, 257)) {
return new ArchiveContainer(entry, " >> tar:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
+ public void extractArchive()
throws IOException {
runCommand(new String[] {
"tar",
"xfC",
entry.getFile().getCanonicalPath(),
- tempDir.getCanonicalPath()});
+ tempDir.getDirectory().getCanonicalPath()});
}
};
}
@@ -149,12 +148,11 @@
if (scanConf.getBoolean("vfs.archive.cab")
&& startsWithMagic(start, CAB_MAGIC)) {
return new ArchiveContainer(entry, " >> cab:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"cabextract",
"-d",
- tempDir.getCanonicalPath(),
+ tempDir.getDirectory().getCanonicalPath(),
entry.getFile().getCanonicalPath()});
}
};
@@ -167,13 +165,12 @@
return new ArchiveContainer(entry,
" >> rar-exe:",
scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unrar",
"x",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -194,9 +191,8 @@
}
if (canUnpack) {
return new UpxContainer(entry, upxDecompress, scanConf);
- } else {
- raf.close();
}
+ raf.close();
}
}
@@ -204,14 +200,13 @@
if (scanConf.getBoolean("vfs.archive.ace")
&& containsMagic(start, ACE_MAGIC, 7)) {
return new ArchiveContainer(entry, " >> ace:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unace",
"x",
"-y",
entry.getFile().getCanonicalPath()},
- tempDir,
+ tempDir.getDirectory(),
null,
false);
}
@@ -222,13 +217,12 @@
if (scanConf.getBoolean("vfs.archive.ar")
&& startsWithMagic(start, AR_MAGIC)) {
return new ArchiveContainer(entry, " >> ar:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"ar",
"x",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -237,13 +231,12 @@
if (scanConf.getBoolean("vfs.archive.rar")
&& startsWithMagic(start, RAR_MAGIC)) {
return new ArchiveContainer(entry, " >> rar:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unrar",
"x",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -264,11 +257,11 @@
|| containsMagic(start, LHAZ4_MAGIC, 2)
|| containsMagic(start, LHAZ5_MAGIC, 2))) {
return new ArchiveContainer(entry, " >> lha:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"lha",
- "xw=" + tempDir.getCanonicalPath(),
+ "xw="
+ + tempDir.getDirectory().getCanonicalPath(),
entry.getFile().getCanonicalPath()});
}
};
@@ -278,13 +271,12 @@
if (scanConf.getBoolean("vfs.archive.arj")
&& startsWithMagic(start, ARJ_MAGIC)) {
return new ArchiveContainer(entry, " >> arj:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unarj",
"x",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -293,13 +285,13 @@
if (scanConf.getBoolean("vfs.archive.zoo")
&& containsMagic(start, ZOO_MAGIC, 0x14)) {
return new ArchiveContainer(entry, " >> zoo:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unzoo",
"-x",
"-j",
- tempDir.getCanonicalPath() + File.separator,
+ tempDir.getDirectory().getCanonicalPath()
+ + File.separator,
entry.getFile().getCanonicalPath()});
}
};
@@ -313,14 +305,13 @@
|| startsWithMagic(start, CPIO2_MAGIC)
|| startsWithMagic(start, CPIO7_MAGIC))) {
return new ArchiveContainer(entry, " >> cpio:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"cpio",
"-i",
"-F",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -329,14 +320,13 @@
if (scanConf.getBoolean("vfs.archive.tnef")
&& startsWithMagic(start, TNEF_MAGIC)) {
return new ArchiveContainer(entry, " >> tnef:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"tnef",
"-f",
entry.getFile().getCanonicalPath(),
"-C",
- tempDir.getCanonicalPath()});
+ tempDir.getDirectory().getCanonicalPath()});
}
};
}
@@ -345,12 +335,11 @@
if (scanConf.getBoolean("vfs.archive.shar")
&& containsMagic(start, SHAR_MAGIC, 10)) {
return new ArchiveContainer(entry, " >> shar:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"unshar",
"-d",
- tempDir.getCanonicalPath(),
+ tempDir.getDirectory().getCanonicalPath(),
entry.getFile().getCanonicalPath()});
}
};
@@ -360,14 +349,13 @@
if (scanConf.getBoolean("vfs.archive.uuencode")
&& startsWithMagic(start, UUENC_MAGIC)) {
return new SingleFileContainer(entry, "uuencode", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
runCommand(new String[] {
"uudecode",
"-o",
"/dev/stdout",
entry.getFile().getCanonicalPath()},
- tempFile);
+ tempFile.getFile());
}
};
}
@@ -376,14 +364,13 @@
if (scanConf.getBoolean("vfs.archive.compress")
&& startsWithMagic(start, COMPR_MAGIC)) {
return new SingleFileContainer(entry, "compress", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
runCommand(new String[] {
"uncompress",
"-d",
"-c",
entry.getFile().getCanonicalPath()},
- tempFile);
+ tempFile.getFile());
}
};
}
@@ -392,14 +379,13 @@
if (scanConf.getBoolean("vfs.archive.rpm")
&& startsWithMagic(start, RPM_MAGIC)) {
return new ArchiveContainer(entry, " >> rpm:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"rpm2cpio",
entry.getFile().getCanonicalPath()},
- tempDir,
+ tempDir.getDirectory(),
new FileOutputStream(
- tempDir.getCanonicalPath()
+ tempDir.getDirectory().getCanonicalPath()
+ File.separator + "rpm.cpio"),
false);
}
@@ -415,13 +401,12 @@
|| startsWithMagic(start, ARC8_MAGIC)
|| startsWithMagic(start, ARC9_MAGIC))) {
return new ArchiveContainer(entry, " >> arc:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
runCommand(new String[] {
"arc",
"x",
entry.getFile().getCanonicalPath()},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -430,14 +415,13 @@
if (scanConf.getBoolean("vfs.archive.lzo")
&& startsWithMagic(start, LZO_MAGIC)) {
return new SingleFileContainer(entry, "lzop", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
runCommand(new String[] {
"lzop",
"-d",
"-c",
entry.getFile().getCanonicalPath()},
- tempFile);
+ tempFile.getFile());
}
};
}
@@ -446,10 +430,10 @@
if (scanConf.getBoolean("vfs.archive.ppmd")
&& startsWithMagic(start, PPMD_MAGIC)) {
return new ArchiveContainer(entry, " >> ppmd:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
final String tempFilename =
- tempDir.getCanonicalPath() + File.separator
+ tempDir.getDirectory().getCanonicalPath()
+ + File.separator
+ "file.pmd";
SingleFileContainer.copyStream(
new FileInputStream(entry.getFile()),
@@ -459,7 +443,7 @@
"d",
"-d",
tempFilename},
- tempDir);
+ tempDir.getDirectory());
}
};
}
@@ -468,14 +452,13 @@
if (scanConf.getBoolean("vfs.archive.dact")
&& startsWithMagic(start, DACT_MAGIC)) {
return new SingleFileContainer(entry, "dact", scanConf) {
- public void extractFile(VfsEntry entry, File tempFile)
- throws IOException {
+ public void extractFile() throws IOException {
runCommand(new String[] {
"dact",
"-d",
"-c",
entry.getFile().getCanonicalPath()},
- tempFile);
+ tempFile.getFile());
}
};
}
@@ -484,8 +467,7 @@
if (scanConf.getBoolean("vfs.archive.dar")
&& startsWithMagic(start, DAR_MAGIC)) {
return new ArchiveContainer(entry, " >> dar:", scanConf) {
- public void extractArchive(VfsEntry entry, File tempDir)
- throws IOException {
+ public void extractArchive() throws IOException {
final String filename = entry.getFile().getCanonicalPath();
runCommand(new String[] {
"dar",
@@ -497,7 +479,7 @@
filename.lastIndexOf('.') - 1)),
"-O",
"-N"},
- tempDir);
+ tempDir.getDirectory());
}
};
}
Index: SingleFileContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/SingleFileContainer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- SingleFileContainer.java 23 May 2004 14:39:19 -0000 1.3
+++ SingleFileContainer.java 3 Sep 2005 16:16:40 -0000 1.4
@@ -42,9 +42,10 @@
public abstract class SingleFileContainer extends VfsEntry
implements VfsContainer {
+ protected final TemporaryFile tempFile;
+ protected final VfsEntry entry;
+
private final VfsEntry fileEntry;
- private final TemporaryFile tempFile;
- private final VfsEntry entry;
private final String type;
private boolean read = false;
private boolean initialized = false;
@@ -61,7 +62,7 @@
protected void init() throws IOException {
try {
- extractFile(entry, tempFile.getFile());
+ extractFile();
} catch (Exception e) {
tempFile.delete();
throw new IOException("error while extracting: " + e.getMessage());
@@ -70,8 +71,7 @@
initialized = true;
}
- public abstract void extractFile(VfsEntry entry, File tempFile)
- throws IOException;
+ public abstract void extractFile() throws IOException;
public void dispose() throws IOException {
tempFile.delete();
@@ -112,12 +112,13 @@
return entry.getName() + " >> " + type;
}
- protected void runCommand(final String[] command, File tempFile) throws IOException, FileNotFoundException {
+ protected void runCommand(final String[] command, File workFile)
+ throws IOException, FileNotFoundException {
Process process = null;
try {
process = Runtime.getRuntime().exec(command);
copyStream(process.getInputStream(),
- new FileOutputStream(tempFile));
+ new FileOutputStream(workFile));
} finally {
if (process != null) {
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf