Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 4x 4x 2x 2x 2x 2x 1x 1x 1x 1x 1x 57x 57x 57x 1x 8x 8x 8x 1x 1x 1x 1x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 1x 1x 1x 1x 1x 1x 1x 9x 9x 9x 11x 11x 11x 11x 11x 11x 8x 8x 8x 18x 18x 18x 18x 18x 18x 18x 18x 8x 11x 11x 11x 9x 9x 1x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 13x 13x 13x 1x 1x 12x 12x 12x 13x 13x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 1x 1x | "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Network = exports.Command = exports.Argument = exports.isIPv6Enabled = void 0;
const os_1 = require("os");
function isIPv6Enabled() {
const interfaces = (0, os_1.networkInterfaces)();
// console.log('interfaces', interfaces);
for (const [, ifaces] of Object.entries(interfaces)) {
// console.log('name', name);
if (ifaces === undefined) {
continue;
}
const found = ifaces.find((iface) => {
// console.log('iface', iface.address, iface.family);
return iface.address[0] == '2' && iface.family === 'IPv6';
});
// console.log('found', found);
if (found !== undefined) {
return true;
}
}
return false;
}
exports.isIPv6Enabled = isIPv6Enabled;
class Argument {
constructor(value, length) {
this.value = value;
this.length = length;
}
asInt() {
if (this.value.length < 4) {
const buf = Buffer.alloc(4);
this.value.copy(buf, 0, 0, this.value.length);
return buf.readUInt32LE();
}
return this.value.readUInt32LE();
}
asString() {
return this.value.toString('binary');
}
}
exports.Argument = Argument;
class Command {
constructor(group = 0, command = 0, data = []) {
this.group = group;
this.command = command;
this.args = [];
this.args = data.map((item) => {
switch (typeof item) {
case 'number':
const buf = Buffer.alloc(4);
buf.writeUInt32LE(item);
return new Argument(buf, 4);
case 'string':
return new Argument(Buffer.from(item), item.length);
default:
return new Argument(item, item.length);
}
});
}
asInt(index) {
const arg = this.args[index];
if (arg === undefined) {
throw new Error(`Argument ${index} is undefined`);
}
return arg.asInt();
}
asBytes(index) {
const arg = this.args[index];
if (arg === undefined) {
throw new Error(`Argument ${index} is undefined`);
}
return arg.value;
}
asString(index) {
const arg = this.args[index];
if (arg === undefined) {
throw new Error(`Argument ${index} is undefined`);
}
return arg.asString();
}
}
exports.Command = Command;
class Network {
_parseRaw(data) {
const commands = [];
let pos = 0;
while (pos < data.length) {
const flags_i = data[pos];
const flagLengthsAreFourBytes = (flags_i & 0x01) === 0x01;
const argSizeLen = flagLengthsAreFourBytes ? 4 : 1;
const payloadLen_i = data.subarray(pos + 3, pos + 7).readUInt32LE();
const command = new Command(data[pos + 1], data[pos + 2]);
if (payloadLen_i > 0) {
const payload_b = data.subarray(pos + 7, pos + 7 + payloadLen_i);
let payloadPos = 0;
while (payloadPos < payloadLen_i) {
const argLen_b = payload_b.subarray(payloadPos, payloadPos + argSizeLen);
const argLen_i = flagLengthsAreFourBytes ? argLen_b.readUInt32LE() : argLen_b.readUInt8();
const argVal = payload_b.subarray(payloadPos + argSizeLen, payloadPos + argSizeLen + argLen_i);
if (argVal.length !== argLen_i) {
throw new Error(`Argument length mismatch: ${argLen_i} != ${argVal.length}`);
}
payloadPos += argLen_i + argSizeLen;
const arg = new Argument(argVal, argLen_i);
command.args.push(arg);
}
}
commands.push(command);
pos += 1 + 1 + 1 + 4 + payloadLen_i + 1;
}
return commands;
}
_serializeCommand(command) {
// Flags
const flagLengthsAreFourBytes = command
.args
.map((item) => item.length)
.find((l) => l > 0xff) !== undefined;
const flags_i = 0x00 | (flagLengthsAreFourBytes ? 0x01 : 0x00);
const flags_b = Buffer.alloc(1);
flags_b.writeUInt8(flags_i);
const argSizeLen = flagLengthsAreFourBytes ? 4 : 1;
// Group
const group_b = Buffer.alloc(1);
group_b.writeUInt8(command.group);
// Command
const command_b = Buffer.alloc(1);
command_b.writeUInt8(command.command);
// Payload
let payloadLen_i = 0;
let payload = Buffer.alloc(0);
for (const arg of command.args) {
payloadLen_i += argSizeLen + arg.length;
const argLen_b = Buffer.alloc(argSizeLen);
if (flagLengthsAreFourBytes) {
argLen_b.writeUInt32LE(arg.length);
}
else {
argLen_b.writeUInt8(arg.length);
}
payload = Buffer.concat([payload, argLen_b, arg.value]);
}
const payloadLen_b = Buffer.alloc(4);
payloadLen_b.writeUInt32LE(payloadLen_i);
// End
const delemiter_b = Buffer.alloc(1);
delemiter_b.writeUInt8(0);
return Buffer.concat([
flags_b,
group_b, command_b,
payloadLen_b, payload,
delemiter_b,
]);
}
}
exports.Network = Network;
|