Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UpdateList.cs #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions PangLib.UpdateList/UpdateList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,35 @@ public UpdateList(string filePath)
///
/// Saves the parsed updatelist in the Document instance attribute
/// </summary>
public void Parse()
public void Parse(bool decrypt = true)
{
if (DecryptionKey == null)
{
throw new NullReferenceException("DecryptionKey needs to be set using the SetDecryptionKey instance method!");
}

Span<byte> 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<byte> chunk = updateList.Slice(i, 8);
Span<uint> decrypted = XTEA.Decipher(16, MemoryMarshal.Cast<byte, uint>(chunk).ToArray(), DecryptionKey);
Span<byte> 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<byte> chunk = updateList.Slice(i, 8);
MemoryMarshal.AsBytes<uint>(XTEA.Encipher(16, MemoryMarshal.Cast<byte, uint>(chunk).ToArray(), DecryptionKey)).CopyTo(chunk);
}
}
Document = Encoding.UTF8.GetString(updateList.ToArray());
}

Expand Down