-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
311 lines (282 loc) · 7.55 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Binary Check</title>
<style>
html, body, p {
margin: 0;
}
html, body, #root, #progress {
height: 100%;
}
body {
background-color: #444;
}
#root {
display: flex;
justify-content: center;
align-items: center;
}
#progress {
width: 0;
position: fixed;
background-color: #333;
}
#status {
font-size: 100px;
}
#made {
position: fixed;
left: -20px;
bottom: 0;
height: 30px;
width: 100%;
color: white;
text-align: right;
}
#made,
code {
z-index: 1;
font-family: monospace;
}
code {
text-align: center;
}
p>strong {
font-size: 20px
}
a {
color: red;
font-weight: 700;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
</style>
</head>
<body>
<div id="progress"></div>
<div id="root">
<code>
<p id="status">DROP APP HERE</p>
<p id="app"></p>
</code>
</div>
<div id="made">[made with ❤ by
<a href="https://www.red-lang.org/">Red language</a>]
</div>
</body>
<script async src="orgs.js"></script>
<script>
var run = false
</script>
<script>
run = true
var utils = {
platforms: { w: "Windows", m: "macOS", l: "Linux" },
sha256: async function(b) {
const hb = await crypto.subtle.digest('SHA-256', b)
const ha = Array.from(new Uint8Array(hb))
return ha.map(b => ('00' + b.toString(16)).slice(-2)).join('')
},
sortObject: function(items, key) {
return items.sort((a, b) => {
if (a[key] < b[key]) {
return -1
}
if (a[key] > b[key]) {
return 1
}
return 0
})
},
getDir: function(entry, path) {
return new Promise((resolve) => {
entry.getDirectory(path, {}, resolve);
});
},
readFile: function(item, direct) {
return new Promise((resolve) => {
const reader = new FileReader()
reader.onload = () => resolve(reader.result)
if (direct) {
reader.readAsArrayBuffer(item)
} else {
item.file(file => { reader.readAsArrayBuffer(file) })
}
})
},
readDir: async function(item, tree, files) {
return new Promise((resolve) => {
item.createReader().readEntries(
async function(entries) {
tree[item.name] = {}
const path = item.fullPath.split('/')
const items = []
// sort directory entries as APFS doesn't!
utils.sortObject(entries, 'name').map(entry => { items.push(entry.name) })
if (
path.slice(-2)[0] === 'Frameworks' &&
path.slice(-1)[0].match(/\.framework$/g) &&
items.indexOf('Versions') >= 0
) {
// Firefox: don't scan aliases on macOS
await utils.dive(
entries[items.indexOf('Versions')],
tree[item.name],
files
)
} else {
if (
path.slice(-3)[0] === 'Frameworks' &&
path.slice(-2)[0].match(/\.framework$/g) &&
path.slice(-1)[0] === 'Versions' &&
items.indexOf('Current') >= 0
) {
// Firefox: don't scan aliases on macOS
entries.pop(items.indexOf('Current'))
}
for (let entry of entries) {
await utils.dive(entry, tree[item.name], files)
}
}
resolve()
}
)
})
},
dive: async function(item, tree, files) {
if (item.isDirectory) {
await utils.readDir(item, tree, files)
} else {
tree[item.name] = 0
console.log(item.fullPath)
// Safari does not list dot files,
// filter out for other browsers as well
if (!item.name.match(/^\./)) {
files.push(item)
}
}
}
}
var html = {
body: document.body,
progress: document.getElementById('progress'),
status: document.getElementById('status'),
app: document.getElementById('app'),
a: document.querySelector('a'),
reset: function() {
html.body.style['background-color'] = '#444'
html.progress.style.width = 0
html.status.innerHTML = 'DROP APP HERE'
html.app.innerHTML = ''
html.a.style.color = 'red'
},
ok: function(data) {
html.progress.style.width = 0
html.body.style['background-color'] = 'green'
html.status.innerHTML = 'OK'
html.app.innerHTML = `<strong><a href="${data.app.commit ? data.app.url + '/commit/' + data.app.commit : data.app.url}">${data.app.name}</a> ${data.app.version}</strong> for <strong>${data.app.platform}</strong> by <strong><a href="${data.org.url}">${data.org.name}</a></strong>`
},
nok: function() {
html.progress.style.width = 0
html.body.style['background-color'] = 'red'
html.a.style.color = 'black'
html.status.innerHTML = 'DANGER'
html.app.innerHTML = `<strong>We couldn't identify this App, make sure you download from a trusted source.</strong>`
},
drop: {
stop: function(e) {
e.stopPropagation()
e.preventDefault()
},
enter: function(e) {
html.drop.stop(e)
html.reset()
html.body.style['background-color'] = '#666'
},
leave: function(e) {
html.drop.stop(e)
html.body.style['background-color'] = '#444'
},
start: function() {
html.body.addEventListener('dragenter', html.drop.enter, true)
html.body.addEventListener('dragleave', html.drop.leave, true)
html.body.addEventListener('dragover', html.drop.enter, true)
html.body.addEventListener('drop', html.drop.drop, true)
},
end: function() {
html.body.removeEventListener('dragenter', html.drop.enter)
html.body.removeEventListener('dragleave', html.drop.leave)
html.body.removeEventListener('dragover', html.drop.enter)
html.body.removeEventListener('drop', html.drop.drop)
},
drop: async function(e) {
const start = new Date()
html.drop.stop(e)
html.drop.end()
html.reset()
let itemIsDir, safariSucks, item
if (e.dataTransfer.items) {
item = e.dataTransfer.items[0].webkitGetAsEntry()
itemIsDir = item.isDirectory
safariSucks = item.name.match(/\.app\.zip$/g) && itemIsDir
}
let hash
if (itemIsDir) {
const tree = {}
const files = []
const hashes = []
await utils.dive(safariSucks ? await utils.getDir(item, '/' + item.name.replace(/\.zip$/, '')) : item, tree, files)
const total = files.length
let counter = 0
// console.log(tree)
// console.log(files)
for (let file of files) {
hashes.push(await utils.sha256(await utils.readFile(file)))
counter += 1
html.status.innerHTML = Math.floor(100 / total * counter) + '%'
html.progress.style.width = Math.floor(html.body.clientWidth / total * counter) + 'px'
}
// console.log(hashes)
hash = await utils.sha256(new TextEncoder('utf-8').encode(hashes.join('')))
} else {
hash = await utils.sha256(await utils.readFile(e.dataTransfer.files[0], true))
}
// const found = whitelist[hash]
const whitelist = (await (await fetch('whitelist/' + hash.charAt(0) + '.txt')).text())
const found = whitelist.match(new RegExp(hash + '\/(.*)\n', 'i'))
if (found) {
const d = found[1].split('/')
const data = {
org: {
name: orgs[d[0]].name,
url: orgs[d[0]].url
},
app: {
name: orgs[d[0]].apps[d[1]].name,
url: orgs[d[0]].apps[d[1]].url,
platform: utils.platforms[d[2]],
version: d[3],
commit: d[4]
}
}
html.ok(data)
console.log(data)
} else {
html.nok()
}
console.log('sha256: ' + hash)
console.log('Done in ' + (new Date() - start) / 1000 + ' seconds')
html.drop.start()
}
}
}
</script>
<script>
run ? html.drop.start() : document.getElementById('status').innerHTML = 'Use a more modern browser'
</script>
</html>