Beispiel #1
0
        public void PackContentToFile(string outputDir, Encryption encryption)
        {
            Console.WriteLine($"Packing Content {ID:X8}\n");

            Console.WriteLine("Packing files into one file:");
            //At first we need to create the decrypted file.
            string decryptedFile = PackDecrypted();

            Console.WriteLine();
            Console.WriteLine("Generate hashes:");
            //Calculates the hashes for the decrypted content. If the content is not hashed,
            //only the hash of the decrypted file will be calculated

            ContentHashes contentHashes = new ContentHashes(decryptedFile, IsHashed);

            string h3Path = Path.Combine(outputDir, $"{ID:X8}.h3");

            contentHashes.SaveH3ToFile(h3Path);
            SHA1 = contentHashes.TMDHash;
            Console.WriteLine();
            Console.WriteLine($"Encrypt content ({ID:X8})");
            string outputFilePath = Path.Combine(outputDir, $"{ID:X8}.app");

            encryptedFileSize = PackEncrypted(decryptedFile, outputFilePath, contentHashes, encryption);

            Console.WriteLine();
            Console.WriteLine($"Content {ID:X8} packed to file \"{ID:X8}.app\"!");
            Console.WriteLine("-------------");
        }
Beispiel #2
0
        private long PackEncrypted(string decryptedFile, string outputFilePath, ContentHashes hashes, Encryption encryption)
        {
            using FileStream input  = new FileStream(decryptedFile, FileMode.Open);
            using FileStream output = new FileStream(outputFilePath, FileMode.Create);

            if (IsHashed)
            {
                encryption.EncryptFileHashed(input, ID, output, hashes);
            }
            else
            {
                encryption.EncryptFileWithPadding(input, ID, output, CONTENT_FILE_PADDING);
            }

            return(output.Length);
        }