#include #include #include #include"wud.h" /* * WUX file structure (v1.0): [Header] UINT32 magic1 "WUX0" UINT32 magic2 0x1099d02e UINT32 sectorSize Size per uncompressed sector (SECTOR_SIZE constant) UINT64 uncompressedSize Size of the Wii U image before being compressed UINT32 flags Enable optional parts of the header (not used right now) [SectorIndexTable] UINT32[] lookupIndex table of indices for lookup of each sector. To calculate number of entries in this array: sectorCount = (uncompressedSize+sectorSize-1)/sectorSize [SectorData] UINT8[] padding Padding until the next field (sectorData) is aligned to sectorSize bytes. You can write whatever data you want here UINT8[] sectorData Array of unique sectors. Size in bytes: sectorSize * sectorCount */ #define SECTOR_SIZE (0x8000) #define SECTOR_HASH_SIZE (32) /* * Hash function used to create a hash of each sector * The hashes are then compared to find duplicate sectors */ void calculateHash256(unsigned char* data, unsigned int length, unsigned char* hashOut) { // cheap and simple hash implementation // you can replace this part with your favorite hash method memset(hashOut, 0x00, 32); for(unsigned int i=0; i [-noverify]"); puts(""); puts("Parameters:"); puts("-noverify Skip the file validation step at the end"); return 0; } char* wudPath = argv[1]; // parse options bool skipVerify = false; for(int i=2; i wud) char* newExtension; if( wud_isWUXCompressed(wud) ) { printf("Mode: Decompress\n"); newExtension = ".wud"; } else { printf("Mode: Compress\n"); newExtension = ".wux"; } bool extensionFound = false; for(int i=strlen(outputPath)-1; i>=0; i--) { if( outputPath[i] == '.' ) { extensionFound = true; strcpy(outputPath+i, newExtension); break; } } if( extensionFound == false ) strcat(outputPath, newExtension); // make sure the output file doesn't already exist (avoid accidental overwriting) FILE* outputFile; outputFile = fopen(outputPath, "r"); if( outputFile != NULL ) { printf("Output file \"%s\" already exists.\n", outputPath); wud_close(wud); return -4; } // open output file outputFile = fopen(outputPath, "wb"); if( outputFile == NULL ) { printf("Unable to create output file\n"); wud_close(wud); return -3; } printf("Input:\n"); puts(wudPath); printf("Output:\n"); puts(outputPath); if( wud_isWUXCompressed(wud) ) { if( decompressWUD(wud, outputFile, outputPath) == false ) return -1; } else { if( compressWUD(wud, outputFile, outputPath) == false ) return -1; } // verify if( skipVerify == false ) { if( validateWUX(wudPath, outputPath) == false ) { printf("Validation failed. \"%s\" is corrupted.\n", outputPath); // delete output file remove(outputPath); return -5; } else { printf("Validation successful. No errors detected.\n"); } } return 0; }