Skip to content

Commit

Permalink
Add extra message for zeroed keys
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Jun 9, 2022
1 parent b14e686 commit f3c60cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
51 changes: 45 additions & 6 deletions finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ function findTreasureKeys(file, callback) {
}

function setResultBox(type, text, isCode) {
var resultSpinner = document.getElementById("result-spinner");
if (type == "process") {
type = "primary";
resultSpinner.style.display = "inline-block";
} else {
resultSpinner.style.display = "none";
}

var resultBox = document.getElementById("result");
resultBox.classList = "alert alert-" + type;
if (isCode) {
resultBox.classList += " font-monospace";
}

resultBox.style.display = "block";
resultBox.innerText = text;

var resultText = document.getElementById("result-text");
resultText.innerText = text;
}

function toHexString(byteArray) {
Expand All @@ -96,7 +106,7 @@ function toHexString(byteArray) {
}).join("");
}

function decodeCipherContext(data) {
function decodeCipherContext(data, offset) {
var resultText = "";

var dv = new DataView(data.buffer);
Expand All @@ -117,7 +127,33 @@ function decodeCipherContext(data) {
resultText += "\n";
resultText += "raw: " + toHexString(data) + "\n";

return resultText;
let isNull = data.every(function (byte) {
return byte === 0;
});

if (cipher === 0x1 && keylen === 0x10) {
setResultBox(
"success",
"Found decryption keys at 0x" + offset.toString(16) + ":\n" + resultText,
true
);
} else if (isNull) {
setResultBox(
"warning",
"Key offset was found (0x" +
offset.toString(16) +
"), but the key data is zeroed out!\n\nThis usually means that the memory dump was made before the character select screen.\nIf you believe this is a mistake, please report it to cohae."
);
} else {
setResultBox(
"danger",
"Key offset was found (0x" +
offset.toString(16) +
"), but data doesn't seem valid\n" +
resultText,
true
);
}
}

function dropHandler(ev) {
Expand All @@ -134,7 +170,7 @@ function dropHandler(ev) {
var file = ev.dataTransfer.items[0].getAsFile();

setResultBox(
"primary",
"process",
"Searching file, please wait\n(this may take a while depending on the file size)"
);
findTreasureKeys(file, function (cipherContext, data) {
Expand All @@ -145,8 +181,7 @@ function dropHandler(ev) {
}

if (data) {
let resultText = decodeCipherContext(data);
setResultBox("success", "Found decryption keys:\n" + resultText, true);
decodeCipherContext(data, cipherContext);
console.log(data);
}
});
Expand All @@ -156,3 +191,7 @@ function dropHandler(ev) {
function dragOverHandler(ev) {
ev.preventDefault();
}

onload = function () {
setResultBox("primary", "Waiting for file...", false);
};
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
</div>
</div>
<div class="d-flex justify-content-center mt-3">
<div class="alert alert-primary" id="result" role="alert" style="max-width: 64rem; overflow-wrap: break-word;">
Waiting for file...
<div class="alert alert-primary align-middle d-flex align-items-center" id="result" role="alert" style="max-width: 64rem; overflow-wrap: break-word;">
<div class="spinner-border text-dark me-3" role="status" id="result-spinner">
<span class="visually-hidden">Loading...</span>
</div>
<span id="result-text">Waiting for file...</span>
</div>
</div>
</body>
Expand Down

0 comments on commit f3c60cc

Please sign in to comment.