From 7743e29f8a07d122c66eac12322a5c7b85ad93d0 Mon Sep 17 00:00:00 2001 From: Date: Wed, 27 Jun 2012 04:09:16 +0000 Subject: [PATCH] Fix up SDK operations - when they're packed inside a BXY wrapper. --- .../shrinkit/MasterHeaderBlock.java | 38 +++++++++++++++++-- src/com/webcodepro/shrinkit/ThreadRecord.java | 2 +- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/com/webcodepro/shrinkit/MasterHeaderBlock.java b/src/com/webcodepro/shrinkit/MasterHeaderBlock.java index c36a1eb..4758724 100644 --- a/src/com/webcodepro/shrinkit/MasterHeaderBlock.java +++ b/src/com/webcodepro/shrinkit/MasterHeaderBlock.java @@ -25,12 +25,26 @@ public class MasterHeaderBlock { private Date archiveModWhen; private int masterVersion; private long masterEof; - + private byte[] nuFileId = {0,0,0,0,0,0}; + /** * Create the Master Header Block, based on the LittleEndianByteInputStream. */ public MasterHeaderBlock(LittleEndianByteInputStream bs) throws IOException { - bs.checkNuFileId(); + int headerOffset = 0; + nuFileId = bs.readBytes(6); + + if (checkId(nuFileId,BXY_ID)) { + bs.readBytes(127 - NUFILE_ID.length); + headerOffset = 128; + int count = bs.read(); + if (count != 0) + throw new IOException("This is actually a Binary II archive with multiple files in it."); + nuFileId = bs.readBytes(6); + } + if (!checkId(nuFileId,NUFILE_ID)) { + throw new IOException("Unable to decode this archive."); + } masterCrc = bs.readWord(); bs.resetCrc(); // CRC is computed from this point to the end of the header totalRecords = bs.readLong(); @@ -44,7 +58,7 @@ public class MasterHeaderBlock { masterEof = -1; } // Read whatever remains of the fixed size header - while (bs.getTotalBytesRead() < MASTER_HEADER_LENGTH) { + while (bs.getTotalBytesRead() < MASTER_HEADER_LENGTH + headerOffset) { bs.readByte(); } validCrc = (masterCrc == bs.getCrcValue()); @@ -91,4 +105,22 @@ public class MasterHeaderBlock { public boolean isValidCrc() { return validCrc; } + /** + * Test that the requested constant is present. + */ + private boolean checkId(byte[] data, byte[] constant) { + for (int i = 0; i < constant.length; i++){ + if (data[i] != constant[i]) + return false; + } + return true; + } + + /** Master Header Block identifier "magic" bytes. */ + public static final byte[] NUFILE_ID = { 0x4e, (byte)0xf5, 0x46, (byte)0xe9, 0x6c, (byte)0xe5 }; + /** Header Block identifier "magic" bytes. */ + public static final byte[] NUFX_ID = { 0x4e, (byte)0xf5, 0x46, (byte)0xd8 }; + /** Binay II identifier "magic" bytes. */ + public static final byte[] BXY_ID = { 0x0a, 0x47, 0x4c }; + } diff --git a/src/com/webcodepro/shrinkit/ThreadRecord.java b/src/com/webcodepro/shrinkit/ThreadRecord.java index 4a2f198..a32003c 100644 --- a/src/com/webcodepro/shrinkit/ThreadRecord.java +++ b/src/com/webcodepro/shrinkit/ThreadRecord.java @@ -53,7 +53,7 @@ public class ThreadRecord { if (hb.getStorageType() <= 13 ) { /* supposed to be block size, but SHK v3.0.1 stored it wrong */ threadEof = hb.getExtraType() * 512; - System.out.println("Found erroneous storage type... fixing."); + // System.out.println("Found erroneous storage type... fixing."); } else if (hb.getStorageType() == 256 && hb.getExtraType() == 280 && hb.getFileSysId() == 2 ) { // FileSysDOS33