From 0e0803c85b690ef762d4825494429f1574c5c804 Mon Sep 17 00:00:00 2001 From: Miguel Villegas <145287911+zarfadev@users.noreply.github.com> Date: Mon, 20 Apr 2026 17:01:21 -0500 Subject: [PATCH] v1.0 --- js/app.js | 13 +++++++++++-- js/keygen.js | 21 ++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/js/app.js b/js/app.js index c1b29ce..6634b3d 100644 --- a/js/app.js +++ b/js/app.js @@ -72,15 +72,24 @@ document.addEventListener('alpine:init', () => { // Generate the raw license string const keyData = generateWinRARLicense(this.userName, this.licenseType); - // Use Data URI instead of Blob to prevent UUID filenames on file:// protocol + // Use Uint8Array and Blob to prevent double-encoding of UTF-8 characters by the browser + const bytes = new Uint8Array(keyData.length); + for (let i = 0; i < keyData.length; i++) { + bytes[i] = keyData.charCodeAt(i); + } + const blob = new Blob([bytes], { type: "application/octet-stream" }); + const link = document.createElement("a"); - link.setAttribute("href", "data:application/octet-stream;charset=utf-8," + encodeURIComponent(keyData)); + link.setAttribute("href", URL.createObjectURL(blob)); link.setAttribute("download", "rarreg.key"); // Programmatically trigger download document.body.appendChild(link); link.click(); document.body.removeChild(link); + + // Keep memory clean + setTimeout(() => URL.revokeObjectURL(link.href), 100); this.showToast(this.t.successMsg); } catch (err) { diff --git a/js/keygen.js b/js/keygen.js index c35015b..f11cb55 100644 --- a/js/keygen.js +++ b/js/keygen.js @@ -1,4 +1,23 @@ -window.generateWinRARLicense = function(username, licenseType) { +window.generateWinRARLicense = function(raw_username, raw_licenseType) { + function encodeForWinRAR(str) { + var hasNonAscii = false; + for (var i = 0; i < str.length; i++) { + if (str.charCodeAt(i) > 127) { hasNonAscii = true; break; } + } + if (hasNonAscii && !str.startsWith("utf8:")) { + str = "utf8:" + str; + } + var bytes = new TextEncoder().encode(str); + var res = ""; + for (var i = 0; i < bytes.length; i++) { + res += String.fromCharCode(bytes[i]); + } + return res; + } + + var username = encodeForWinRAR(raw_username); + var licenseType = encodeForWinRAR(raw_licenseType); + let $ = function f() { let $ = new Uint32Array(32767), e = 1; $[0] = 1;