-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
97 lines (84 loc) · 3.05 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>CFR in TeaVM</title>
<style>
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&display=swap");
body {
margin: 0;
padding: 0;
font-family: "JetBrains Mono", monospace;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
background-color: var(--bg-color);
color: var(--text-color);
transition: background-color 0.3s, color 0.3s;
}
:root {
--bg-color: #ffffff;
--text-color: #000000;
}
@media (prefers-color-scheme: dark) {
:root {
--bg-color: #1e1e1e;
--text-color: #cfcfcf;
}
}
#file-input {
margin-bottom: 20px;
}
#file-content {
width: 80%;
max-width: 1024px;
height: 60vh;
padding: 10px;
overflow-y: auto;
border: 1px solid var(--text-color);
border-radius: 5px;
background-color: var(--bg-color);
color: var(--text-color);
white-space: pre-wrap;
}
</style>
</head>
<body>
<input accept=".class" id="file-input" type="file">
<div id="file-content"></div>
<script src="https://cdn.jsdelivr.net/gh/leonardosnt/java-class-tools@master/dist/java-class-tools.min.js"></script>
<script type="module">
import { decompile } from "https://cdn.jsdelivr.net/npm/@run-slicer/cfr/cfr.js";
const decoder = new TextDecoder();
const readClassName = (buf) => {
const cf = new JavaClassTools.JavaClassFileReader().read(buf);
const cpEntry = cf.constant_pool[cf.constant_pool[cf.this_class].name_index];
return decoder.decode(new Uint8Array(cpEntry.bytes));
};
const input = document.getElementById("file-input");
input.value = null; // clear file input
input.addEventListener("change", (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = async (evt) => {
const buf = new Uint8Array(evt.target.result);
const name = readClassName(buf);
const start = Date.now();
console.log(`Decompiling ${name}...`);
document.getElementById("file-content").textContent = await decompile(name, {
source: async (n) => {
return n === name ? buf : null;
},
});
console.log(`Decompiled ${name} in ${Date.now() - start}ms.`);
};
reader.readAsArrayBuffer(file);
}
});
</script>
</body>
</html>