protected abstract void seek(long offset) throws ParseException;
protected abstract void skipBytes(int length) throws ParseException;
protected void parseHeader() throws ParseException {
Header imgHeader = new Header();
img.setImgHeader(imgHeader);
parseXorByte(imgHeader);
// 0x00 x9
skipBytes(9);
// Update month
imgHeader.setUpdateMonth(nextByte());
// Update year
nextByte();
if (currentByte <= 0x62) {
imgHeader.setUpdateYear(currentByte + 2000);
} else { // >= 0x63
imgHeader.setUpdateYear(currentByte + 1900);
}
// 0x00 x3
skipBytes(3);
// Checksum
imgHeader.setChecksum(nextByte());
// Signature
imgHeader.setSignature(parseString(7));
// 0x02 x1
skipBytes(1);
// Sector? x2
skipBytes(2);
// Heads? x2
skipBytes(2);
// Cylinders? x2
skipBytes(2);
// 0x00 x2
skipBytes(2);
// 0x00 x25
skipBytes(25);
// Creation date
imgHeader.setCreationDate(parseDate());
// 0x02 x1
skipBytes(1);
// Map file identifier
imgHeader.setMapFileIdentifier(parseString(7));
// 0x00 x1
skipBytes(1);
// Description (first)
imgHeader.setDescription(parseString(20));
// Heads? x2
skipBytes(2);
// Sectors? x2
skipBytes(2);
// Exponent1
imgHeader.setBlockSizeExponent1(nextByte());
// Exponent2
imgHeader.setBlockSizeExponent2(nextByte());
// FAT block size
imgHeader.setFatBlockSize(
(int)
Math.pow(
2, imgHeader.getBlockSizeExponent1() + imgHeader.getBlockSizeExponent2()));
// ???
skipBytes(2);
// Description (second)
imgHeader.setDescription(imgHeader.getDescription() + parseString(31));
// 0x00 x314
skipBytes(314);
// Partition table
PartitionTable imgPartitionTable = new PartitionTable();
imgHeader.setPartitionTable(imgPartitionTable);
// Boot
imgPartitionTable.setBoot(nextByte());
// Start head
imgPartitionTable.setStartHead(nextByte());
// Start sector
imgPartitionTable.setStartSector(nextByte());
// Start cylinder
imgPartitionTable.setStartCylinder(nextByte());
// System type
imgPartitionTable.setSystemType(nextByte());
// End head
imgPartitionTable.setEndHead(nextByte());
// End sector
imgPartitionTable.setEndSector(nextByte());
// End cylinder
imgPartitionTable.setEndCylinder(nextByte());
// Rel sectors
imgPartitionTable.setRelSectors(getLittleEndianDWord(4));
// Number of sectors
imgPartitionTable.setNumberOfSectors(getLittleEndianDWord(4));
// 0x00 x48
skipBytes(48);
// 0x55
if (nextByte() != 0x55) {
throw new IllegalStateException(); // fixme
}
// 0xAA
if (nextByte() != 0xAA) {
throw new IllegalStateException(); // fixme
}
// End of partition table
// 0x00 x512
skipBytes(512);
// 0x01 x1
skipBytes(1);
// 0x20 x11
skipBytes(11);
// First subfile offset
imgHeader.setFirstSubfileOffset(getLittleEndianWord(4));
// 0x03 x 1
skipBytes(1);
// 0x00 x 15
skipBytes(15);
// Block sequence numbers
int blockSequenceCounter = 0;
for (int i = 0; i < 240; i++) {
int blockSequence = getLittleEndianWord(2);
if (blockSequence == blockSequenceCounter) {
imgHeader.getBlockSequence().add(blockSequence);
blockSequenceCounter++;
} else {
// Fill block sequence
// fixme, que debo hacer acá?
}
}
// Header size
imgHeader.setHeaderSize(
imgHeader.getFatBlockSize() * imgHeader.getBlockSequence().size());
// FAT blocks total size within header
imgHeader.setFatBlocksTotalSize(imgHeader.getFirstSubfileOffset() - 0x600);
// FAT Blocks
while (getBytePointer() < imgHeader.getFirstSubfileOffset()) {
FATBlock fatBlock = new FATBlock();
imgHeader.getFatBlocks().add(fatBlock);
// Block type
if (nextByte() == 0x01) {
fatBlock.setType(FATBlockType.TRUE);
} else {
fatBlock.setType(FATBlockType.DUMMY);
}
if (fatBlock.getType() == FATBlockType.TRUE) {
// Subfile name
fatBlock.setSubfileName(parseString(8));
// Subfile type
fatBlock.setSubfileType(SubfileType.valueOf(parseString(3)));
// Subfile size
fatBlock.setSubfileSizeInBytes(getLittleEndianWord(4));
// Subfile part
fatBlock.setSubfilePart(getLittleEndianDWord(2));
// Subfile offset
if (fatBlock.getSubfilePart() == 0) {
fatBlock.setSubfileOffset(
blockSequenceCounter * imgHeader.getFatBlockSize());
}
// 0x00 x14
skipBytes(14);