Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- public class XLDContainer {
- public static final String XLD_SIGNATURE = "XLD0I\0";
- // Header
- public int magic = 0;
- public byte unknown = 0;
- public short entries = 0;
- public int[] length = new int[0];
- public byte[][] subfiles = new byte[0][];
- public XLDContainer(File xldFile) throws Exception {
- if (xldFile.exists() && xldFile.isFile()) {
- parseXLD(xldFile);
- } else {
- System.err.println(String.format("Invalid File: %s", xldFile.getName()));
- return;
- }
- }
- public void parseXLD(File file) throws Exception {
- FileInputStream fin = new FileInputStream(file);
- DataInputStream din = new DataInputStream(fin);
- // dbg
- debug(String.valueOf(swapInteger(1)));
- debug(String.valueOf(swapInteger(255)));
- //debug(String.valueOf(swapInteger(4278190080)));
- int lastEntry = -1;
- short nEntries = 0;
- int[] entrylen = null;
- String sig = "";
- // Read signature
- byte[] sigBuf = new byte[6];
- din.read(sigBuf, 0, 6);
- sig = new String(sigBuf);
- if (sig.equals(XLD_SIGNATURE)) {
- nEntries = (short) swapShort(din.readShort());
- entrylen = new int[nEntries];
- debug("nEntries: " + nEntries);
- for (int i = 0; i < nEntries; i++) {
- entrylen[i] = din.readInt();
- debug("EntryLen[" + i + "] = " + swapInteger(entrylen[i]));
- }
- byte[][] entries = new byte[nEntries][];
- for(int i = 0; i < nEntries; i++)
- {
- lastEntry = i;
- //din.read(entries[i], 0, entrylen[i]);
- }
- din.close();
- } else {
- din.close();
- throw new Exception("This is not a valid XLD File.");
- }
- }
- public static short swapShort(short val) {
- return (short) (((val & 0xFF00) >> 8) + ((val & 0xFF) << 8));
- }
- public static int swapInteger(int value) {
- return ((value&0xFF)<<24)|((value&0xFF00)<<8)|((value&0xFF0000)>>8)|((value&0xFF000000)>>24);
- }
- public static void debug(final String str) {
- System.out.printf("[DEBUG] %s\n", str);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement