|
dump your yahoo archives:
I was bored so I figured out how Yahoo files are encoded. Mostly. - rob
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.util.Date;
public class YahooDumper {
public static void main(String[] args) {
try {
// Figure out who's talking.
File in = new File(args[0]);
String author = in.getName().substring(9, in.getName().length() - 4);
String friend = in.getParentFile().getName();
String[] participants = { author, friend };
// The xor key is the chars from the author's name
char[] key = author.toCharArray();
// Map the file in.
FileChannel fc = new FileInputStream(in).getChannel();
MappedByteBuffer buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
buf.order(ByteOrder.LITTLE_ENDIAN);
while (buf.hasRemaining()) {
// The time is encoded in seconds.
Date when = new Date(buf.getInt() * 1000L);
// This value is always 6. I don't know what it means.
int six = buf.getInt();
// This int always seems to be 0 or 1 ... it's possible that
// everything other than the first bit is used for something else.
int who = buf.getInt();
// The length may not be 4 bytes; there may be two shorts
// here, only the first of which is used for length.
int len = buf.getInt();
// Sometimes there are blank records here and there. So len is
// really zero from time to time.
if (len > 0) {
System.out.print(when + "\t" + (participants[who]) + ": ");
for (int i = 0; i < len; i++) {
int c = buf.get() ^ key[i % key.length];
System.out.print((char) c);
}
System.out.println();
}
// This always seems to be zero.
buf.getInt();
}
fc.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
|
programming fun
|
10/10/2003 7:26 PM
rob
|
New Window
Move/Edit
|