io_func* seekDmgPartition(io_func* toReturn, int partition) { Partition* partitions; uint8_t ddmBuffer[SECTOR_SIZE]; DriverDescriptorRecord* ddm; int numPartitions; int i; unsigned int BlockSize; toReturn->read(toReturn, 0, SECTOR_SIZE, ddmBuffer); ddm = (DriverDescriptorRecord*) ddmBuffer; flipDriverDescriptorRecord(ddm, FALSE); BlockSize = ddm->sbBlkSize; partitions = (Partition*) malloc(BlockSize); toReturn->read(toReturn, BlockSize, BlockSize, partitions); flipPartitionMultiple(partitions, FALSE, FALSE, BlockSize); numPartitions = partitions->pmMapBlkCnt; partitions = (Partition*) realloc(partitions, numPartitions * BlockSize); toReturn->read(toReturn, BlockSize, numPartitions * BlockSize, partitions); flipPartition(partitions, FALSE, BlockSize); if(partition >= 0) { ((DMG*)toReturn->data)->offset = partitions[partition].pmPyPartStart * BlockSize; } else { for(i = 0; i < numPartitions; i++) { if(strcmp((char*)partitions->pmParType, "Apple_HFSX") == 0 || strcmp((char*)partitions->pmParType, "Apple_HFS") == 0) { ((DMG*)toReturn->data)->offset = partitions->pmPyPartStart * BlockSize; break; } partitions = (Partition*)((uint8_t*)partitions + BlockSize); } } return toReturn; }
int writeApplePartitionMap(int pNum, AbstractFile* file, Partition* partitions, unsigned int BlockSize, ChecksumFunc dataForkChecksum, void* dataForkToken, ResourceKey **resources, NSizResource** nsizIn) { AbstractFile* bufferFile; BLKXTable* blkx; ChecksumToken uncompressedToken; Partition* buffer; NSizResource* nsiz; CSumResource csum; size_t realPartitionSize = (PARTITION_SIZE * SECTOR_SIZE) / BlockSize * BlockSize; buffer = (Partition*) malloc(realPartitionSize); memcpy(buffer, partitions, realPartitionSize); memset(&uncompressedToken, 0, sizeof(uncompressedToken)); flipPartition(buffer, TRUE, BlockSize); bufferFile = createAbstractFileFromMemory((void**)&buffer, realPartitionSize); blkx = insertBLKX(file, bufferFile, PARTITION_OFFSET * BlockSize / SECTOR_SIZE, realPartitionSize / SECTOR_SIZE, pNum, CHECKSUM_CRC32, &BlockCRC, &uncompressedToken, dataForkChecksum, dataForkToken, NULL, 0); bufferFile->close(bufferFile); *((uint32_t*)blkx->checksum.data) = uncompressedToken.crc; csum.version = 1; csum.type = CHECKSUM_MKBLOCK; csum.checksum = uncompressedToken.block; char pName[100]; sprintf(pName, "Apple (Apple_partition_map : %d)", pNum + 1); *resources = insertData(*resources, "blkx", pNum, pName, (const char*) blkx, sizeof(BLKXTable) + (blkx->blocksRunCount * sizeof(BLKXRun)), ATTRIBUTE_HDIUTIL); *resources = insertData(*resources, "cSum", 0, "", (const char*) (&csum), sizeof(csum), 0); nsiz = (NSizResource*) malloc(sizeof(NSizResource)); memset(nsiz, 0, sizeof(NSizResource)); nsiz->isVolume = FALSE; nsiz->blockChecksum2 = uncompressedToken.block; nsiz->partitionNumber = 0; nsiz->version = 6; nsiz->next = NULL; if((*nsizIn) == NULL) { *nsizIn = nsiz; } else { nsiz->next = (*nsizIn)->next; (*nsizIn)->next = nsiz; } free(buffer); free(blkx); return pNum + 1; }
void readApplePartitionMap(AbstractFile* file, ResourceKey* resources, unsigned int BlockSize) { AbstractFile* bufferFile; BLKXTable* blkx; Partition* partition; int i; blkx = (BLKXTable*) (getDataByID(getResourceByKey(resources, "blkx"), 0)->data); partition = (Partition*) malloc(512); bufferFile = createAbstractFileFromMemory((void**)&partition, 512); extractBLKX(file, bufferFile, blkx); bufferFile->close(bufferFile); flipPartition(partition, FALSE, BlockSize); for(i = 0; i < partition->pmMapBlkCnt; i++) { if(partition[i].pmSig != APPLE_PARTITION_MAP_SIGNATURE) { break; } printf("pmSig:\t\t\t0x%x\n", partition[i].pmSig); printf("pmSigPad:\t\t0x%x\n", partition[i].pmSigPad); printf("pmMapBlkCnt:\t\t0x%x\n", partition[i].pmMapBlkCnt); printf("pmPartName:\t\t%s\n", partition[i].pmPartName); printf("pmParType:\t\t%s\n", partition[i].pmParType); printf("pmPyPartStart:\t\t0x%x\n", partition[i].pmPyPartStart); printf("pmPartBlkCnt:\t\t0x%x\n", partition[i].pmPartBlkCnt); printf("pmLgDataStart:\t\t0x%x\n", partition[i].pmLgDataStart); printf("pmDataCnt:\t\t0x%x\n", partition[i].pmDataCnt); printf("pmPartStatus:\t\t0x%x\n", partition[i].pmPartStatus); printf("pmLgBootStart:\t\t0x%x\n", partition[i].pmLgBootStart); printf("pmBootSize:\t\t0x%x\n", partition[i].pmBootSize); printf("pmBootAddr:\t\t0x%x\n", partition[i].pmBootAddr); printf("pmBootAddr2:\t\t0x%x\n", partition[i].pmBootAddr2); printf("pmBootEntry:\t\t0x%x\n", partition[i].pmBootEntry); printf("pmBootEntry2:\t\t0x%x\n", partition[i].pmBootEntry2); printf("pmBootCksum:\t\t0x%x\n", partition[i].pmBootCksum); printf("pmProcessor:\t\t\t%s\n\n", partition[i].pmProcessor); } free(partition); }