From 9a2e9f8950e5f2893e7e27ee68687370dc1a0800 Mon Sep 17 00:00:00 2001 From: fudgepop01 Date: Sat, 20 Jun 2020 22:53:36 -0400 Subject: [PATCH] added binary edit toggle for faster experimentation; fixed hex editor updating bug --- src/components/Hex.svelte | 13 ++-- src/components/Main.svelte | 13 +++- src/components/Overview.svelte | 82 +++++++++++++++++++++++-- static/amiibo/regions.txt | 88 +++++++++++++++++++++++++++ static/amiibo/sample_files/CAP_2 | Bin 0 -> 540 bytes static/amiibo/sample_files/CAP_2_ENC | Bin 0 -> 540 bytes static/amiibo/sample_files/CAP_3 | Bin 0 -> 540 bytes 7 files changed, 183 insertions(+), 13 deletions(-) create mode 100644 static/amiibo/sample_files/CAP_2 create mode 100644 static/amiibo/sample_files/CAP_2_ENC create mode 100644 static/amiibo/sample_files/CAP_3 diff --git a/src/components/Hex.svelte b/src/components/Hex.svelte index 13bab737..c7b3504a 100644 --- a/src/components/Hex.svelte +++ b/src/components/Hex.svelte @@ -5,6 +5,7 @@ export let data; export let params; let editor; + let lastChange; let dispatch = createEventDispatcher(); onMount(async () => { @@ -30,16 +31,16 @@ description: param.description }) } + + dispatch('updateEditorFn', (data) => { + editor.acceptFile(new File([new Blob([data])], 'amiibodata')); + }); }, 100); }) async function broadcastChange() { - dispatch('dataChanged', await editor.saveFile()); - } - - let binView = false; - const toggleBinView = () => { - + lastChange = await editor.saveFile(); + dispatch('dataChanged', lastChange); } diff --git a/src/components/Main.svelte b/src/components/Main.svelte index 45cf5817..e9a61ad5 100644 --- a/src/components/Main.svelte +++ b/src/components/Main.svelte @@ -83,12 +83,14 @@ return await card.init(); } + let updateEditorFn = (data) => {}; async function loadFile(method) { let paths = await remote.dialog.showOpenDialog({ message: 'open amiibo bin' }); if (method === 'encrypt') data = decrypt(await readFile(paths[0]), keys); else data = await readFile(paths[0]); + updateEditorFn(data); } async function saveFile(method) { @@ -120,6 +122,7 @@ data = await card.read(); data = decrypt(data, keys); data[0xE3] |= 0b00000001; + updateEditorFn(data); } }) .modal('show'); @@ -150,6 +153,8 @@ targetCard = decrypt(targetCard, keys); data.copy(targetCard, 0xE0, 0xE0, 0x1B5); + // uncomment this to be able to set the nickname: + // targetCard.write(newStr, 0x39, newStr.length * 2, 'utf16le'); sign(targetCard); let encrypted = encrypt(targetCard, keys); @@ -258,6 +263,7 @@
+
\ No newline at end of file diff --git a/src/components/Overview.svelte b/src/components/Overview.svelte index 16971938..b860a490 100644 --- a/src/components/Overview.svelte +++ b/src/components/Overview.svelte @@ -114,16 +114,78 @@ } let thing = false; - function checkBoundsAndSet(evt, param) { - if (param.min <= evt.target.value && evt.target.value <= param.max) { - writeAdjustment(evt.target.value, param); + function checkBoundsAndSet(evt, param, isBin) { + let value; + + if (isBin) { + value = parseInt(evt.target.value, 2); + if (param.min !== 0 && evt.target.value.startsWith('1')) { + value = param.min + parseInt(evt.target.value.substring(1), 2); + } } else { - evt.target.value = (evt.target.value > 0) ? param.max : param.min; - writeAdjustment(evt.target.value, param); + value = evt.target.value; } + if (param.min <= value && value <= param.max) { + writeAdjustment(value, param); + } else { + const v = (value > 0) ? param.max : param.min; + writeAdjustment(v, param); + } thing = !thing; } + + function binEdit(evt, param) { + let selStart; + let selEnd; + switch (evt.key) { + case 'ArrowLeft': + case 'ArrowRight': + return; + case 'i': + evt.preventDefault(); + selStart = evt.target.selectionStart; + selEnd = evt.target.selectionEnd; + let out = evt.target.value.substring(0, selStart); + for (const ch of evt.target.value.substring(selStart, selEnd)) { + out += (ch === '0') ? '1' : '0'; + } + out += evt.target.value.substring(selEnd); + evt.target.value = out; + evt.target.setSelectionRange(selStart, selEnd); + + checkBoundsAndSet(evt, param, true); + break; + case 'Backspace': + evt.preventDefault(); + selStart = evt.target.selectionStart + evt.target.value = + evt.target.value.substring(0, selStart - 1) + + '0' + + evt.target.value.substring(selStart); + + evt.target.setSelectionRange(selStart - 1, selStart - 1); + + checkBoundsAndSet(evt, param, true); + break; + case '1': + case '0': + evt.preventDefault(); + selStart = evt.target.selectionStart + evt.target.value = + evt.target.value.substring(0, selStart) + + evt.key + + evt.target.value.substring(selStart + 1); + + evt.target.setSelectionRange(selStart + 1, selStart + 1); + + checkBoundsAndSet(evt, param, true) + break; + default: + evt.preventDefault(); + } + } +