-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (51 loc) · 1.79 KB
/
index.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
const fs = require('fs');
const FILE_PATH = './container.225'
const FILE_IDENTIFIER = '0400000014'
fs.readFile(FILE_PATH, (err, buffer) => {
if (buffer.indexOf(FILE_IDENTIFIER, 0, 'hex') !== 0) {
throw new Error('This is not a valid file');
}
let bufferChecker = '';
let hasName = false;
for (const [index, hex] of buffer.entries()) {
const hexString = hex.toString(16).toUpperCase().padStart(2, 0);
if (index < 5) {
continue;
}
if (hexString === '00' && bufferChecker === '') {
continue;
} else if (hexString === '00' && bufferChecker.endsWith('00')) {
const sequence = bufferChecker.substring(0, bufferChecker.length - 2);
console.log(Buffer.from(sequence, 'hex').toString('utf8'));
hasName = true;
bufferChecker = '';
continue;
}
bufferChecker += hexString;
if (hasName && bufferChecker.length === 64) {
console.log(bufferChecker);
const guid = convertHexToGuuid(bufferChecker.substr(0, 32));
console.log(guid);
hasName = false;
bufferChecker = '';
}
}
});
function convertHexToGuuid(hexString) {
let guuid = '';
guuid += hexString.substring(6, 8);
guuid += hexString.substring(4, 6);
guuid += hexString.substring(2, 4);
guuid += hexString.substring(0, 2);
guuid += '-'
guuid += hexString.substring(10, 12);
guuid += hexString.substring(8, 10);
guuid += '-';
guuid += hexString.substring(14, 16);
guuid += hexString.substring(12, 14);
guuid += '-';
guuid += hexString.substring(16, 20);
guuid += '-';
guuid += hexString.substring(20);
return guuid
}