-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
382 lines (316 loc) · 12.4 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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<!DOCTYPE html>
<html>
<head>
<meta property="og:title" content="acropalypse screenshot recovery utility"/>
<meta property="og:type" content="website"/>
<meta name="theme-color" content="#36393f">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title>acropalypse</title>
<style>
@font-face {
font-family: "Noto Sans";
src: url(NotoSans.ttf);
}
@font-face {
font-family: "Noto Sans Bold";
src: url(NotoSans-Bold.ttf);
}
body {
color: white;
font-family: "Noto Sans", sans-serif;
margin: 2em;
text-align: center;
animation: intro 1s forwards;
background: linear-gradient(to bottom right, #36393f, #26292f);
background-attachment: fixed;
}
.settings {
text-align: left;
width: 300px;
margin: auto;
}
.resolution {
transition: opacity 0.5s;
}
input {
font-family: "Noto Sans", sans-serif;
}
input[type="number"] {
width: 60px;
background-color: transparent;
color: white;
border: 1px solid #ccc;
border-radius: 4px;
padding-left: 4px;
}
input[type="file"] {
display: none;
}
select {
font-family: "Noto Sans", sans-serif;
width: 240px;
background-color: transparent;
color: white;
border: 1px solid #ccc;
border-radius: 4px;
}
option, optgroup {
background-color: #36393f;
}
.upload {
border: 1px solid #ccc;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
text-align: center;
border-radius: 8px;
transition: background-color 0.4s ease;
width: 280px;
}
.upload:hover {
background-color: #5b5d61;
}
.logo {
font-family: "Noto Sans Bold";
color: #f55;
font-size: 40pt;
}
.logo-crop {
color: white;
background-color: rgba(255,255,255,0.2);
position: relative;
padding-bottom: 0.2em;
}
.logo-crop::before, .logo-crop::after {
position: absolute;
width: 0.2em;
height: 0.2em;
border-style: solid;
border-color: white;
content: ' ';
}
.logo-crop::before {
top: -0.5em;
left: -0.5em;
animation: crop1 0.5s 0.2s forwards;
border-width: 0.2em 0 0 0.2em;
}
.logo-crop::after {
right: -0.5em;
bottom: -0.5em;
animation: crop2 0.5s 0.2s forwards;
border-width: 0 0.2em 0.2em 0;
}
@keyframes crop1 {
from {
top: -0.5em;
left: -0.5em;
}
to {
top: -0.1em;
left: -0.1em;
}
}
@keyframes crop2 {
from {
right: -0.5em;
bottom: -0.5em;
}
to {
right: -0.1em;
bottom: -0.1em;
}
}
@keyframes intro {
from {
opacity: 0;
margin-top: 100px;
}
to {
opacity: 1;
margin-top: 0px;
}
}
</style>
<script type="text/javascript" src="./acropalypse.js"></script>
</head>
<body>
<h1 class="logo">a<span class="logo-crop">crop</span>alypse</h1>
<h2>Screenshot recovery utility</h2>
<div class="settings">
<div>
Device:
<select id="device" onchange="setDevice()">
<optgroup label="Device presets">
<option value="p3">Pixel 3</option>
<option value="p3xl">Pixel 3 XL</option>
<option value="p3a">Pixel 3a</option>
<option value="p3axl">Pixel 3a XL</option>
<option value="p4">Pixel 4</option>
<option value="p4xl">Pixel 4 XL</option>
<option value="p4a">Pixel 4a</option>
<option value="p5">Pixel 5</option>
<option value="p5a">Pixel 5a</option>
<option value="p6">Pixel 6</option>
<option value="p6pro">Pixel 6 Pro</option>
<option value="p6a">Pixel 6a</option>
<option value="p7">Pixel 7</option>
<option value="p7pro" selected>Pixel 7 Pro</option>
</optgroup>
<optgroup label="Custom resolution">
<option value="custom">Custom</option>
</optgroup>
</select>
</div>
<br>
<div id="resolution" class="resolution" style="display: none">
Resolution: <input id="height" value="3120" type="number"> h × <input id="width" value="1440" type="number"> w
<br><br>
</div>
</div>
<label for="upload" class="upload">Select screenshot</label>
<input type="file" id="upload"><br>
<p id="status"></p>
<img id="output" width="90%"><br>
<script>
const acropalypse_recover = Module.cwrap('acropalypse_recover', Number, [Number, Number, Number, Number, Number]);
// Set height and width
function setResolution(height, width)
{
document.getElementById('height').value = height;
document.getElementById('width').value = width;
}
function setDevice()
{
let device = document.getElementById('device');
let custom = document.getElementById('resolution');
if (device.value == 'custom')
{
custom.style.display = 'inline';
return;
}
else
{
custom.style.display = 'none';
}
// Select resolution for device selected
switch (device.value)
{
case 'p3':
case 'p3axl':
setResolution(2160, 1080); break;
case 'p3xl':
setResolution(2960, 1440); break;
case 'p3a':
setResolution(2220, 1080); break;
case 'p4':
setResolution(2280, 1080); break;
case 'p4xl':
setResolution(3040, 1440); break;
case 'p4a':
case 'p5':
setResolution(2340, 1080); break;
case 'p5a':
case 'p6':
case 'p6a':
case 'p7':
setResolution(2400, 1080); break;
case 'p6pro':
case 'p7pro':
setResolution(3120, 1440);
}
}
function getErrorMessage(code)
{
switch (code)
{
case -1: return 'Invalid PNG header.';
case -2: return 'No additional image data found.';
case -3: return 'Unknown PNG chunk found.';
case -4: return 'Unable to decompress additional image data. Refresh the page and try again.'
default: return 'An unknown error occurred.';
}
}
document.getElementById('upload').addEventListener('change', event =>
{
let status = document.getElementById('status');
status.textContent = 'Recovering image...';
let height = parseInt(document.getElementById('height').value);
let width = parseInt(document.getElementById('width').value);
// Ensure height and width are entered
if (isNaN(height) || isNaN(width))
{
status.textContent = 'Error: Please select height and width!';
return;
}
// Get uploaded file
let file = event.target.files[0];
// Ensure uploaded image is a PNG
if (file.type != 'image/png')
{
status.textContent = 'Error: Input file is not a PNG!';
return;
}
let reader = new FileReader();
// Runs when file is read
reader.onload = function(e)
{
// Convert image data to u8 array
let originalImage = new Uint8Array(e.target.result);
// Calculate array lengths
let inputLen = file.size;
let outputLen = ((width * 3) + 1) * height;
// Allocate memory in WASM heap
const inputPtr = Module._malloc(inputLen);
const outputPtr = Module._malloc(outputLen);
// Create JS arrays from WASM heap
let input = new Uint8Array(Module.HEAPU8.buffer, inputPtr, inputLen);
let output = new Uint8Array(Module.HEAPU8.buffer, outputPtr, outputLen);
// Copy image data to WASM heap
input.set(originalImage);
// Trigger JS garbage collector
originalImage = null;
// Get image
let image = document.getElementById('output');
// Attempt to recover image using the ACropalypse bug
let ret;
if ((ret = acropalypse_recover(inputPtr, inputLen, outputPtr, width, height)) < 0)
{
// Free memory
Module._free(inputPtr);
Module._free(outputPtr);
// Trigger garbage collector
input = null;
output = null;
// Set error
status.textContent = 'Error: ' + getErrorMessage(ret);
// Hide image
image.style.display = 'none';
// Delete last image if present
if (image.src)
URL.revokeObjectURL(image.src);
return;
}
// Create new array of size ret
let recoveredImage = new Uint8Array(Module.HEAPU8.buffer, outputPtr, ret);
status.textContent = 'Your recovered image:';
// Delete last image if present
if (image.src)
URL.revokeObjectURL(image.src);
// Set image
image.src = URL.createObjectURL(new Blob([recoveredImage], { type: 'image/png' }));
image.style.display = 'inline';
// Free memory
Module._free(inputPtr);
Module._free(outputPtr);
// Trigger garbage collector
input = null;
output = null;
recoveredImage = null;
}
// Read file
reader.readAsArrayBuffer(file);
});
</script>
</body>
</html>