-
Notifications
You must be signed in to change notification settings - Fork 1
/
signum-d-or.html
261 lines (237 loc) · 8.56 KB
/
signum-d-or.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<html lang="en">
<head>
<title>Signum D`OR</title>
<meta charset="utf-8">
<script src="src/decompiler.js"></script>
<script src="src/optimizer.js"></script>
<script src="src/bytecode.js"></script>
<script src="src/asm_highlight.js"></script>
<script src="3rdParty/difflib.js"></script>
<script src="3rdParty/diffview.js"></script>
<style>
body {
font-size: 100%;
}
h1 {
text-align: center;
}
h3 {
margin-bottom: 5px;
}
.right {
float: right;
width: 50%;
}
.left {
float: left;
width: 50%;
}
textarea {
width: 100%;
height: 50px;
padding: 5px 5px 5px 5px;
min-height: 75px;
}
pre {
font-family: "Lucida Console", "Courier New", 'monospace';
border: solid 1px black;
padding: 5px;
white-space: pre-wrap;
word-wrap: anywhere;
min-height: 75px;
}
output {
font-family: "Lucida Console", "Courier New", 'monospace';
}
button {
margin: 20px 0px 20px 0px;
padding: 5px 20px 5px 20px;
}
footer {
font-size: 0.875em;
}
table.diff {
border-collapse:collapse;
border:1px solid darkgray;
white-space:pre-wrap
}
/* table.diff tbody {
font-family:Courier, monospace;
} */
table.diff tbody th {
font-family:verdana,arial,'Bitstream Vera Sans',helvetica,sans-serif;
background:#EED;
/* font-size:11px; */
font-weight:normal;
border:1px solid #BBC;
color:#886;
padding:.3em .5em .1em 2em;
text-align:right;
vertical-align:middle;
font-size:70%;
}
table.diff thead {
border-bottom:1px solid #BBC;
background:#EFEFEF;
font-family:Verdana;
font-size:80%;
}
table.diff thead th.texttitle {
text-align:left
}
table.diff tbody td {
padding:0px .4em;
padding-top:.4em;
vertical-align:middle;
}
table.diff .empty {
background-color:#f7f7f7;
}
table.diff .replace {
background-color:#Fea
}
table.diff .delete {
background-color:#fbb
}
table.diff .skip {
background-color:#EFEFEF;
border:1px solid #AAA;
border-right:1px solid #BBC;
}
table.diff .insert {
background-color:#9E9
}
table.diff th.author {
text-align:right;
border-top:1px solid #BBC;
background:#EFEFEF
}
</style>
<script>
function ClickDecompile() {
var codeString = document.getElementById("codeString").value;
var outputMAP = document.getElementById("map_obj");
//decompile
var decomp_output = decompiler(codeString.trim(), outputMAP.value);
outputMAP.value = JSON.stringify(decomp_output.JSONmap, stringifyReplacer, ' ');
document.getElementById("decompiled_assembly").innerHTML = asm_highlight(decomp_output.AssemblyProgram);
//optimize
if (document.getElementById("check_optimize").checked) {
var optimized = optimizer(decomp_output.AssemblyProgram);
document.getElementById("optimized_assembly").innerHTML = asm_highlight(optimized);
}
//diff view
if (document.getElementById("check_diff").checked) {
var diffoutputdiv=document.getElementById("diff_table");
var base=difflib.stringAsLines(asm_highlight(decomp_output.AssemblyProgram));
var newtxt=difflib.stringAsLines(asm_highlight(optimized));
var sm= new difflib.SequenceMatcher(base, newtxt);
var opcodes = sm.get_opcodes();
diffoutputdiv.innerHTML = "";
var Obj = {
baseTextLines: base,
newTextLines: newtxt,
opcodes: opcodes,
viewType: 0,
baseTextName: "Decompiled",
newTextName: "Optimized",
contextSize: null,
viewType: 0
}
diffoutputdiv.appendChild(diffview.buildView(Obj));
}
//recompile
if (document.getElementById("check_recompile").checked) {
var recompiled=bytecode(optimized);
document.getElementById("recompiled_bytecode").innerHTML = JSON.stringify(recompiled, stringifyReplacer, ' ');
}
function stringifyReplacer(key, value) {
if (typeof value === 'bigint') {
return value.toString(10); //+ 'n';
} else if (typeof value === 'number'){
return value.toString(10);
} else {
return value;
}
}
}
function check_optimize(ev) {
if ((ev.checked !== undefined && ev.checked) || (ev.target !== undefined && ev.target.checked)) {
document.getElementById("optimized_div").style.display="block";
} else {
document.getElementById("optimized_div").style.display="none";
}
}
function check_diff(ev) {
if ((ev.checked !== undefined && ev.checked) || (ev.target !== undefined && ev.target.checked)) {
document.getElementById("diff_div").style.display="block";
} else {
document.getElementById("diff_div").style.display="none";
}
}
function check_recompile(ev) {
if ((ev.checked !== undefined && ev.checked) || (ev.target !== undefined && ev.target.checked)) {
document.getElementById("recompiled_div").style.display="block";
} else {
document.getElementById("recompiled_div").style.display="none";
}
}
window.onload = function () {
if (!document.getElementById("check_optimize").checked) {
document.getElementById("optimized_div").style.display="none";
}
//diff view
if (!document.getElementById("check_diff").checked) {
document.getElementById("diff_div").style.display="none";
}
//recompile
if (!document.getElementById("check_recompile").checked) {
document.getElementById("recompiled_div").style.display="none";
}
}
</script>
</head>
<body>
<div>
<h1>Signum D`OR - Smart contracts Decompiler/Optimizer/Recompiler</h1>
<h3>Paste here contract's machineCode:</h3>
<textarea id="codeString" placeholder="Bytecode here"></textarea>
<button id="codeDecompile" onClick="javascript: ClickDecompile();">Decompile/Optimize/Recompile</button>
<label><input type="checkbox" id="check_optimize" checked="true" onClick="javascript: check_optimize(this);">Optimize </label>
<label><input type="checkbox" id="check_diff" checked="true" onClick="javascript: check_diff(this);">Show diff </label>
<label><input type="checkbox" id="check_recompile" checked="true" onClick="javascript: check_recompile(this);">Recompile </label>
</div>
<div>
<h3>MAP object (optional):</h3>
<textarea id="map_obj" placeholder="Edit/paste MAP object. Remember to delete when pasting a new machineCode!!!"></textarea>
</div>
<div id="recompiled_div">
<h3>Optimized and recompiled smart contract details:</h3>
<pre id="recompiled_bytecode"></pre>
</div>
<div id="diff_div">
<h3>Diff table:</h3>
<output id="diff_table"></output>
</div>
<div id="optimized_div" class="right">
<h3>Optimized assembly:</h3>
<pre id="optimized_assembly">Always check with diff tools!</pre>
</div>
<div class="left">
<h3>Decompiled assembly:</h3>
<pre id="decompiled_assembly">Always check with diff tools!</pre>
</div>
<div>
<br/><br/><br/>
<footer>Create your program in <a href="https://github.com/deleterium/SmartC">SmartC</a> to optimize even more!<br />
Notes:<br />
• Tuned for smart contracts created with SmartJ/BlockTalk.<br />
• Always check assembly code. Please report if wrong optimizations occurs<br />
Releases:<br/>
• July 2021 • <a href="https://github.com/deleterium/Signum-D-Or">deleterium</a> S-DKVF-VE8K-KUXB-DELET<br/>
• April 2022 • <a href="https://github.com/deleterium/Signum-D-Or">deleterium</a> S-DKVF-VE8K-KUXB-DELET - Including AT Version 3 codes<br/>
• July 2024 • <a href="https://github.com/deleterium/Signum-D-Or">deleterium</a> S-DKVF-VE8K-KUXB-DELET - Fixing missing 3 API codes<br/>
</footer>
</div>
</body>
</html>