Skip to content

Commit 50dc6bc

Browse files
committed
Commit files to repo for distribution. *shrug*
1 parent 659bc3c commit 50dc6bc

File tree

7 files changed

+240
-5
lines changed

7 files changed

+240
-5
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ console_error_panic_hook = { version = "0.1.1", optional = true }
2424
# Unfortunately, `wee_alloc` requires nightly Rust when targeting wasm for now.
2525
wee_alloc = { version = "0.4.2", optional = true }
2626

27-
faerie = { path = "../faerie" }
2827
target-lexicon = "0.9.0"
2928
goblin = "0.1"
3029
scroll = "0.10"
@@ -37,6 +36,10 @@ serde_derive = "^1.0.59"
3736
version = "^0.2"
3837
features = ["serde-serialize"]
3938

39+
[dependencies.faerie]
40+
git = "https://github.com/kitlith/faerie"
41+
branch = "mcorrupt_test"
42+
4043
[dev-dependencies]
4144
wasm-bindgen-test = "0.2"
4245

pkg/.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
*
2-
!.gitignore
3-
!*.user.js
1+
README.md
2+
package.json

pkg/mcorrupt.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @namespace Kitlith
44
// @match https://*.microcorruption.com/cpu/debugger
55
// @grant GM_getResourceURL
6-
// @version 1.0
6+
// @version 0.0.1
77
// @author Kitlith
88
// @require microcorruption_wasm.js
99
// @resource wasm microcorruption_wasm_bg.wasm

pkg/microcorruption_wasm.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* tslint:disable */
2+
/**
3+
* @param {string} name
4+
* @param {Uint8Array} memory
5+
* @param {any} symbols
6+
* @returns {Uint8Array}
7+
*/
8+
export function gen_elf(name: string, memory: Uint8Array, symbols: any): Uint8Array;
9+
10+
/**
11+
* If `module_or_path` is {RequestInfo}, makes a request and
12+
* for everything else, calls `WebAssembly.instantiate` directly.
13+
*
14+
* @param {RequestInfo | BufferSource | WebAssembly.Module} module_or_path
15+
*
16+
* @returns {Promise<any>}
17+
*/
18+
export default function init (module_or_path: RequestInfo | BufferSource | WebAssembly.Module): Promise<any>;
19+

pkg/microcorruption_wasm.js

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
(function() {
2+
const __exports = {};
3+
let wasm;
4+
5+
let WASM_VECTOR_LEN = 0;
6+
7+
let cachedTextEncoder = new TextEncoder('utf-8');
8+
9+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
10+
? function (arg, view) {
11+
return cachedTextEncoder.encodeInto(arg, view);
12+
}
13+
: function (arg, view) {
14+
const buf = cachedTextEncoder.encode(arg);
15+
view.set(buf);
16+
return {
17+
read: arg.length,
18+
written: buf.length
19+
};
20+
});
21+
22+
let cachegetUint8Memory = null;
23+
function getUint8Memory() {
24+
if (cachegetUint8Memory === null || cachegetUint8Memory.buffer !== wasm.memory.buffer) {
25+
cachegetUint8Memory = new Uint8Array(wasm.memory.buffer);
26+
}
27+
return cachegetUint8Memory;
28+
}
29+
30+
function passStringToWasm(arg) {
31+
32+
let len = arg.length;
33+
let ptr = wasm.__wbindgen_malloc(len);
34+
35+
const mem = getUint8Memory();
36+
37+
let offset = 0;
38+
39+
for (; offset < len; offset++) {
40+
const code = arg.charCodeAt(offset);
41+
if (code > 0x7F) break;
42+
mem[ptr + offset] = code;
43+
}
44+
45+
if (offset !== len) {
46+
if (offset !== 0) {
47+
arg = arg.slice(offset);
48+
}
49+
ptr = wasm.__wbindgen_realloc(ptr, len, len = offset + arg.length * 3);
50+
const view = getUint8Memory().subarray(ptr + offset, ptr + len);
51+
const ret = encodeString(arg, view);
52+
53+
offset += ret.written;
54+
}
55+
56+
WASM_VECTOR_LEN = offset;
57+
return ptr;
58+
}
59+
60+
function passArray8ToWasm(arg) {
61+
const ptr = wasm.__wbindgen_malloc(arg.length * 1);
62+
getUint8Memory().set(arg, ptr / 1);
63+
WASM_VECTOR_LEN = arg.length;
64+
return ptr;
65+
}
66+
67+
const heap = new Array(32);
68+
69+
heap.fill(undefined);
70+
71+
heap.push(undefined, null, true, false);
72+
73+
let stack_pointer = 32;
74+
75+
function addBorrowedObject(obj) {
76+
if (stack_pointer == 1) throw new Error('out of js stack');
77+
heap[--stack_pointer] = obj;
78+
return stack_pointer;
79+
}
80+
81+
let cachegetInt32Memory = null;
82+
function getInt32Memory() {
83+
if (cachegetInt32Memory === null || cachegetInt32Memory.buffer !== wasm.memory.buffer) {
84+
cachegetInt32Memory = new Int32Array(wasm.memory.buffer);
85+
}
86+
return cachegetInt32Memory;
87+
}
88+
89+
function getArrayU8FromWasm(ptr, len) {
90+
return getUint8Memory().subarray(ptr / 1, ptr / 1 + len);
91+
}
92+
/**
93+
* @param {string} name
94+
* @param {Uint8Array} memory
95+
* @param {any} symbols
96+
* @returns {Uint8Array}
97+
*/
98+
__exports.gen_elf = function(name, memory, symbols) {
99+
const retptr = 8;
100+
try {
101+
const ret = wasm.gen_elf(retptr, passStringToWasm(name), WASM_VECTOR_LEN, passArray8ToWasm(memory), WASM_VECTOR_LEN, addBorrowedObject(symbols));
102+
const memi32 = getInt32Memory();
103+
const v0 = getArrayU8FromWasm(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1]).slice();
104+
wasm.__wbindgen_free(memi32[retptr / 4 + 0], memi32[retptr / 4 + 1] * 1);
105+
return v0;
106+
} finally {
107+
heap[stack_pointer++] = undefined;
108+
}
109+
};
110+
111+
function getObject(idx) { return heap[idx]; }
112+
113+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
114+
115+
cachedTextDecoder.decode();
116+
117+
function getStringFromWasm(ptr, len) {
118+
return cachedTextDecoder.decode(getUint8Memory().subarray(ptr, ptr + len));
119+
}
120+
121+
let heap_next = heap.length;
122+
123+
function addHeapObject(obj) {
124+
if (heap_next === heap.length) heap.push(heap.length + 1);
125+
const idx = heap_next;
126+
heap_next = heap[idx];
127+
128+
heap[idx] = obj;
129+
return idx;
130+
}
131+
132+
function dropObject(idx) {
133+
if (idx < 36) return;
134+
heap[idx] = heap_next;
135+
heap_next = idx;
136+
}
137+
138+
function takeObject(idx) {
139+
const ret = getObject(idx);
140+
dropObject(idx);
141+
return ret;
142+
}
143+
144+
function init(module) {
145+
146+
let result;
147+
const imports = {};
148+
imports.wbg = {};
149+
imports.wbg.__wbindgen_json_serialize = function(arg0, arg1) {
150+
const obj = getObject(arg1);
151+
const ret = JSON.stringify(obj === undefined ? null : obj);
152+
const ret0 = passStringToWasm(ret);
153+
const ret1 = WASM_VECTOR_LEN;
154+
getInt32Memory()[arg0 / 4 + 0] = ret0;
155+
getInt32Memory()[arg0 / 4 + 1] = ret1;
156+
};
157+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
158+
const ret = getStringFromWasm(arg0, arg1);
159+
return addHeapObject(ret);
160+
};
161+
imports.wbg.__wbindgen_rethrow = function(arg0) {
162+
throw takeObject(arg0);
163+
};
164+
165+
if ((typeof URL === 'function' && module instanceof URL) || typeof module === 'string' || (typeof Request === 'function' && module instanceof Request)) {
166+
167+
const response = fetch(module);
168+
if (typeof WebAssembly.instantiateStreaming === 'function') {
169+
result = WebAssembly.instantiateStreaming(response, imports)
170+
.catch(e => {
171+
return response
172+
.then(r => {
173+
if (r.headers.get('Content-Type') != 'application/wasm') {
174+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
175+
return r.arrayBuffer();
176+
} else {
177+
throw e;
178+
}
179+
})
180+
.then(bytes => WebAssembly.instantiate(bytes, imports));
181+
});
182+
} else {
183+
result = response
184+
.then(r => r.arrayBuffer())
185+
.then(bytes => WebAssembly.instantiate(bytes, imports));
186+
}
187+
} else {
188+
189+
result = WebAssembly.instantiate(module, imports)
190+
.then(result => {
191+
if (result instanceof WebAssembly.Instance) {
192+
return { instance: result, module };
193+
} else {
194+
return result;
195+
}
196+
});
197+
}
198+
return result.then(({instance, module}) => {
199+
wasm = instance.exports;
200+
init.__wbindgen_wasm_module = module;
201+
202+
return wasm;
203+
});
204+
}
205+
206+
self.wasm_bindgen = Object.assign(init, __exports);
207+
208+
})();

pkg/microcorruption_wasm_bg.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* tslint:disable */
2+
export const memory: WebAssembly.Memory;
3+
export function gen_elf(a: number, b: number, c: number, d: number, e: number, f: number): void;
4+
export function __wbindgen_malloc(a: number): number;
5+
export function __wbindgen_realloc(a: number, b: number, c: number): number;
6+
export function __wbindgen_free(a: number, b: number): void;

pkg/microcorruption_wasm_bg.wasm

384 KB
Binary file not shown.

0 commit comments

Comments
 (0)