File Block - mechpaul/NXPatcher GitHub Wiki

File Block

Once the zlibBlock is decompressed from the header, you can then begin parsing file blocks.

The decompressed zlib block immediately beings with a fileBlock. File blocks are continually parsed until the end of the decompressed zlib block buffer is reached. A fileBlock is parsed as such:

//unsigned char* zlibBlock = A pointer to the current place in the unpacked zlib stream
//unsigned char* zlibBlockPtr = A pointer to the beginning of the unpacked zlib stream
//int unpackedLengthZlib = The length of the decompressed zlib stream
//char checkByte = The current byte being read from the zlib stream
//char fileName[260] = The file name that we are working on now

do {
  checkByte = GetByte(&zlibBlock);
  switch(checkByte)  
  {
      case 0x00:
          //Create file OR folder
          break;
      case 0x01:
          //Rebuild the file
          break;
      case 0x02:
          //Delete the file OR folder
          break;
      default:
          //Add checkByte to the end of fileName
  }

}while((zlibBlock - zlibBlockPtr) < unpackedLenZlibBlock); 
//Basically, continue parsing file blocks until the final offset is reached.

The fileBlock always starts with a file name and then a check byte which states what to do with that file name.