-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExeToBin.js
More file actions
101 lines (83 loc) · 3.29 KB
/
Copy pathExeToBin.js
File metadata and controls
101 lines (83 loc) · 3.29 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
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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const args = process.argv.slice(2);
const InputFile = args.find(arg => !arg.startsWith('-')) || process.argv.find(arg => arg.includes('.exe'));
const OutputFormat = args.includes('-Hex') ? 'Hex' : args.includes('-Both') ? 'Both' : 'Base64';
const OutputFile = args.includes('-OutputFile') ? args[args.indexOf('-OutputFile') + 1] : null;
const colors = {
green: '\x1b[32m',
red: '\x1b[31m',
cyan: '\x1b[36m',
gray: '\x1b[90m',
reset: '\x1b[0m'
};
function colorLog(message, color) {
console.log(`${colors[color]}${message}${colors.reset}`);
}
if (!InputFile) {
colorLog('[ERROR] Usage: node ExeToBin.js <inputfile.exe> [-Base64|-Hex|-Both] [-OutputFile <path>]', 'red');
process.exit(1);
}
if (!fs.existsSync(InputFile)) {
colorLog(`[ERROR] File not found: ${InputFile}`, 'red');
process.exit(1);
}
const fileInfo = fs.statSync(InputFile);
const fileSizeKB = (fileInfo.size / 1024).toFixed(2);
colorLog(`[INFO] Processing: ${path.basename(InputFile)}`, 'cyan');
colorLog(`[INFO] File size: ${fileSizeKB} KB`, 'cyan');
const fileBytes = fs.readFileSync(InputFile);
switch (OutputFormat) {
case 'Base64': {
const encoded = fileBytes.toString('base64');
colorLog('[SUCCESS] Base64 conversion complete', 'green');
if (OutputFile) {
fs.writeFileSync(OutputFile, encoded, 'utf8');
colorLog(`[SAVED] Output: ${OutputFile}`, 'green');
} else {
colorLog('[OUTPUT] Base64 String:', 'cyan');
colorLog('-'.repeat(60), 'gray');
console.log(encoded);
colorLog('-'.repeat(60), 'gray');
colorLog(`[INFO] Total characters: ${encoded.length}`, 'cyan');
}
break;
}
case 'Hex': {
const hexString = fileBytes.toString('hex').match(/.{1,2}/g).join(' ');
colorLog('[SUCCESS] Hex conversion complete', 'green');
if (OutputFile) {
fs.writeFileSync(OutputFile, hexString, 'utf8');
colorLog(`[SAVED] Output: ${OutputFile}`, 'green');
} else {
colorLog('[OUTPUT] Hex String:', 'cyan');
colorLog('-'.repeat(60), 'gray');
console.log(hexString);
colorLog('-'.repeat(60), 'gray');
colorLog(`[INFO] Total characters: ${hexString.length}`, 'cyan');
}
break;
}
case 'Both': {
const base64 = fileBytes.toString('base64');
const hexString = fileBytes.toString('hex').match(/.{1,2}/g).join(' ');
colorLog('[SUCCESS] Both conversions complete', 'green');
colorLog('[OUTPUT] Base64 String:', 'cyan');
colorLog('-'.repeat(60), 'gray');
console.log(base64);
colorLog('-'.repeat(60), 'gray');
console.log();
colorLog('[OUTPUT] Hex String:', 'cyan');
colorLog('-'.repeat(60), 'gray');
console.log(hexString);
colorLog('-'.repeat(60), 'gray');
if (OutputFile) {
const combined = `=== BASE64 OUTPUT ===\n${base64}\n\n=== HEX OUTPUT ===\n${hexString}`;
fs.writeFileSync(OutputFile, combined, 'utf8');
colorLog(`[SAVED] Output: ${OutputFile}`, 'green');
}
break;
}
}
colorLog('\n[COMPLETE] Conversion finished successfully!', 'green');