-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "microcorruption-wasm" | ||
version = "0.1.0" | ||
version = "0.0.3" | ||
authors = ["Kitlith <[email protected]>"] | ||
edition = "2018" | ||
|
||
|
@@ -27,6 +27,7 @@ wee_alloc = { version = "0.4.2", optional = true } | |
target-lexicon = "0.9.0" | ||
goblin = "0.1" | ||
scroll = "0.10" | ||
byteorder = "1.3.2" | ||
|
||
serde = "^1.0.59" | ||
serde_json = "^1.0.40" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
// @namespace Kitlith | ||
// @match https://*.microcorruption.com/cpu/debugger | ||
// @grant GM_getResourceURL | ||
// @version 0.0.1 | ||
// @version 0.0.3 | ||
// @author Kitlith | ||
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/FileSaver.min.js | ||
// @require microcorruption_wasm.js | ||
// @resource wasm microcorruption_wasm_bg.wasm | ||
// @description Adds a command (dump) to the debugger that performs a memory dump (w/ symbols!) and downloads it as "<level name>.elf" | ||
|
@@ -14,35 +15,38 @@ | |
// For now, this works without too much modification. | ||
wasm_bindgen(GM_getResourceURL('wasm')); | ||
|
||
unsafeWindow.cpu._dump = (function () { | ||
// File download code from: https://stackoverflow.com/a/19328891 | ||
var a = document.createElement("a"); | ||
a.style = "display: none"; | ||
document.body.appendChild(a); | ||
return function (e) { | ||
// cpu.memory is a sparse js 'array', let's convert it to a full 64KiB array before downloading | ||
var memory = new Uint8Array(0x10000); | ||
for (key in cpu.memory) { | ||
memory[key] = cpu.memory[key]; | ||
} | ||
function getMemory() { | ||
// cpu.memory is a sparse js 'array', let's convert it to a full 64KiB array before downloading | ||
var memory = new Uint8Array(0x10000); | ||
for (key in cpu.memory) { | ||
memory[key] = cpu.memory[key]; | ||
} | ||
|
||
return memory; | ||
} | ||
|
||
var symbols = {}; | ||
for (elem of document.getElementsByClassName("insnlabel")) { | ||
let addr = parseInt(elem.innerText.slice(0, 4), 16); // first four characters are address in hex | ||
let name = elem.textContent.slice(7, -2); // skip the addr, skip ' <', and leave out '>' | ||
symbols[name] = addr; | ||
unsafeWindow.cpu._dump = function (e) { | ||
var symbols = {}; | ||
for (elem of document.getElementsByClassName("insnlabel")) { | ||
let addr = parseInt(elem.innerText.slice(0, 4), 16); // first four characters are address in hex | ||
if (isNaN(addr)) { | ||
continue; | ||
} | ||
let name = elem.textContent.slice(7, -2); // skip the addr, skip ' <', and leave out '>' | ||
symbols[name] = addr; | ||
} | ||
|
||
console.log(symbols); | ||
// By querying whoami, we can get the current level name. woo! | ||
cpu.get('/whoami', function(e) { | ||
var memory = getMemory(); | ||
let elf = wasm_bindgen.gen_elf(e.level, memory, symbols); | ||
saveAs(new Blob([elf], {type: "application/octet-stream"}), e.level + ".elf"); | ||
}); | ||
}; | ||
|
||
// By querying whoami, we can get the current level name. woo! | ||
cpu.get('/whoami', function(e) { | ||
let elf = wasm_bindgen.gen_elf(e.level, memory, symbols); | ||
var url = unsafeWindow.URL.createObjectURL(new Blob([elf], {type: "application/octet-stream"})); | ||
a.href = url; | ||
a.download = e.level + ".elf"; | ||
a.click(); | ||
unsafeWindow.URL.revokeObjectURL(url); | ||
}); | ||
}; | ||
}()); | ||
unsafeWindow.cpu._dumpbin = function () { | ||
cpu.get('/whoami', function(e) { | ||
var memory = getMemory(); | ||
saveAs(new Blob([memory], {type: "application/octet-stream"}), e.level + ".bin"); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters