-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmake-signatures.js
59 lines (51 loc) · 1.59 KB
/
make-signatures.js
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
// make-signatures.js - Create file format signature constants.
var Node = {
fs: require('fs')
};
var signatures = {
ICONR: [0x49, 0x63, 0x6f, 0x6e, 0x0d],
RAR: [0x52, 0x61, 0x72, 0x21, 0x1a, 0x07],
TAR: [0x75, 0x73, 0x74, 0x61, 0x72],
XAR: [0x78, 0x61, 0x72, 0x21],
ZIP_CDH: [0x50, 0x4b, 0x01, 0x02],
ZIP_DDR: [0x50, 0x4b, 0x07, 0x08],
ZIP_EOCDL_64: [0x50, 0x4b, 0x06, 0x07],
ZIP_EOCDR_64: [0x50, 0x4b, 0x06, 0x06],
ZIP_EOCDR: [0x50, 0x4b, 0x05, 0x06],
ZIP_LFH: [0x50, 0x4b, 0x03, 0x04],
ZIP_PK: [0x50, 0x4b],
ZIP_SPAN: [0x50, 0x4b, 0x07, 0x08],
ZIP_TEMP: [0x50, 0x4b, 0x30, 0x30]
};
var lines = [];
function line(string) {
lines.push(string);
}
function arrayName(name, octets) {
return 'const uint8_t PURE_S_' + name + '[' + octets.length + ']';
}
function hex(octets) {
return octets.map(
function(octet) {
return '0x' + octet.toString(16).padStart(2, '0');
}
).join(', ');
}
var max = 0;
for (var name in signatures) {
var octets = signatures[name];
var length = arrayName(name, octets).length;
if (length > max) max = length;
}
for (var name in signatures) {
var octets = signatures[name];
var padded = arrayName(name, octets).padEnd(max, ' ');
line(padded + ' = {' + hex(octets) + '};');
}
line('');
for (var name in signatures) {
var octets = signatures[name];
var padded = ('const uint64_t PURE_L_' + name).padEnd(max, ' ');
line(padded + ' = ' + octets.length + ';');
}
Node.fs.writeFileSync('pure_signatures.h', lines.join('\n'), 'utf-8');