From 8983f14f5c58d916fd4c2673285d2838477af51f Mon Sep 17 00:00:00 2001 From: Luiz Lopes Date: Thu, 1 Feb 2024 12:29:27 -0300 Subject: [PATCH] Update UpdateList.cs add encrypt --- PangLib.UpdateList/UpdateList.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/PangLib.UpdateList/UpdateList.cs b/PangLib.UpdateList/UpdateList.cs index a827fd2..6548141 100644 --- a/PangLib.UpdateList/UpdateList.cs +++ b/PangLib.UpdateList/UpdateList.cs @@ -31,7 +31,7 @@ public UpdateList(string filePath) /// /// Saves the parsed updatelist in the Document instance attribute /// - public void Parse() + public void Parse(bool decrypt = true) { if (DecryptionKey == null) { @@ -39,15 +39,27 @@ public void Parse() } Span updateList = File.ReadAllBytes(FilePath); - - for (int i = 0; i < updateList.Length; i += 8) +if(decrypt) +{ for (int i = 0; i < updateList.Length; i += 8) { Span chunk = updateList.Slice(i, 8); Span decrypted = XTEA.Decipher(16, MemoryMarshal.Cast(chunk).ToArray(), DecryptionKey); Span resource = MemoryMarshal.AsBytes(decrypted); resource.CopyTo(chunk); } +} + else + { + var newArray = new byte[updateList.Length - updateList.Length % 8 + 8]; + updateList.CopyTo(newArray); + updateList = newArray; + for (int i = 0; i < updateList.Length; i += 8) + { + Span chunk = updateList.Slice(i, 8); + MemoryMarshal.AsBytes(XTEA.Encipher(16, MemoryMarshal.Cast(chunk).ToArray(), DecryptionKey)).CopyTo(chunk); + } + } Document = Encoding.UTF8.GetString(updateList.ToArray()); }