From efa325f75db9a971c2cca9e28c9ac724cd537ade Mon Sep 17 00:00:00 2001 From: Date: Wed, 1 Aug 2012 21:35:54 +0000 Subject: [PATCH] Add read-only support for DC42 images --- .../applecommander/storage/Disk.java | 25 ++++++++++++++++--- .../applecommander/util/AppleUtil.java | 14 +++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/com/webcodepro/applecommander/storage/Disk.java b/src/com/webcodepro/applecommander/storage/Disk.java index 994f878..9128f4f 100644 --- a/src/com/webcodepro/applecommander/storage/Disk.java +++ b/src/com/webcodepro/applecommander/storage/Disk.java @@ -178,6 +178,7 @@ public class Disk { this.filename = filename; int diskSize = 0; byte[] diskImage = null; + byte[] diskImageDC42 = null; if (isSDK() || isSHK()) { // If we have an SDK, unpack it and send along the byte array @@ -194,13 +195,31 @@ public class Disk { StreamUtil.copy(input, diskImageByteArray); diskImage = diskImageByteArray.toByteArray(); } - boolean is2img = false; + int offset = 0; + boolean is2img = false, isDC42 = false; /* Does it have the 2IMG header? */ - if ((diskImage[00] == 0x32) && (diskImage[01] == 0x49) && (diskImage[02] == 0x4D) && (diskImage[03]) == 0x47) + if ((diskImage[00] == 0x32) && (diskImage[01] == 0x49) && (diskImage[02] == 0x4D) && (diskImage[03]) == 0x47) { is2img = true; - int offset = UniversalDiskImageLayout.OFFSET; + offset = UniversalDiskImageLayout.OFFSET; + } + /* Does it have the DiskCopy 4.2 header? */ + else if (((diskImage[0x52] == 0x01) && (diskImage[0x53] == 0x00)) && + ((diskImage[0x51] == 0x02) || (diskImage[0x51] == 0x22) || (diskImage[0x51] == 0x24))) { + isDC42 = true; + offset = 84; + long end = AppleUtil.getLongValue(diskImage,0x40); + if (end < diskImage.length - 83) { + diskImageDC42 = new byte[(int)end]; + System.arraycopy(diskImage, 84, diskImageDC42, 0, (int)end); + diskImageManager = new ByteArrayImageLayout(diskImageDC42); + } + else + throw new IllegalArgumentException(textBundle.get("Disk.ResizeDiskError")); // FIXME - need a better explanation of this + } if (is2img == true || diskImage.length == APPLE_800KB_DISK + offset || diskImage.length == APPLE_5MB_HARDDISK + offset || diskImage.length == APPLE_10MB_HARDDISK + offset || diskImage.length == APPLE_20MB_HARDDISK + offset || diskImage.length == APPLE_32MB_HARDDISK + offset) { diskImageManager = new UniversalDiskImageLayout(diskImage); + } else if (isDC42) { + diskImageManager = new ByteArrayImageLayout(diskImageDC42); } else { diskImageManager = new ByteArrayImageLayout(diskImage); } diff --git a/src/com/webcodepro/applecommander/util/AppleUtil.java b/src/com/webcodepro/applecommander/util/AppleUtil.java index 924a870..13147b2 100644 --- a/src/com/webcodepro/applecommander/util/AppleUtil.java +++ b/src/com/webcodepro/applecommander/util/AppleUtil.java @@ -110,6 +110,20 @@ public class AppleUtil { + getUnsignedByte(buffer[offset+2])*65536; } + /** + * Compute the value of a 4 byte value. This is specific to DC42 processing. + * Pulls value from buffer given the offset, MSB first. + */ + public static long getLongValue(byte[] buffer, int offset) { + if (offset+3 > buffer.length) { + return 0; + } + return getUnsignedByte(buffer[offset+3]) + + getUnsignedByte(buffer[offset+2])*256 + + getUnsignedByte(buffer[offset+1])*65536 + + getUnsignedByte(buffer[offset])*16777216; + } + /** * Set the value of a 3 byte value. */