decode into String and paste into textarea

This commit is contained in:
ReznoRMichael 2021-01-23 01:48:17 +01:00
parent 1a87c72eb8
commit 68240dd446
2 changed files with 16 additions and 11 deletions

View file

@ -44,7 +44,7 @@
</p> </p>
<div> <div>
<textarea name="save-area" id="save-area" rows="6" autofocus spellcheck="false" placeholder="Paste (Ctrl + V) your decoded save here..." autofocus></textarea> <textarea name="save-area" id="save-area" rows="6" spellcheck="false" placeholder="Paste (Ctrl + V) your decoded save here..." autofocus></textarea>
<div class="buttons"> <div class="buttons">

View file

@ -6,8 +6,8 @@ const BASE64_DECODE_TABLE = new Map(BASE64_ARRAY.map((ord, i) => [ord, i]));
const AES_KEY = new TextEncoder().encode('UKu52ePUBwetZ9wNX88o54dnfKRu0T1l'); // encodes to Uint8Array const AES_KEY = new TextEncoder().encode('UKu52ePUBwetZ9wNX88o54dnfKRu0T1l'); // encodes to Uint8Array
const ECB_STREAM_CIPHER = new aesjs.ModeOfOperation.ecb(AES_KEY); // create a new AES stream cipher object const ECB_STREAM_CIPHER = new aesjs.ModeOfOperation.ecb(AES_KEY); // create a new AES stream cipher object
console.log(`AES_KEY: ${AES_KEY}`); // console.log(`AES_KEY: ${AES_KEY}`);
console.log(`ECB_STREAM_CIPHER: ${ECB_STREAM_CIPHER}`); // console.log(`ECB_STREAM_CIPHER: ${ECB_STREAM_CIPHER}`);
function ShowFile(input) { function ShowFile(input) {
let inputFileObject = input.files[0]; let inputFileObject = input.files[0];
@ -31,18 +31,14 @@ function LoadSaveFile(input) {
inputReader.readAsArrayBuffer(inputFileObject); inputReader.readAsArrayBuffer(inputFileObject);
// addEventListener("load", function) - to decode the file when loaded // addEventListener("load", function) - to decode the file when loaded
inputReader.addEventListener("load", ProcessFileObject); inputReader.addEventListener("load", ProcessFileObject);
// 2. Decode file
// 3. Convert file to JSON string (optional?)
// JSON.stringify(JSON.parse(decrypted), undefined, 2)
// 4. Paste decoded string file to text area
} }
// reads the File object as an Array Buffer and does all other operations (decoding, decryption, conversion to string, pasting to text area) // reads the File object as an Array Buffer and does all other operations (decoding, decryption, conversion to string, pasting to text area)
function ProcessFileObject() { function ProcessFileObject() {
let inputArrayBuffer = this.result; let inputArrayBuffer = this.result;
let decodedString;
// 2. Decode file
try { try {
// Uint8Array(ArrayBuffer) uint8_t equivalent in C // Uint8Array(ArrayBuffer) uint8_t equivalent in C
@ -62,9 +58,18 @@ function ProcessFileObject() {
inputArrayBuffer = AESDecryption(inputArrayBuffer); inputArrayBuffer = AESDecryption(inputArrayBuffer);
// Convert ArrayBuffer to string/text TextDecoder().decode(ArrayBuffer) // Convert ArrayBuffer to string/text TextDecoder().decode(ArrayBuffer)
decodedString = new TextDecoder().decode(inputArrayBuffer);
// 4. Paste decoded string file to text area
alert(`Array Buffer: ${inputArrayBuffer}`); document.getElementById("save-area").value = "";
document.getElementById("save-area").value = decodedString;
// after pasting the decoded string, launch the main analyzing function immediately
HKReadTextArea();
// alert(`Decoded String: ${decodedString}`);
// alert(`Array Buffer: ${inputArrayBuffer}`);
} catch (error) { } catch (error) {
alert(`The file cannot be decoded. Error: ${error}`); alert(`The file cannot be decoded. Error: ${error}`);
} }