io_func* openDmgFilePartition(AbstractFile* abstractIn, int partition) { io_func* toReturn = openDmgFile(abstractIn); if(toReturn == NULL) { return NULL; } return seekDmgPartition(toReturn, partition); }
io_func* openDmgFilePartition(AbstractFile* abstractIn, int partition) { io_func* toReturn; Partition* partitions; uint8_t ddmBuffer[SECTOR_SIZE]; DriverDescriptorRecord* ddm; int numPartitions; int i; unsigned int BlockSize; toReturn = openDmgFile(abstractIn); if(toReturn == NULL) { return NULL; } 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; }