java/src/org/openantivirus/engine/vfs/container CompressedContainerFactory.java,1.1,1.2 ArchiveContainer.java,1.1,1.2 UpxContainer.java,1.1,1.2 SingleFileContainer.java,1.2,1.3 GzipContainer.java,1.1,NONE TarContainer.java,1.1,NONE Bzip2Container.java,1.1,NONE
Kurt Huwig <[email protected]> Sun, 23 May 2004 14:39:21 +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-serv31740/src/org/openantivirus/engine/vfs/container
Modified Files:
CompressedContainerFactory.java ArchiveContainer.java
UpxContainer.java SingleFileContainer.java
Removed Files:
GzipContainer.java TarContainer.java Bzip2Container.java
Log Message:
Added more decompressors:
- ace
- ar
- arc
- arj
- cab
- cpio
- compress
- dact
- dar
- self-extrating rar
- lha
- lzop
- PPMd
- rar
- rpm
- shar
- tnef
- uuencode
- zoo
--- Bzip2Container.java DELETED ---
--- GzipContainer.java DELETED ---
--- TarContainer.java DELETED ---
Index: CompressedContainerFactory.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/CompressedContainerFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CompressedContainerFactory.java 14 Dec 2003 11:08:26 -0000 1.1
+++ CompressedContainerFactory.java 23 May 2004 14:39:19 -0000 1.2
@@ -27,6 +27,7 @@
package org.openantivirus.engine.vfs.container;
import java.io.*;
+import java.util.zip.*;
import org.openantivirus.engine.*;
import org.openantivirus.engine.vfs.*;
@@ -41,12 +42,50 @@
*/
public class CompressedContainerFactory implements VfsContainerFactory {
private final byte[]
- ZIP_MAGIC = {'P', 'K', 3, 4},
+ ACE_MAGIC = "**ACE**".getBytes(),
+ AR_MAGIC = "!<arch>".getBytes(),
+ ARC2_MAGIC = {(byte)0x1a, (byte)0x02},
+ ARC3_MAGIC = {(byte)0x1a, (byte)0x03},
+ ARC4_MAGIC = {(byte)0x1a, (byte)0x04},
+ ARC6_MAGIC = {(byte)0x1a, (byte)0x06},
+ ARC8_MAGIC = {(byte)0x1a, (byte)0x08},
+ ARC9_MAGIC = {(byte)0x1a, (byte)0x09},
+ ARJ_MAGIC = {(byte)0x60, (byte)0xea},
CAB_MAGIC = {'M', 'S', 'C', 'F', 0, 0, 0, 0},
- EXE_MAGIC = {'M', 'Z'},
- BZIP2_MAGIC = {'B', 'Z', 'h'},
+ CPIO_MAGIC = {(byte)0xc7, (byte)0x71},
+ CPIOS_MAGIC = {(byte)0x71, (byte)0xc7},
+ CPIO1_MAGIC = "070701".getBytes(),
+ CPIO2_MAGIC = "070702".getBytes(),
+ CPIO7_MAGIC = "070707".getBytes(),
+ COMPR_MAGIC = {(byte)0x1f, (byte)0x9d},
+ DACT_MAGIC = {(byte)0x44, (byte)0x43, (byte)0x54, (byte)0xc3},
+ DAR_MAGIC = {(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x7b},
+ EXE_MAGIC = "MZ".getBytes(),
+ BZIP2_MAGIC = "BZh".getBytes(),
GZIP_MAGIC = {(byte)0x1f, (byte)0x8b},
- TAR_MAGIC = {'u', 's', 't', 'a', 'r'};
+ LHA__MAGIC = "-lh -".getBytes(),
+ LHA0_MAGIC = "-lh0-".getBytes(),
+ LHA1_MAGIC = "-lh1-".getBytes(),
+ LHA2_MAGIC = "-lh2-".getBytes(),
+ LHA3_MAGIC = "-lh3-".getBytes(),
+ LHA4_MAGIC = "-lh4-".getBytes(),
+ LHA5_MAGIC = "-lh5-".getBytes(),
+ LHA6_MAGIC = "-lh6-".getBytes(),
+ LHA7_MAGIC = "-lh7-".getBytes(),
+ LHAD_MAGIC = "-lhd-".getBytes(),
+ LHAZ4_MAGIC = "-lz4-".getBytes(),
+ LHAZ5_MAGIC = "-lz5-".getBytes(),
+ LZO_MAGIC = {(byte)0x89, (byte)0x4c, (byte)0x5a, (byte)0x4f,
+ (byte)0x00, (byte)0x0d, (byte)0x0a, (byte)0x1a},
+ PPMD_MAGIC = {(byte)0x8f, (byte)0xaf, (byte)0xac, (byte)0x84},
+ RAR_MAGIC = "Rar!".getBytes(),
+ RPM_MAGIC = {(byte)0xed, (byte)0xab, (byte)0xee, (byte)0xdb},
+ SHAR_MAGIC = "# This is a shell archive".getBytes(),
+ TAR_MAGIC = "ustar".getBytes(),
+ TNEF_MAGIC = {(byte)0x78, (byte)0x9f, (byte)0x3e, (byte)0x22},
+ UUENC_MAGIC = "begin ".getBytes(),
+ ZIP_MAGIC = {'P', 'K', 3, 4},
+ ZOO_MAGIC = {(byte)0xdc, (byte)0xa7, (byte)0xc4, (byte)0xfd};
public VfsContainer getContainer(VfsEntry entry,
ScanConfiguration configuration)
@@ -60,25 +99,74 @@
// BZIP2
if (startsWithMagic(start, BZIP2_MAGIC)) {
- return new Bzip2Container(entry, configuration);
+ return new SingleFileContainer(entry, "bzip2", configuration) {
+ public void extractFile(VfsEntry entry, File tempFile)
+ throws IOException {
+ runCommand(new String[] {
+ "bunzip2",
+ "-c",
+ entry.getFile().getCanonicalPath()},
+ tempFile);
+ }
+ };
}
// GZIP
if (startsWithMagic(start, GZIP_MAGIC)) {
- return new GzipContainer(entry, configuration);
+ return new SingleFileContainer(entry, "gzip", configuration) {
+ public void extractFile(VfsEntry entry, File tempFile)
+ throws IOException {
+ copyStream(new GZIPInputStream(new FileInputStream(entry.getFile())),
+ new FileOutputStream(tempFile));
+ }
+ };
}
// TAR
if (containsMagic(start, TAR_MAGIC, 257)) {
- return new TarContainer(entry, configuration);
+ return new ArchiveContainer(entry, " >> tar:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "tar",
+ "xfC",
+ entry.getFile().getCanonicalPath(),
+ tempDir.getCanonicalPath()});
+ }
+ };
}
// Microsoft Cabinet
if (startsWithMagic(start, CAB_MAGIC)) {
- System.err.println("Cannot scan Microsoft Cabinet files");
+ return new ArchiveContainer(entry, " >> cab:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "cabextract",
+ "-d",
+ tempDir.getCanonicalPath(),
+ entry.getFile().getCanonicalPath()});
+ }
+ };
}
+ // Self-extracting
if (startsWithMagic(start, EXE_MAGIC)) {
+ if (containsMagic(start, RAR_MAGIC, 7195)) {
+ return new ArchiveContainer(entry,
+ " >> rar-exe:",
+ configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unrar",
+ "x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
final File file = entry.getFile();
final RandomAccessFile raf = new RandomAccessFile(file, "r");
final UPXDecompress upxDecompress =
@@ -97,7 +185,288 @@
} else {
raf.close();
}
- }
+ }
+
+ // ACE
+ if (containsMagic(start, ACE_MAGIC, 7)) {
+ return new ArchiveContainer(entry, " >> ace:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unace",
+ "e",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // AR
+ if (startsWithMagic(start, AR_MAGIC)) {
+ return new ArchiveContainer(entry, " >> ar:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "ar",
+ "x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // RAR
+ if (startsWithMagic(start, RAR_MAGIC)) {
+ return new ArchiveContainer(entry, " >> rar:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unrar",
+ "x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // LHA
+ if (containsMagic(start, LHA__MAGIC, 2)
+ || containsMagic(start, LHA0_MAGIC, 2)
+ || containsMagic(start, LHA1_MAGIC, 2)
+ || containsMagic(start, LHA2_MAGIC, 2)
+ || containsMagic(start, LHA3_MAGIC, 2)
+ || containsMagic(start, LHA4_MAGIC, 2)
+ || containsMagic(start, LHA5_MAGIC, 2)
+ || containsMagic(start, LHA6_MAGIC, 2)
+ || containsMagic(start, LHA7_MAGIC, 2)
+ || containsMagic(start, LHA7_MAGIC, 2)
+ || containsMagic(start, LHAD_MAGIC, 2)
+ || containsMagic(start, LHAZ4_MAGIC, 2)
+ || containsMagic(start, LHAZ5_MAGIC, 2)) {
+ return new ArchiveContainer(entry, " >> lha:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "lha",
+ "xw=" + tempDir.getCanonicalPath(),
+ entry.getFile().getCanonicalPath()});
+ }
+ };
+ }
+
+ // ARJ
+ if (startsWithMagic(start, ARJ_MAGIC)) {
+ return new ArchiveContainer(entry, " >> arj:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unarj",
+ "x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // ZOO
+ if (containsMagic(start, ZOO_MAGIC, 0x14)) {
+ return new ArchiveContainer(entry, " >> zoo:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unzoo",
+ "-x",
+ "-j",
+ tempDir.getCanonicalPath() + File.separator,
+ entry.getFile().getCanonicalPath()});
+ }
+ };
+ }
+
+ // CPIO
+ if (startsWithMagic(start, CPIO_MAGIC)
+ || startsWithMagic(start, CPIOS_MAGIC)
+ || startsWithMagic(start, CPIO1_MAGIC)
+ || startsWithMagic(start, CPIO2_MAGIC)
+ || startsWithMagic(start, CPIO7_MAGIC)) {
+ return new ArchiveContainer(entry, " >> cpio:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "cpio",
+ "-i",
+ "-F",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // TNEF
+ if (startsWithMagic(start, TNEF_MAGIC)) {
+ return new ArchiveContainer(entry, " >> tnef:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "tnef",
+ "-f",
+ entry.getFile().getCanonicalPath(),
+ "-C",
+ tempDir.getCanonicalPath()});
+ }
+ };
+ }
+
+ // SHAR
+ if (containsMagic(start, SHAR_MAGIC, 10)) {
+ return new ArchiveContainer(entry, " >> shar:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "unshar",
+ "-d",
+ tempDir.getCanonicalPath(),
+ entry.getFile().getCanonicalPath()});
+ }
+ };
+ }
+
+ // UUENCODE
+ if (startsWithMagic(start, UUENC_MAGIC)) {
+ return new SingleFileContainer(entry, "uudecode", configuration) {
+ public void extractFile(VfsEntry entry, File tempFile)
+ throws IOException {
+ runCommand(new String[] {
+ "uudecode",
+ "-o",
+ "/dev/stdout",
+ entry.getFile().getCanonicalPath()},
+ tempFile);
+ }
+ };
+ }
+
+ // COMPRESS
+ if (startsWithMagic(start, COMPR_MAGIC)) {
+ return new SingleFileContainer(entry, "compress", configuration) {
+ public void extractFile(VfsEntry entry, File tempFile)
+ throws IOException {
+ runCommand(new String[] {
+ "uncompress",
+ "-d",
+ "-c",
+ entry.getFile().getCanonicalPath()},
+ tempFile);
+ }
+ };
+ }
+
+ // RPM
+ if (startsWithMagic(start, RPM_MAGIC)) {
+ return new ArchiveContainer(entry, " >> rpm:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "rpm2cpio",
+ entry.getFile().getCanonicalPath()},
+ tempDir,
+ new FileOutputStream(
+ tempDir.getCanonicalPath()
+ + File.separator + "rpm.cpio"));
+ }
+ };
+ }
+
+ // ARC
+ if (startsWithMagic(start, ARC2_MAGIC)
+ || startsWithMagic(start, ARC3_MAGIC)
+ || startsWithMagic(start, ARC4_MAGIC)
+ || startsWithMagic(start, ARC6_MAGIC)
+ || startsWithMagic(start, ARC8_MAGIC)
+ || startsWithMagic(start, ARC9_MAGIC)) {
+ return new ArchiveContainer(entry, " >> arc:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "arc",
+ "x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // LZO
+ if (startsWithMagic(start, LZO_MAGIC)) {
+ return new ArchiveContainer(entry, " >> lzo:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ runCommand(new String[] {
+ "lzop",
+ "-x",
+ entry.getFile().getCanonicalPath()},
+ tempDir);
+ }
+ };
+ }
+
+ // PPMd
+ if (startsWithMagic(start, PPMD_MAGIC)) {
+ return new ArchiveContainer(entry, " >> ppmd:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ final String tempFilename =
+ tempDir.getCanonicalPath() + File.separator
+ + "file.pmd";
+ SingleFileContainer.copyStream(
+ new FileInputStream(entry.getFile()),
+ new FileOutputStream(new File(tempFilename)));
+ runCommand(new String[] {
+ "PPMd",
+ "d",
+ "-d",
+ tempFilename},
+ tempDir);
+ }
+ };
+ }
+
+ // DACT
+ if (startsWithMagic(start, DACT_MAGIC)) {
+ return new SingleFileContainer(entry, "dact", configuration) {
+ public void extractFile(VfsEntry entry, File tempFile)
+ throws IOException {
+ runCommand(new String[] {
+ "dact",
+ "-d",
+ "-c",
+ entry.getFile().getCanonicalPath()},
+ tempFile);
+ }
+ };
+ }
+
+ // DAR
+ if (startsWithMagic(start, DAR_MAGIC)) {
+ return new ArchiveContainer(entry, " >> dar:", configuration) {
+ public void extractArchive(VfsEntry entry, File tempDir)
+ throws IOException {
+ final String filename = entry.getFile().getCanonicalPath();
+ runCommand(new String[] {
+ "dar",
+ "-x",
+ filename.substring(
+ 0,
+ filename.lastIndexOf(
+ '.',
+ filename.lastIndexOf('.') - 1)),
+ "-O",
+ "-N"},
+ tempDir);
+ }
+ };
+ }
+
return null;
}
Index: UpxContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/UpxContainer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- UpxContainer.java 14 Dec 2003 11:08:26 -0000 1.1
+++ UpxContainer.java 23 May 2004 14:39:19 -0000 1.2
@@ -44,8 +44,8 @@
private final UPXDecompress upxDecompress;
public UpxContainer(VfsEntry entry,
- UPXDecompress upxDecompress,
- ScanConfiguration scanConf)
+ UPXDecompress upxDecompress,
+ ScanConfiguration scanConf)
throws IOException {
super(entry, "upx", scanConf);
this.upxDecompress = upxDecompress;
Index: ArchiveContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/ArchiveContainer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ArchiveContainer.java 14 Dec 2003 11:08:26 -0000 1.1
+++ ArchiveContainer.java 23 May 2004 14:39:19 -0000 1.2
@@ -79,14 +79,14 @@
public abstract void extractArchive(VfsEntry entry, File tempDir)
throws IOException;
- public boolean hasNext() {
+ public boolean hasNext() throws IOException {
+ if (!initialized) {
+ init();
+ }
return directory.hasNext();
}
public VfsEntry next() throws IOException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
return directory.next();
}
@@ -96,9 +96,23 @@
}
protected void runCommand(final String[] command) throws IOException {
+ runCommand(command, null);
+ }
+
+ protected void runCommand(String[] command, File directory)
+ throws IOException {
+ runCommand(command, directory, null);
+ }
+
+ protected void runCommand(String[] command, File directory, OutputStream os)
+ throws IOException {
Process process = null;
try {
- process = Runtime.getRuntime().exec(command);
+ process = Runtime.getRuntime().exec(command, null, directory);
+ process.getOutputStream().close();
+ if (os != null) {
+ SingleFileContainer.copyStream(process.getInputStream(), os);
+ }
process.waitFor();
} catch (InterruptedException ie) {
// should not happen
Index: SingleFileContainer.java
===================================================================
RCS file: /cvsroot/openantivirus/java/src/org/openantivirus/engine/vfs/container/SingleFileContainer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SingleFileContainer.java 20 May 2004 13:04:50 -0000 1.2
+++ SingleFileContainer.java 23 May 2004 14:39:19 -0000 1.3
@@ -85,19 +85,20 @@
return fileEntry.getStart();
}
- public boolean hasNext() {
+ public boolean hasNext() throws IOException {
+ if (!initialized) {
+ init();
+ }
return !read;
}
public VfsEntry next() throws IOException {
- if (!initialized) {
- throw new IllegalStateException("not initialized");
- }
read = true;
return this;
}
- protected void copyStream(final InputStream is, final OutputStream os) throws IOException {
+ public static void copyStream(final InputStream is, final OutputStream os)
+ throws IOException {
final byte[] buffer = new byte[32768];
int length;
while ((length = is.read(buffer)) != -1) {
-------------------------------------------------------
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