private static void ReplaceFilesInArchive(DrpArchive drp, IEnumerable <string> filesToReplace) { foreach (var f in filesToReplace) { ReplaceFile(drp, f); } }
private static DrpArchive Replace(string source, IEnumerable <string> filesToReplace) { var data = File.ReadAllBytes(source); var drp = new DrpArchive(data); ReplaceFilesInArchive(drp, filesToReplace); return(drp); }
/// <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); }
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); } }
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}"); } }
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); }
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); } } }
private static void ReplaceFile(DrpArchive drp, string fileFullPath) { var fn = Path.GetFileName(fileFullPath); ReplaceFileName(drp, fileFullPath, fn); }