Example #1
0
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;
}
Example #2
0
void readDriverDescriptorMap(AbstractFile* file, ResourceKey* resources) {
  BLKXTable* blkx;
  unsigned char* buffer;
  AbstractFile* bufferFile;
  DriverDescriptorRecord* record;
  int i;
  
  blkx = (BLKXTable*) (getDataByID(getResourceByKey(resources, "blkx"), -1)->data);

  buffer = (unsigned char*) malloc(512);
  bufferFile = createAbstractFileFromMemory((void**)&(buffer), 512);
  extractBLKX(file, bufferFile, blkx);
  bufferFile->close(bufferFile);

  record = (DriverDescriptorRecord*)buffer;
  flipDriverDescriptorRecord(record, FALSE);
  printf("sbSig:\t\t0x%x\n", record->sbSig);
  printf("sbBlkSize:\t0x%x\n", record->sbBlkSize);
  printf("sbBlkCount:\t0x%x\n", record->sbBlkCount);
  printf("sbDevType:\t0x%x\n", record->sbDevType);
  printf("sbDevId:\t0x%x\n", record->sbDevId);
  printf("sbData:\t\t0x%x\n", record->sbData);
  printf("sbDrvrCount:\t0x%x\n", record->sbDrvrCount);
  printf("ddBlock:\t0x%x\n", record->ddBlock);
  printf("ddSize:\t\t0x%x\n", record->ddSize);
  printf("ddType:\t\t0x%x\n", record->ddType);
  
  for(i = 0; i < (record->sbDrvrCount - 1); i++) {
    printf("\tddBlock:\t0x%x\n", record->ddPad[i].ddBlock);
    printf("\tddSize:\t\t0x%x\n", record->ddPad[i].ddSize);
    printf("\tddType:\t\t0x%x\n", record->ddPad[i].ddType);
  }
  
  free(buffer);
}
Example #3
0
void writeDriverDescriptorMap(AbstractFile* file, DriverDescriptorRecord* DDM, ChecksumFunc dataForkChecksum, void* dataForkToken,
				ResourceKey **resources) {
  AbstractFile* bufferFile;
  BLKXTable* blkx;
  ChecksumToken uncompressedToken;
  DriverDescriptorRecord* buffer;
  
  buffer = (DriverDescriptorRecord*) malloc(DDM_SIZE * SECTOR_SIZE);
  memcpy(buffer, DDM, DDM_SIZE * SECTOR_SIZE);
  memset(&uncompressedToken, 0, sizeof(uncompressedToken));
  
  flipDriverDescriptorRecord(buffer, TRUE);

  bufferFile = createAbstractFileFromMemory((void**)&buffer, DDM_SIZE * SECTOR_SIZE);
  
  blkx = insertBLKX(file, bufferFile, DDM_OFFSET, DDM_SIZE, DDM_DESCRIPTOR, CHECKSUM_CRC32, &CRCProxy, &uncompressedToken,
			dataForkChecksum, dataForkToken, NULL);
              
  blkx->checksum.data[0] = uncompressedToken.crc;
  
  *resources = insertData(*resources, "blkx", -1, "Driver Descriptor Map (DDM : 0)", (const char*) blkx, sizeof(BLKXTable) + (blkx->blocksRunCount * sizeof(BLKXRun)), ATTRIBUTE_HDIUTIL);
  
  free(buffer);
  bufferFile->close(bufferFile);
  free(blkx);
}
Example #4
0
int writeDriverDescriptorMap(int pNum, AbstractFile* file, DriverDescriptorRecord* DDM, unsigned int BlockSize, ChecksumFunc dataForkChecksum, void* dataForkToken,
				ResourceKey **resources) {
  AbstractFile* bufferFile;
  BLKXTable* blkx;
  ChecksumToken uncompressedToken;
  DriverDescriptorRecord* buffer;
  
  buffer = (DriverDescriptorRecord*) malloc(DDM_SIZE * BlockSize);
  memcpy(buffer, DDM, DDM_SIZE * BlockSize);
  memset(&uncompressedToken, 0, sizeof(uncompressedToken));
  
  flipDriverDescriptorRecord(buffer, TRUE);

  bufferFile = createAbstractFileFromMemory((void**)&buffer, DDM_SIZE * BlockSize);
  
  blkx = insertBLKX(file, bufferFile, DDM_OFFSET, DDM_SIZE, DDM_DESCRIPTOR, CHECKSUM_CRC32, &CRCProxy, &uncompressedToken,
			dataForkChecksum, dataForkToken, NULL, 0);
              
  blkx->checksum.data[0] = uncompressedToken.crc;
  
  char pName[100];
  sprintf(pName, "Driver Descriptor Map (DDM : %d)", pNum + 1);	
  *resources = insertData(*resources, "blkx", pNum, pName, (const char*) blkx, sizeof(BLKXTable) + (blkx->blocksRunCount * sizeof(BLKXRun)), ATTRIBUTE_HDIUTIL);
  
  free(buffer);
  bufferFile->close(bufferFile);
  free(blkx);

  pNum++;

  if((DDM_SIZE * BlockSize / SECTOR_SIZE) - DDM_SIZE > 0)
    pNum = writeFreePartition(pNum, file, DDM_SIZE, (DDM_SIZE * BlockSize / SECTOR_SIZE) - DDM_SIZE, resources);

  return pNum;
}