Exemplo n.º 1
0
 private static void ReplaceFilesInArchive(DrpArchive drp, IEnumerable <string> filesToReplace)
 {
     foreach (var f in filesToReplace)
     {
         ReplaceFile(drp, f);
     }
 }
Exemplo n.º 2
0
        private static DrpArchive Replace(string source, IEnumerable <string> filesToReplace)
        {
            var data = File.ReadAllBytes(source);
            var drp  = new DrpArchive(data);

            ReplaceFilesInArchive(drp, filesToReplace);
            return(drp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes the <see cref="archive"/> to the <see cref="output"/> stream.
        /// </summary>
        public static void Write(this DrpArchive archive, Stream output)
        {
            using var bw = new BinaryWriter(output);
            var seed = GetHeaderSeed(archive);

            bw.WriteHeader(archive, seed);
            bw.WriteEntries(archive);
            bw.WriteFooter(archive, seed);
        }
Exemplo n.º 4
0
        private static void WriteEntries(this BinaryWriter bw, DrpArchive archive)
        {
            var  files     = archive.Files;
            bool encrypted = archive.Encrypted;
            var  table     = archive.SeedTable;

            foreach (var f in files)
            {
                WriteEntry(bw, f, encrypted, table);
            }
        }
Exemplo n.º 5
0
        private static void ReplaceFileName(DrpArchive drp, string fileFullPath, string fn)
        {
            var entry = drp.GetFileEntry(fn);

            if (entry is not null)
            {
                ReplaceEntry(entry, fileFullPath);
            }
            else
            {
                Console.WriteLine($"Unable to find file in the input drp archive: {fn}");
            }
        }
Exemplo n.º 6
0
 private static void WriteHeader(this BinaryWriter bw, DrpArchive archive, uint seed)
 {
     bw.Write(DrpArchive.ArchiveHeaderMagic);
     bw.Write(seed);
     if (archive.Encrypted)
     {
         var rng = XorShiftUtil.GetEncryptionRng(seed, archive.SeedTable);
         bw.Write(rng.GetNext(uint.MaxValue) ^ DrpArchive.CryptoBlockMagic);
         bw.Write(rng.GetNext(uint.MaxValue) ^ 0x90u);
         bw.Write(rng.GetNext(uint.MaxValue) ^ (uint)archive.FileCount);
     }
     else
     {
         bw.Write(DrpArchive.CryptoBlockMagic);
         bw.Write(0x90u);
         bw.Write(archive.FileCount);
     }
     bw.Write(archive.SeedTable);
 }
Exemplo n.º 7
0
        private static void WriteFooter(this BinaryWriter bw, DrpArchive archive, uint seed)
        {
            var asUint = MemoryMarshal.Cast <byte, uint>(archive.Footer);

            if (archive.Encrypted)
            {
                var rng = XorShiftUtil.GetEncryptionRng(seed, archive.SeedTable);
                foreach (var u32 in asUint)
                {
                    bw.Write(u32 ^ rng.GetNext(uint.MaxValue));
                }
            }
            else
            {
                foreach (var u32 in asUint)
                {
                    bw.Write(u32);
                }
            }
        }
Exemplo n.º 8
0
        private static void ReplaceFile(DrpArchive drp, string fileFullPath)
        {
            var fn = Path.GetFileName(fileFullPath);

            ReplaceFileName(drp, fileFullPath, fn);
        }