-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (60 loc) · 1.35 KB
/
index.js
File metadata and controls
67 lines (60 loc) · 1.35 KB
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
/*jslint node: true */
'use strict';
let os = require('os'),
shelljs = require('shelljs');
let fs = require('node:fs');
/* let argv = require('yargs')(process.argv.slice(2))
.option('f', {
alias: 'file',
demandOption: true,
describe: 'file to test',
type: 'string'
})
.argv;
*/
module.exports = { binaryBit,
is64bits,
is32bits }
/*
Windows Get Adrress pointed at 0x3c~0x3d
Signatures:
50 45 20 20 4c = 32 bits
50 45 20 20 64 86 = 64 bits
In this program we test only the 5th byte after the address pointed at 0x3c~0x3d to test
if it is 76 decimal (0x4c hex) it is 32 bits
if it is 100 decimal (0x64 hex) it is 64 bits
*/
function binaryBit(binFile) {
if (os.platform() != "win32") {
console.log(shelljs.exec('file ' + binFile));
}
else {
var binData;
try {
binData = fs.readFileSync(binFile);
}
catch {
throw new Error ("Error reading file " + binFile);
}
//console.log(binData.buffer);
if (binData.length > 62) {
var num = (binData[61] * 255) + binData[60];
if (binData.length > (num+5)) {
if (binData[num+5] == 76) {
return "32";
}
if (binData[num+5] == 100){
return "64";
}
}
}
}
return "unknown";
}
function is64bits(binFile) {
return binaryBit(binFile) == "64";
}
function is32bits(binFile) {
return binaryBit(binFile) == "32";
}
//is64(argv.file);