FTD and FST

This commit is contained in:
Denis Molony 2017-01-22 11:01:15 +11:00
parent 532809bfee
commit 66f0602e23
7 changed files with 154 additions and 6 deletions

View File

@ -0,0 +1,39 @@
package com.bytezone.diskbrowser.applefile;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class FileSystemTranslator extends AbstractFile
{
private final String text1;
private final String text2;
private final String text3;
private final String text4;
public FileSystemTranslator (String name, byte[] buffer)
{
super (name, buffer);
text1 = HexFormatter.getPascalString (buffer, 0x36);
text2 = HexFormatter.getPascalString (buffer, 0xFC);
int len1 = buffer[0xFC] & 0xFF;
text3 = HexFormatter.getPascalString (buffer, 0xFC + len1 + 1);
int len2 = buffer[0xFC + len1 + 1] & 0xFF;
text4 = HexFormatter.getPascalString (buffer, 0xFC + len1 + len2 + 4);
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ("Name : " + name + "\n\n");
text.append ("File System Translator\n\n");
text.append (String.format ("Text 1 ....... %s%n", text1));
text.append (String.format ("Text 2 ....... %s%n", text2));
text.append (String.format ("Text 3 ....... %s%n", text3));
text.append (String.format ("Text 4 ....... %s%n", text4));
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
}

View File

@ -0,0 +1,95 @@
package com.bytezone.diskbrowser.applefile;
import java.util.ArrayList;
import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter;
public class FileTypeDescriptorTable extends AbstractFile
{
int versionMajor;
int versionMinor;
int flags;
int numEntries;
int spareWord;
int indexRecordSize;
int offsetToIdx;
private final List<IndexRecord> indexRecords = new ArrayList<IndexRecord> ();
public FileTypeDescriptorTable (String name, byte[] buffer)
{
super (name, buffer);
versionMajor = buffer[0] & 0xFF;
versionMinor = buffer[1] & 0xFF;
flags = HexFormatter.unsignedShort (buffer, 2);
numEntries = HexFormatter.unsignedShort (buffer, 4);
spareWord = HexFormatter.unsignedShort (buffer, 6);
indexRecordSize = HexFormatter.unsignedShort (buffer, 8);
offsetToIdx = HexFormatter.unsignedShort (buffer, 10);
int ptr = offsetToIdx;
for (int i = 0; i < numEntries; i++)
{
indexRecords.add (new IndexRecord (buffer, ptr));
ptr += indexRecordSize;
}
}
@Override
public String getText ()
{
StringBuilder text = new StringBuilder ("Name : " + name + "\n\n");
text.append ("File Type Descriptor Table\n\n");
text.append (
String.format ("Version ........... %d.%d%n", versionMajor, versionMinor));
text.append (String.format ("Flags ............. %04X%n", flags));
text.append (String.format ("NumEntries ........ %d%n", numEntries));
text.append (String.format ("SpareWord ......... %d%n", spareWord));
text.append (String.format ("IndexRecordSize ... %d%n", indexRecordSize));
text.append (String.format ("OffsetToIdx ....... %d%n%n", offsetToIdx));
text.append ("Type Aux Flags Offset String\n");
for (IndexRecord indexRecord : indexRecords)
text.append (String.format ("%04X %04X %04X %04X %s%n",
indexRecord.fileType, indexRecord.auxType, indexRecord.flags,
indexRecord.offset, indexRecord.string));
text.deleteCharAt (text.length () - 1);
return text.toString ();
}
class IndexRecord
{
int fileType;
int auxType;
int flags;
int offset;
String string;
public IndexRecord (byte[] buffer, int offset)
{
fileType = HexFormatter.unsignedShort (buffer, offset);
auxType = HexFormatter.unsignedLong (buffer, offset + 2);
flags = HexFormatter.unsignedShort (buffer, offset + 6);
this.offset = HexFormatter.unsignedShort (buffer, offset + 8);
string = HexFormatter.getPascalString (buffer, this.offset);
}
@Override
public String toString ()
{
StringBuilder text = new StringBuilder ();
text.append (String.format ("File type ...... %d%n", fileType));
text.append (String.format ("Aux type ....... %04X%n", auxType));
text.append (String.format ("Flags .......... %04X%n", flags));
text.append (String.format ("Offset ......... %04X%n", offset));
text.append (String.format ("String ......... %s%n", string));
return text.toString ();
}
}
}

View File

@ -17,9 +17,9 @@ public class IconFile extends AbstractFile
{
super (name, buffer);
iBlkNext = HexFormatter.getLong (buffer, 0);
iBlkNext = HexFormatter.unsignedLong (buffer, 0);
iBlkID = HexFormatter.unsignedShort (buffer, 4);
iBlkPath = HexFormatter.getLong (buffer, 6);
iBlkPath = HexFormatter.unsignedLong (buffer, 6);
iBlkName = HexFormatter.getHexString (buffer, 10, 16);
int ptr = 26;
@ -183,12 +183,12 @@ public class IconFile extends AbstractFile
private void appendIcon (StringBuilder text, byte[] buffer)
{
int rowBytes = 1 + (iconWidth - 1) / 2;
int rowBytes = (iconWidth - 1) / 2 + 1;
for (int i = 0; i < main.length; i += rowBytes)
{
for (int ptr = i, max = i + rowBytes; ptr < max; ptr++)
{
int left = (byte) ((buffer[ptr] & 0xF0) >> 4);
int left = (byte) ((buffer[ptr] & 0xF0) >>> 4);
int right = (byte) (buffer[ptr] & 0x0F);
text.append (String.format ("%X %X ", left, right));
}

View File

@ -17,7 +17,7 @@ public class SimpleText extends AbstractFile
text.append (String.format ("End of file : %,8d%n%n", buffer.length));
int ptr = 0;
while (ptr < buffer.length)
while (ptr < buffer.length && buffer[ptr] != 0x00)
{
String line = getLine (ptr);
text.append (line + "\n");

View File

@ -359,6 +359,12 @@ class FileEntry extends CatalogEntry implements ProdosConstants
case FILE_TYPE_FONT:
file = new QuickDrawFont (name, exactBuffer, fileType, auxType);
break;
case FILE_TYPE_DESCRIPTOR_TABLE:
file = new FileTypeDescriptorTable (name, exactBuffer);
break;
case FILE_TYPE_GSOS_FILE_SYSTEM_TRANSLATOR:
file = new FileSystemTranslator (name, exactBuffer);
break;
default:
System.out.format ("Unknown file type : %02X%n", fileType);
file = new DefaultAppleFile (name, exactBuffer);

View File

@ -9,11 +9,13 @@ public interface ProdosConstants
int FILE_TYPE_ADB = 0x19;
int FILE_TYPE_AWP = 0x1A;
int FILE_TYPE_ASP = 0x1B;
int FILE_TYPE_DESCRIPTOR_TABLE = 0x42;
int FILE_TYPE_GWP = 0x50;
int FILE_TYPE_IIGS_SOURCE = 0xB0;
int FILE_TYPE_IIGS_OBJECT = 0xB1;
// int FILE_TYPE_FORKED_FILE = 0xB3; // S16
int FILE_TYPE_IIGS_APPLICATION = 0xB3;
int FILE_TYPE_GSOS_FILE_SYSTEM_TRANSLATOR = 0xBD;
int FILE_TYPE_PNT = 0xC0;
int FILE_TYPE_PIC = 0xC1;
int FILE_TYPE_FONT = 0xC8;

View File

@ -292,7 +292,7 @@ public class HexFormatter
return (b1 & 0xFF) + (b2 & 0xFF) * 256 + (b3 & 0xFF) * 65536;
}
public static int getLong (byte[] buffer, int ptr)
public static int unsignedLong (byte[] buffer, int ptr)
{
int val = 0;
for (int i = 3; i >= 0; i--)
@ -303,6 +303,12 @@ public class HexFormatter
return val;
}
public static int signedLong (byte[] buffer, int ptr)
{
return (((buffer[ptr] & 0xFF) << 24) | ((buffer[ptr] & 0xFF) << 16)
| ((buffer[ptr] & 0xFF) << 8) | (buffer[ptr + 1] & 0xFF));
}
public static int getLongBigEndian (byte[] buffer, int ptr)
{
int val = 0;