Well hopefully this will start the ball rolling and get the real coders to write a better tool.. :-)
It's not pretty, and I make no claims to this being in any way efficient or great code... it does the job...
I'm happy for somebody to come along and make it better... but please post it so that we can all benefit...
I wrote two bits of code, one to inflate and join the PART files:
processPartFiles.java
import java.io.*;
import java.util.StringTokenizer;
import java.util.zip.InflaterInputStream;
public class processPartFiles
{
public processPartFiles()
{
}
public static void main(String args[])
{
try
{
FileInputStream fileinputstream = new FileInputStream("PKG.DIR");
DataInputStream datainputstream = new DataInputStream(fileinputstream);
String s = "";
boolean flag = false;
for(int i = 1; i < 8; i++)
s = datainputstream.readLine();
FileOutputStream fileoutputstream = new FileOutputStream("PKG.bin");
while((s = datainputstream.readLine()) != null)
{
StringTokenizer stringtokenizer = new StringTokenizer(s, " ");
String s1 = stringtokenizer.nextToken();
String s2 = stringtokenizer.nextToken();
String s3 = stringtokenizer.nextToken();
String s4 = stringtokenizer.nextToken();
String s5 = stringtokenizer.nextToken();
String s6 = stringtokenizer.nextToken();
String s7 = stringtokenizer.nextToken();
String s8 = stringtokenizer.nextToken();
Object obj = null;
obj = new FileInputStream(s1);
if(s8.equals("2"))
obj = new InflaterInputStream(((InputStream) (obj)));
int j = -1;
int k = 0;
byte abyte0[] = new byte[1024];
while((j = ((InputStream) (obj)).read(abyte0)) != -1)
{
for(int l = 0; l < j; l++)
{
byte byte0 = (byte)(abyte0[l] >> 5 & 7);
byte byte1 = (byte)(abyte0[l] << 3 & 0xf8);
byte byte2 = (byte)(byte0 | byte1);
byte byte3 = (byte)(byte2 ^ k++ & 0xff);
abyte0[l] = byte3;
}
fileoutputstream.write(abyte0, 0, j);
}
}
}
catch(IOException ioexception)
{
System.out.println(ioexception);
}
}
}
...and another to unpack the resulting binary into the files and directory structure contained within:
unpack.java
import java.io.*;
public class unPack
{
public unPack()
{
}
public static void main(String args[])
{
try
{
FileInputStream fileinputstream = null;
fileinputstream = new FileInputStream("PKG.bin");
byte byte0 = -1;
boolean flag = false;
byte abyte0[] = new byte[8];
fileinputstream.read(abyte0);
for(int i = 0; i < 1000; i++)
{
byte abyte1[] = new byte[4];
fileinputstream.read(abyte1);
byte abyte2[] = new byte[1];
fileinputstream.read(abyte2);
String s = "";
while(abyte2[0] != 0)
{
if((char)abyte2[0] == '\\')
{
boolean flag1 = (new File(s)).exists();
if(!flag1)
{
boolean flag2 = (new File(s)).mkdir();
if(!flag2)
System.out.println("Directory creation failed");
}
}
s = (new StringBuilder()).append(s).append((char)abyte2[0]).toString();
fileinputstream.read(abyte2);
}
System.out.println((new StringBuilder()).append("fName: ").append(s).toString());
System.out.println((new StringBuilder()).append("fLength: ").append(swabInt(byteArrayToInt(abyte1, 0))).toString());
byte abyte3[] = new byte[swabInt(byteArrayToInt(abyte1, 0))];
fileinputstream.read(abyte3);
FileOutputStream fileoutputstream = new FileOutputStream(s);
fileoutputstream.write(abyte3, 0, swabInt(byteArrayToInt(abyte1, 0)));
fileoutputstream.close();
}
}
catch(IOException ioexception)
{
System.out.println(ioexception);
}
}
private byte[] intToDWord(int i)
{
byte abyte0[] = new byte[4];
abyte0[0] = (byte)(i & 0xff);
abyte0[1] = (byte)(i >> 8 & 0xff);
abyte0[2] = (byte)(i >> 16 & 0xff);
abyte0[3] = (byte)(i >> 24 & 0xff);
return abyte0;
}
public static int byteArrayToInt(byte abyte0[], int i)
{
int j = 0;
for(int k = 0; k < 4; k++)
{
int l = (3 - k) * 8;
j += (abyte0[k + i] & 0xff) << l;
}
return j;
}
public static int byteArrayToInt2(byte abyte0[], int i)
{
int j = 0;
i = 0;
j += unsignedByteToInt(abyte0[i++]) << 24;
j += unsignedByteToInt(abyte0[i++]) << 16;
j += unsignedByteToInt(abyte0[i++]) << 8;
j += unsignedByteToInt(abyte0[i++]) << 0;
return j;
}
public static int unsignedByteToInt(byte byte0)
{
return byte0 & 0xff;
}
public static final int swabInt(int i)
{
return i >>> 24 | i << 24 | i << 8 & 0xff0000 | i >> 8 & 0xff00;
}
}
When compiled copy the classes to the same directory as the PKG.DIR and all the part files.
run:
java processPartFiles
this expects to find the PKG.DIR file in the same directory and reads the zip flag, writes a file called PKG.bin
next run:
java unPack
This reads the PKG.bin and creates the files and the entire directory structure in the same directory.
Hope this helps...
Redband