Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suchat #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions dmg/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
INCLUDE(FindOpenSSL)
INCLUDE(FindZLIB)

FIND_LIBRARY(CRYPTO_LIBRARIES crypto
PATHS
/usr/lib
/usr/local/lib
)

IF(NOT ZLIB_FOUND)
message(FATAL_ERROR "zlib is required for dmg!")
ENDIF(NOT ZLIB_FOUND)
Expand All @@ -18,15 +11,6 @@ link_directories(${PROJECT_BINARY_DIR}/common ${PROJECT_BINARY_DIR}/hfs)

add_library(dmg adc.c base64.c checksum.c dmgfile.c dmglib.c filevault.c io.c partition.c resources.c udif.c)

IF(OPENSSL_FOUND)
add_definitions(-DHAVE_CRYPT)
include_directories(${OPENSSL_INCLUDE_DIR})
target_link_libraries(dmg ${CRYPTO_LIBRARIES})
IF(WIN32)
TARGET_LINK_LIBRARIES(dmg gdi32)
ENDIF(WIN32)
ENDIF(OPENSSL_FOUND)

target_link_libraries(dmg common hfs z)

add_executable(dmg-bin dmg.c)
Expand Down
17 changes: 9 additions & 8 deletions dmg/dmgfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

static void cacheRun(DMG* dmg, BLKXTable* blkx, int run) {
size_t bufferSize;
size_t bufferRead;
z_stream strm;
void* inBuffer;
int ret;
Expand All @@ -30,14 +31,14 @@ static void cacheRun(DMG* dmg, BLKXTable* blkx, int run) {
ASSERT(dmg->dmg->seek(dmg->dmg, blkx->dataStart + blkx->runs[run].compOffset) == 0, "fseeko");

switch(blkx->runs[run].type) {
case BLOCK_ADC:
bufferRead = 0;
do {
strm.avail_in = dmg->dmg->read(dmg->dmg, inBuffer, blkx->runs[run].compLength);
strm.avail_out = adc_decompress(strm.avail_in, inBuffer, bufferSize, dmg->runData, &have);
bufferRead+=strm.avail_out;
} while (bufferRead < blkx->runs[run].compLength);
break;
case BLOCK_ADC:
bufferRead = 0;
do {
strm.avail_in = dmg->dmg->read(dmg->dmg, inBuffer, blkx->runs[run].compLength);
strm.avail_out = adc_decompress(strm.avail_in, inBuffer, bufferSize, dmg->runData, &have);
bufferRead+=strm.avail_out;
} while (bufferRead < blkx->runs[run].compLength);
break;
case BLOCK_ZLIB:
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
Expand Down
13 changes: 13 additions & 0 deletions dmg/dmglib.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ int buildDmg(AbstractFile* abstractIn, AbstractFile* abstractOut) {
nsiz = NULL;

memset(&dataForkToken, 0, sizeof(ChecksumToken));
memset(koly.fUDIFMasterChecksum.data, 0, sizeof(koly.fUDIFMasterChecksum.data));
memset(koly.fUDIFDataForkChecksum.data, 0, sizeof(koly.fUDIFDataForkChecksum.data));

printf("Creating and writing DDM and partition map...\n"); fflush(stdout);

Expand Down Expand Up @@ -227,14 +229,18 @@ int buildDmg(AbstractFile* abstractIn, AbstractFile* abstractOut) {
koly.fUDIFSegmentID.data4 = rand();
koly.fUDIFDataForkChecksum.type = CHECKSUM_CRC32;
koly.fUDIFDataForkChecksum.size = 0x20;

koly.fUDIFDataForkChecksum.data[0] = dataForkChecksum;

koly.fUDIFXMLOffset = plistOffset;
koly.fUDIFXMLLength = plistSize;
memset(&(koly.reserved1), 0, 0x78);

koly.fUDIFMasterChecksum.type = CHECKSUM_CRC32;
koly.fUDIFMasterChecksum.size = 0x20;

koly.fUDIFMasterChecksum.data[0] = calculateMasterChecksum(resources);

printf("Master checksum: %x\n", koly.fUDIFMasterChecksum.data[0]); fflush(stdout);

koly.fUDIFImageVariant = kUDIFDeviceImageType;
Expand Down Expand Up @@ -296,6 +302,8 @@ int convertToDMG(AbstractFile* abstractIn, AbstractFile* abstractOut) {
nsiz = NULL;
myNSiz = NULL;
memset(&dataForkToken, 0, sizeof(ChecksumToken));
memset(koly.fUDIFMasterChecksum.data, 0, sizeof(koly.fUDIFMasterChecksum.data));
memset(koly.fUDIFDataForkChecksum.data, 0, sizeof(koly.fUDIFDataForkChecksum.data));

partitions = (Partition*) malloc(SECTOR_SIZE);

Expand Down Expand Up @@ -380,6 +388,7 @@ int convertToDMG(AbstractFile* abstractIn, AbstractFile* abstractOut) {
abstractIn->seek(abstractIn, 0);
blkx = insertBLKX(abstractOut, abstractIn, 0, fileLength/SECTOR_SIZE, ENTIRE_DEVICE_DESCRIPTOR, CHECKSUM_CRC32,
&BlockCRC, &uncompressedToken, &CRCProxy, &dataForkToken, NULL);
blkx->checksum.data[0] = uncompressedToken.crc;
resources = insertData(resources, "blkx", 0, "whole disk (unknown partition : 0)", (const char*) blkx, sizeof(BLKXTable) + (blkx->blocksRunCount * sizeof(BLKXRun)), ATTRIBUTE_HDIUTIL);
free(blkx);

Expand Down Expand Up @@ -444,14 +453,18 @@ int convertToDMG(AbstractFile* abstractIn, AbstractFile* abstractOut) {
koly.fUDIFSegmentID.data4 = rand();
koly.fUDIFDataForkChecksum.type = CHECKSUM_CRC32;
koly.fUDIFDataForkChecksum.size = 0x20;

koly.fUDIFDataForkChecksum.data[0] = dataForkChecksum;

koly.fUDIFXMLOffset = plistOffset;
koly.fUDIFXMLLength = plistSize;
memset(&(koly.reserved1), 0, 0x78);

koly.fUDIFMasterChecksum.type = CHECKSUM_CRC32;
koly.fUDIFMasterChecksum.size = 0x20;

koly.fUDIFMasterChecksum.data[0] = calculateMasterChecksum(resources);

printf("Master checksum: %x\n", koly.fUDIFMasterChecksum.data[0]); fflush(stdout);

koly.fUDIFSectorCount = numSectors;
Expand Down
5 changes: 3 additions & 2 deletions dmg/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void extractBLKX(AbstractFile* in, AbstractFile* out, BLKXTable* blkx) {
unsigned char* outBuffer;
unsigned char zero;
size_t bufferSize;
size_t bufferRead;
size_t have;
off_t initialOffset;
int i;
Expand Down Expand Up @@ -182,14 +183,14 @@ void extractBLKX(AbstractFile* in, AbstractFile* out, BLKXTable* blkx) {
printf("run %d: start=%" PRId64 " sectors=%" PRId64 ", length=%" PRId64 ", fileOffset=0x%" PRIx64 "\n", i, initialOffset + (blkx->runs[i].sectorStart * SECTOR_SIZE), blkx->runs[i].sectorCount, blkx->runs[i].compLength, blkx->runs[i].compOffset);

switch(blkx->runs[i].type) {
case BLOCK_ADC:
case BLOCK_ADC:
do {
ASSERT((strm.avail_in = in->read(in, inBuffer, blkx->runs[i].compLength)) == blkx->runs[i].compLength, "fread");
strm.avail_out = adc_decompress(strm.avail_in, inBuffer, bufferSize, outBuffer, &have);
ASSERT(out->write(out, outBuffer, have) == have, "mWrite");
bufferRead+=strm.avail_out;
} while (bufferRead < blkx->runs[i].compLength);
break;
break;
case BLOCK_ZLIB:
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
Expand Down