From 6f2e382aeb59a80a04ccbe28d28be56a7f96bade Mon Sep 17 00:00:00 2001 From: GermanBluefox Date: Fri, 20 Sep 2024 23:00:30 +0800 Subject: [PATCH] chore: release v1.0.5 - (ChrisDietrich) Corrected the link in readme.md - (bluefox) Corrected the Big-Endian PCAP format --- README.md | 2 +- build/lib/recording.js | 90 ++++++++++++++++++++++++++---------------- build/main.js | 2 +- io-package.json | 28 ++++++------- package.json | 2 +- src-admin/package.json | 2 +- 6 files changed, 73 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 59916b6..ad17900 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Detect IP addresses from: --> ## Changelog -### **WORK IN PROGRESS** +### 1.0.5 (2024-09-20) - (ChrisDietrich) Corrected the link in readme.md - (bluefox) Corrected the Big-Endian PCAP format diff --git a/build/lib/recording.js b/build/lib/recording.js index 2dc98e2..b1de783 100644 --- a/build/lib/recording.js +++ b/build/lib/recording.js @@ -30,13 +30,11 @@ function analyzePacket(context) { if (len < headerLength) { return false; } + const seconds = context.libpCapFormat ? context.buffer.readUInt32BE(0) : context.buffer.readUInt32LE(0); + const microseconds = context.libpCapFormat ? context.buffer.readUInt32BE(4) : context.buffer.readUInt32LE(4); + const packageLen = context.libpCapFormat ? context.buffer.readUInt32BE(8) : context.buffer.readUInt32LE(8); + const packageLenSent = context.libpCapFormat ? context.buffer.readUInt32BE(12) : context.buffer.readUInt32LE(12); if (debug) { - const seconds = context.libpCapFormat ? context.buffer.readUInt32BE(0) : context.buffer.readUInt32LE(0); - const microseconds = context.libpCapFormat ? context.buffer.readUInt32BE(4) : context.buffer.readUInt32LE(4); - const packageLen = context.libpCapFormat ? context.buffer.readUInt32BE(8) : context.buffer.readUInt32LE(8); - const packageLenSent = context.libpCapFormat - ? context.buffer.readUInt32BE(12) - : context.buffer.readUInt32LE(12); let MAC1; let MAC2; if (context.networkType === 0x69) { @@ -49,12 +47,11 @@ function analyzePacket(context) { } console.log(`Packet: ${new Date(seconds * 1000 + Math.round(microseconds / 1000)).toISOString()} ${packageLen} ${packageLenSent} ${MAC1.toString('hex')} => ${MAC2.toString('hex')}`); } - const nextPackageLen = context.libpCapFormat ? context.buffer.readUInt32BE(8) : context.buffer.readUInt32LE(8); - if (nextPackageLen > 10000) { + if (packageLen > 10000) { // error of capturing - throw new Error(`Packet length is too big: ${nextPackageLen}`); + throw new Error(`Packet length is too big: ${packageLen}`); } - if (len < headerLength + nextPackageLen) { + if (len < headerLength + packageLen) { return false; } // next 6 bytes are MAC address of a source @@ -113,19 +110,41 @@ function analyzePacket(context) { // } } if (maxBytes) { - if (nextPackageLen < maxBytes) { - // remove from buffer nextPackageLen + 16 bytes - context.packets.push(context.buffer.subarray(0, headerLength + nextPackageLen)); - context.totalBytes += headerLength + nextPackageLen; + if (packageLen < maxBytes) { + // remove from buffer packageLen + 16 bytes + const packetBuffer = context.buffer.subarray(0, headerLength + packageLen); + if (context.libpCapFormat) { + // write header in LE notation + packetBuffer.writeUInt32LE(seconds, 0); + packetBuffer.writeUInt32LE(microseconds, 4); + packetBuffer.writeUInt32LE(packageLen, 8); + packetBuffer.writeUInt32LE(packageLenSent, 12); + const ifindex = packetBuffer.readUInt32BE(16); + const protocol = packetBuffer.readUInt16BE(20); + packetBuffer.writeUInt32LE(ifindex, 16); + packetBuffer.writeUInt16LE(protocol, 20); + } + context.packets.push(packetBuffer); + context.totalBytes += headerLength + packageLen; if (debug) { - console.log(`Saved packet: ${headerLength + nextPackageLen}`); + console.log(`Saved packet: ${headerLength + packageLen}`); } } else { - const packet = context.buffer.subarray(0, headerLength + maxBytes); + const packetBuffer = context.buffer.subarray(0, headerLength + maxBytes); + if (context.libpCapFormat) { + // write header in LE notation + packetBuffer.writeUInt32LE(seconds, 0); + packetBuffer.writeUInt32LE(microseconds, 4); + packetBuffer.writeUInt32LE(packageLenSent, 12); + const ifindex = packetBuffer.readUInt32BE(16); + const protocol = packetBuffer.readUInt16BE(20); + packetBuffer.writeUInt32LE(ifindex, 16); + packetBuffer.writeUInt16LE(protocol, 20); + } // save new length in the packet - packet.writeUInt32LE(maxBytes, 8); - context.packets.push(packet); + packetBuffer.writeUInt32LE(maxBytes, 8); + context.packets.push(packetBuffer); context.totalBytes += headerLength + maxBytes; if (debug) { console.log(`Saved packet: ${headerLength + maxBytes}`); @@ -134,7 +153,7 @@ function analyzePacket(context) { context.totalPackets++; } // remove this packet - context.buffer = context.buffer.subarray(headerLength + nextPackageLen); + context.buffer = context.buffer.subarray(headerLength + packageLen); return true; } async function stopAllRecordingsOnFritzBox(ip, sid) { @@ -211,27 +230,28 @@ function startRecordingOnFritzBox(ip, sid, iface, MACs, onEnd, context, progress const magic = context.buffer.readUInt32LE(0); context.modifiedMagic = magic === 0xa1b2cd34; context.libpCapFormat = magic === 0x34cdb2a1; + const versionMajor = context.libpCapFormat + ? context.buffer.readUInt16BE(4) + : context.buffer.readUInt16LE(4); + const versionMinor = context.libpCapFormat + ? context.buffer.readUInt16BE(4 + 2) + : context.buffer.readUInt16LE(4 + 2); + const reserved1 = context.libpCapFormat + ? context.buffer.readUInt32BE(4 * 2) + : context.buffer.readUInt32LE(4 * 2); + const reserved2 = context.libpCapFormat + ? context.buffer.readUInt32BE(4 * 3) + : context.buffer.readUInt32LE(4 * 3); + const snapLen = context.libpCapFormat + ? context.buffer.readUInt32BE(4 * 4) + : context.buffer.readUInt32LE(4 * 4); context.networkType = context.libpCapFormat ? context.buffer.readUInt32BE(4 * 5) : context.buffer.readUInt32LE(4 * 5); if (debug) { - const versionMajor = context.libpCapFormat - ? context.buffer.readUInt16BE(4) - : context.buffer.readUInt16LE(4); - const versionMinor = context.libpCapFormat - ? context.buffer.readUInt16BE(4 + 2) - : context.buffer.readUInt16LE(4 + 2); - const reserved1 = context.libpCapFormat - ? context.buffer.readUInt32BE(4 * 2) - : context.buffer.readUInt32LE(4 * 2); - const reserved2 = context.libpCapFormat - ? context.buffer.readUInt32BE(4 * 3) - : context.buffer.readUInt32LE(4 * 3); - const snapLen = context.libpCapFormat - ? context.buffer.readUInt32BE(4 * 4) - : context.buffer.readUInt32LE(4 * 4); - console.log(`PCAP: ${magic.toString(16)} ${versionMajor}.${versionMinor} res1=${reserved1} res2=${reserved2} snaplen=${snapLen} ${context.networkType.toString(16)}`); + console.log(`PCAP: ${magic.toString(16)} v${versionMajor}.${versionMinor} res1=${reserved1} res2=${reserved2} snaplen=${snapLen} network=${context.networkType.toString(16)}`); } + // remove header context.buffer = context.buffer.subarray(6 * 4); } else { diff --git a/build/main.js b/build/main.js index 1c7af19..b517fcb 100644 --- a/build/main.js +++ b/build/main.js @@ -540,7 +540,7 @@ class KISSHomeResearchAdapter extends utils.Adapter { // create PCAP header const byteArray = Buffer.alloc(6 * 4); // magic number - byteArray.writeUInt32LE(this.context.modifiedMagic ? MODIFIED_MAGIC : STANDARD_MAGIC, 0); + byteArray.writeUInt32LE(this.context.modifiedMagic || this.context.libpCapFormat ? MODIFIED_MAGIC : STANDARD_MAGIC, 0); // major version byteArray.writeUInt16LE(2, 4); // minor version diff --git a/io-package.json b/io-package.json index 4ee90ec..3c258f4 100644 --- a/io-package.json +++ b/io-package.json @@ -1,8 +1,21 @@ { "common": { "name": "kisshome-research", - "version": "1.0.4", + "version": "1.0.5", "news": { + "1.0.5": { + "en": "Corrected the link in readme.md\nCorrected the Big-Endian PCAP format", + "de": "Korrigierte den Link im Readme. md\nKorrektur des Big-Endian PCAP Format", + "ru": "Исправлена ссылка в считывании. md\nИсправлены Большой индейец Формат PCAP", + "pt": "Corrigido o link no readme. Md\nCorrigido o Big-Endian Formato PCAP", + "nl": "De link in readme gecorrigeerd. md\nGecorrigeerd de Big-Endian PCAP-formaat", + "fr": "Corrigé le lien dans readme. md\nCorrigé le Big-Endian Format PAC", + "it": "Corretto il link in readme. M\nCorretto il Big-Endian Formato PCAP", + "es": "Corregido el enlace en readme. md\nCorregido el Gran Endian Formato PCAP", + "pl": "Naprawiłem link. md\nPoprawiono Wielkiego Endianina Format PCAP", + "uk": "Виправлено посилання в чителю. мд\nВиправлено великий Формат ПКАП", + "zh-cn": "更正了readme中的链接. 微额\n纠正了大印地安人 PCAP 格式" + }, "1.0.4": { "en": "Corrected GUI\nFilter out not used interfaces\nAdded notification to admin if public key not accepted\nTry to detect zero bytes interfaces", "de": "Korrigierte GUI\nFiltern nicht genutzte Schnittstellen\nHinzugefügt Benachrichtigung zu Admin, wenn der öffentliche Schlüssel nicht akzeptiert\nVersuchen Sie, Null Bytes-Schnittstellen zu erkennen", @@ -80,19 +93,6 @@ "pl": "Dodano wykrywanie niektórych IP", "uk": "Додано виявлення деяких IP-адрес", "zh-cn": "添加检测一些IP" - }, - "0.2.1": { - "en": "used valid URL address", - "de": "verwendete gültige URL-Adresse", - "ru": "использованный адрес", - "pt": "endereço URL válido usado", - "nl": "gebruikt geldig URL-adres", - "fr": "adresse URL valide utilisée", - "it": "indirizzo URL valido", - "es": "dirección URL válida", - "pl": "używany poprawny adres URL", - "uk": "використовується вірна адреса URL", - "zh-cn": "使用有效的 URL 地址" } }, "titleLang": { diff --git a/package.json b/package.json index 0c1d345..ac15b15 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iobroker.kisshome-research", - "version": "1.0.4", + "version": "1.0.5", "description": "Collection of information for KISSHome research", "author": { "name": "Denis Haev", diff --git a/src-admin/package.json b/src-admin/package.json index 7d96038..c267403 100644 --- a/src-admin/package.json +++ b/src-admin/package.json @@ -1,7 +1,7 @@ { "name": "iobroker-admin-component-telegram", "private": true, - "version": "1.0.4", + "version": "1.0.5", "scripts": { "start": "set PORT=4173 && craco start", "build": "craco build"