-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
40 lines (31 loc) · 1.18 KB
/
utils.js
File metadata and controls
40 lines (31 loc) · 1.18 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
const config = require('./config');
function hexDump(data, prefix = '') {
if (!config.DEBUG_PACKETS) return;
if (!data || data.length === 0) return;
const width = 16;
let lines = [];
// Красивый заголовок
console.log(`\x1b[36m${prefix}\x1b[0m (Len: ${data.length})`);
for (let i = 0; i < data.length; i += width) {
const chunk = data.subarray(i, i + width);
// Hex часть
const hex = [];
for (let j = 0; j < width; j++) {
if (j < chunk.length) {
hex.push(chunk[j].toString(16).padStart(2, '0').toUpperCase());
} else {
hex.push(' ');
}
}
// ASCII часть
let ascii = '';
for (const byte of chunk) {
// Печатные символы
ascii += (byte >= 32 && byte <= 126) ? String.fromCharCode(byte) : '.';
}
lines.push(` ${i.toString(16).padStart(4, '0')} ${hex.join(' ')} |${ascii}|`);
}
console.log(lines.join('\n'));
console.log('\x1b[90m' + '-'.repeat(60) + '\x1b[0m');
}
module.exports = { hexDump };