summaryrefslogtreecommitdiff
path: root/www/js/webrdp-ext.js
blob: 9a96b23c321b94cc0b0ca79ba65fb43e21176fee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/** BSD-2-Clause license
 *
 * Copyright (c) 2018-2023 NST <www.newinfosec.ru>, smake <smake at ya dot ru>.
 *
 */

ArrayBuffer.prototype.toHexdump = function () {
	return new Uint8Array(this).reduce(
		(p, c, i, a) => p + (
			i % 16 === 0 ? i.toString(16).padStart(6, 0) + '  ' : ' '
		) + c.toString(16).padStart(2, 0) + (
			i === a.length - 1 || i % 16 === 15 ?
			' '.repeat((15 - i % 16) * 3) + Array.from(a).splice(i - i % 16, 16).reduce((r, v) => r + (
				v > 31 && v < 127 || v > 159 ? String.fromCharCode(v) : '.'
			), '  ') + '\n' : ''
		), ''
	);

}