Base64Decode cleaning

This commit is contained in:
ReznoRMichael 2021-01-23 13:01:49 +01:00
parent fa88b665b6
commit c492672f6a

View file

@ -113,15 +113,22 @@ function RemoveHeaders(buffer, csHeader = CSHARP_HEADER) {
return buffer.subarray(lengthCount); return buffer.subarray(lengthCount);
} }
// Thanks to KayDeeTee https://github.com/KayDeeTee/Hollow-Knight-SaveManager and bloodorca https://github.com/bloodorca/hollow (base64.js)
function Base64Decode(buffer) { function Base64Decode(buffer) {
buffer = new Uint8Array(buffer).slice(); buffer = new Uint8Array(buffer).slice();
buffer = buffer.map(v => BASE64_DECODE_TABLE.get(v)) buffer = buffer.map(v => BASE64_DECODE_TABLE.get(v));
{
// The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
let p = buffer.indexOf(64); let p = buffer.indexOf(64);
buffer = buffer.subarray(0, p != -1 ? p : buffer.length); let end;
if (p != -1) {
end = p;
} else {
end = buffer.length;
} }
buffer = buffer.subarray(0, end);
let output = new Uint8Array(3 * buffer.length / 4); let output = new Uint8Array(3 * buffer.length / 4);
let continuous = Math.floor(buffer.length / 4) * 4; let continuous = Math.floor(buffer.length / 4) * 4;
@ -142,7 +149,6 @@ function Base64Decode(buffer) {
return output; return output;
} }
// Thanks to KayDeeTee https://github.com/KayDeeTee/Hollow-Knight-SaveManager and bloodorca https://github.com/bloodorca/hollow (functions.js)
// Decrypt the Uint8Array Buffer using aesjs and a predefined AES key + remove pkcs7 padding // Decrypt the Uint8Array Buffer using aesjs and a predefined AES key + remove pkcs7 padding
function AESDecryption(buffer) { function AESDecryption(buffer) {
let output = ECB_STREAM_CIPHER.decrypt(buffer); let output = ECB_STREAM_CIPHER.decrypt(buffer);