void displayFolder(HFSCatalogNodeID folderID, Volume* volume) { CatalogRecordList* list; CatalogRecordList* theList; HFSPlusCatalogFolder* folder; HFSPlusCatalogFile* file; theList = list = getFolderContents(folderID, volume); while(list != NULL) { if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; bufferPrintf("%06o ", folder->permissions.fileMode); bufferPrintf("%3d ", folder->permissions.ownerID); bufferPrintf("%3d ", folder->permissions.groupID); bufferPrintf("%12d ", folder->valence); } else if(list->record->recordType == kHFSPlusFileRecord) { file = (HFSPlusCatalogFile*)list->record; bufferPrintf("%06o ", file->permissions.fileMode); bufferPrintf("%3d ", file->permissions.ownerID); bufferPrintf("%3d ", file->permissions.groupID); bufferPrintf("%12Ld ", file->dataFork.logicalSize); } bufferPrintf(" "); printUnicode(&list->name); bufferPrintf("\r\n"); list = list->next; } releaseCatalogRecordList(theList); }
void removeAllInFolder(HFSCatalogNodeID folderID, Volume* volume, const char* parentName) { CatalogRecordList* list; CatalogRecordList* theList; char fullName[1024]; char* name; char* pathComponent; int pathLen; char isRoot; HFSPlusCatalogFolder* folder; theList = list = getFolderContents(folderID, volume); strcpy(fullName, parentName); pathComponent = fullName + strlen(fullName); isRoot = FALSE; if(strcmp(fullName, "/") == 0) { isRoot = TRUE; } while(list != NULL) { name = unicodeToAscii(&list->name); if(isRoot && (name[0] == '\0' || strncmp(name, ".HFS+ Private Directory Data", sizeof(".HFS+ Private Directory Data") - 1) == 0)) { free(name); list = list->next; continue; } strcpy(pathComponent, name); pathLen = strlen(fullName); if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; fullName[pathLen] = '/'; fullName[pathLen + 1] = '\0'; removeAllInFolder(folder->folderID, volume, fullName); } else { printf("%s\n", fullName); removeFile(fullName, volume); } free(name); list = list->next; } releaseCatalogRecordList(theList); if(!isRoot) { *(pathComponent - 1) = '\0'; printf("%s\n", fullName); removeFile(fullName, volume); } }
void displayFolder(HFSCatalogNodeID folderID, Volume* volume) { CatalogRecordList* list; CatalogRecordList* theList; HFSPlusCatalogFolder* folder; HFSPlusCatalogFile* file; time_t fileTime; struct tm *date; HFSPlusDecmpfs* compressData; size_t attrSize; theList = list = getFolderContents(folderID, volume); while(list != NULL) { if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; printf("%06o ", folder->permissions.fileMode); printf("%3d ", folder->permissions.ownerID); printf("%3d ", folder->permissions.groupID); printf("%12d ", folder->valence); fileTime = APPLE_TO_UNIX_TIME(folder->contentModDate); } else if(list->record->recordType == kHFSPlusFileRecord) { file = (HFSPlusCatalogFile*)list->record; printf("%06o ", file->permissions.fileMode); printf("%3d ", file->permissions.ownerID); printf("%3d ", file->permissions.groupID); if(file->permissions.ownerFlags & UF_COMPRESSED) { attrSize = getAttribute(volume, file->fileID, "com.apple.decmpfs", (uint8_t**)(&compressData)); flipHFSPlusDecmpfs(compressData); printf("%12" PRId64 " ", compressData->size); free(compressData); } else { printf("%12" PRId64 " ", file->dataFork.logicalSize); } fileTime = APPLE_TO_UNIX_TIME(file->contentModDate); } date = localtime(&fileTime); if(date != NULL) { printf("%2d/%2d/%4d %02d:%02d ", date->tm_mon, date->tm_mday, date->tm_year + 1900, date->tm_hour, date->tm_min); } else { printf(" "); } printUnicode(&list->name); printf("\n"); list = list->next; } releaseCatalogRecordList(theList); }
void extractAllInFolder(HFSCatalogNodeID folderID, Volume* volume) { CatalogRecordList* list; CatalogRecordList* theList; char cwd[1024]; char* name; HFSPlusCatalogFolder* folder; HFSPlusCatalogFile* file; AbstractFile* outFile; struct stat status; ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory"); theList = list = getFolderContents(folderID, volume); while(list != NULL) { name = unicodeToAscii(&list->name); if(strncmp(name, ".HFS+ Private Directory Data", sizeof(".HFS+ Private Directory Data") - 1) == 0 || name[0] == '\0') { free(name); list = list->next; continue; } if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; printf("folder: %s\n", name); if(stat(name, &status) != 0) { ASSERT(mkdir(name, 0755) == 0, "mkdir"); } ASSERT(chdir(name) == 0, "chdir"); extractAllInFolder(folder->folderID, volume); ASSERT(chdir(cwd) == 0, "chdir"); } else if(list->record->recordType == kHFSPlusFileRecord) { printf("file: %s\n", name); file = (HFSPlusCatalogFile*)list->record; outFile = createAbstractFileFromFile(fopen(name, "wb")); if(outFile != NULL) { writeToFile(file, outFile, volume); outFile->close(outFile); } else { printf("WARNING: cannot fopen %s\n", name); } } free(name); list = list->next; } releaseCatalogRecordList(theList); }
void displayFolder(HFSCatalogNodeID folderID, Volume* volume) { CatalogRecordList* list; CatalogRecordList* theList; HFSPlusCatalogFolder* folder; HFSPlusCatalogFile* file; time_t fileTime; struct tm *date; theList = list = getFolderContents(folderID, volume); while(list != NULL) { if(list->record->recordType == kHFSPlusFolderRecord) { folder = (HFSPlusCatalogFolder*)list->record; printf("%06o ", folder->permissions.fileMode); printf("%3d ", folder->permissions.ownerID); printf("%3d ", folder->permissions.groupID); printf("%12d ", folder->valence); fileTime = APPLE_TO_UNIX_TIME(folder->contentModDate); } else if(list->record->recordType == kHFSPlusFileRecord) { file = (HFSPlusCatalogFile*)list->record; printf("%06o ", file->permissions.fileMode); printf("%3d ", file->permissions.ownerID); printf("%3d ", file->permissions.groupID); printf("%12" PRId64 " ", file->dataFork.logicalSize); fileTime = APPLE_TO_UNIX_TIME(file->contentModDate); } date = localtime(&fileTime); if(date != NULL) { printf("%2d/%2d/%4d %02d:%02d ", date->tm_mon, date->tm_mday, date->tm_year + 1900, date->tm_hour, date->tm_min); } else { printf(" "); } printUnicode(&list->name); printf("\n"); list = list->next; } releaseCatalogRecordList(theList); }
void addAllInFolder(HFSCatalogNodeID folderID, Volume* volume, const char* parentName) { CatalogRecordList* list; CatalogRecordList* theList; char cwd[1024]; char fullName[1024]; char testBuffer[1024]; char* pathComponent; int pathLen; char* name; DIR* dir; DIR* tmp; HFSCatalogNodeID cnid; struct dirent* ent; AbstractFile* file; HFSPlusCatalogFile* outFile; strcpy(fullName, parentName); pathComponent = fullName + strlen(fullName); ASSERT(getcwd(cwd, 1024) != NULL, "cannot get current working directory"); theList = list = getFolderContents(folderID, volume); ASSERT((dir = opendir(cwd)) != NULL, "opendir"); while((ent = readdir(dir)) != NULL) { if(ent->d_name[0] == '.' && (ent->d_name[1] == '\0' || (ent->d_name[1] == '.' && ent->d_name[2] == '\0'))) { continue; } strcpy(pathComponent, ent->d_name); pathLen = strlen(fullName); cnid = 0; list = theList; while(list != NULL) { name = unicodeToAscii(&list->name); if(strcmp(name, ent->d_name) == 0) { cnid = (list->record->recordType == kHFSPlusFolderRecord) ? (((HFSPlusCatalogFolder*)list->record)->folderID) : (((HFSPlusCatalogFile*)list->record)->fileID); free(name); break; } free(name); list = list->next; } if((tmp = opendir(ent->d_name)) != NULL) { closedir(tmp); printf("folder: %s\n", fullName); fflush(stdout); if(cnid == 0) { cnid = newFolder(fullName, volume); } fullName[pathLen] = '/'; fullName[pathLen + 1] = '\0'; ASSERT(chdir(ent->d_name) == 0, "chdir"); addAllInFolder(cnid, volume, fullName); ASSERT(chdir(cwd) == 0, "chdir"); } else { printf("file: %s\n", fullName); fflush(stdout); if(cnid == 0) { cnid = newFile(fullName, volume); } file = createAbstractFileFromFile(fopen(ent->d_name, "rb")); ASSERT(file != NULL, "fopen"); outFile = (HFSPlusCatalogFile*)getRecordByCNID(cnid, volume); writeToHFSFile(outFile, file, volume); file->close(file); free(outFile); if(strncmp(fullName, "/Applications/", sizeof("/Applications/") - 1) == 0) { testBuffer[0] = '\0'; strcpy(testBuffer, "/Applications/"); strcat(testBuffer, ent->d_name); strcat(testBuffer, ".app/"); strcat(testBuffer, ent->d_name); if(strcmp(testBuffer, fullName) == 0) { if(strcmp(ent->d_name, "Installer") == 0 || strcmp(ent->d_name, "BootNeuter") == 0 ) { printf("Giving setuid permissions to %s...\n", fullName); fflush(stdout); chmodFile(fullName, 04755, volume); } else { printf("Giving permissions to %s\n", fullName); fflush(stdout); chmodFile(fullName, 0755, volume); } } } else if(strncmp(fullName, "/bin/", sizeof("/bin/") - 1) == 0 || strncmp(fullName, "/Applications/BootNeuter.app/bin/", sizeof("/Applications/BootNeuter.app/bin/") - 1) == 0 || strncmp(fullName, "/sbin/", sizeof("/sbin/") - 1) == 0 || strncmp(fullName, "/usr/sbin/", sizeof("/usr/sbin/") - 1) == 0 || strncmp(fullName, "/usr/bin/", sizeof("/usr/bin/") - 1) == 0 || strncmp(fullName, "/usr/libexec/", sizeof("/usr/libexec/") - 1) == 0 || strncmp(fullName, "/usr/local/bin/", sizeof("/usr/local/bin/") - 1) == 0 || strncmp(fullName, "/usr/local/sbin/", sizeof("/usr/local/sbin/") - 1) == 0 || strncmp(fullName, "/usr/local/libexec/", sizeof("/usr/local/libexec/") - 1) == 0 ) { chmodFile(fullName, 0755, volume); printf("Giving permissions to %s\n", fullName); fflush(stdout); } } } closedir(dir); releaseCatalogRecordList(theList); }