From 074b132703c5e2fc0743795b77747f9609e3ade2 Mon Sep 17 00:00:00 2001 From: MultiMote <contact@mmote.ru> Date: Wed, 15 Jan 2025 22:42:19 +0300 Subject: [PATCH] Fix packet parser utility scrips --- utils/parse-text-dump.mjs | 6 +++--- utils/parse-wireshark-dump.mjs | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/parse-text-dump.mjs b/utils/parse-text-dump.mjs index bc163a0..cbfb980 100644 --- a/utils/parse-text-dump.mjs +++ b/utils/parse-text-dump.mjs @@ -1,4 +1,4 @@ -import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId } from "../dist/index.js"; +import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId, PacketParser } from "../dist/index.js"; import fs from "fs"; // usage: yarn parse-text-dump <path> [data | min | min-out | print-task] @@ -29,8 +29,8 @@ for (const line of lines) { let comment = ""; try { - const data = Utils.hexToBuf(hexData); - const packets = NiimbotPacket.fromBytesMultiPacket(data); + const data = Utils.hexToBuf(hexData.startsWith("03") ? hexData.substring(2) : hexData); + const packets = PacketParser.parsePacketBundle(data); if (packets.length === 0) { comment = "Parse error (no packets found)"; diff --git a/utils/parse-wireshark-dump.mjs b/utils/parse-wireshark-dump.mjs index 9b17f4c..dc6b4d4 100644 --- a/utils/parse-wireshark-dump.mjs +++ b/utils/parse-wireshark-dump.mjs @@ -1,4 +1,4 @@ -import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId } from "../dist/index.js"; +import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId, PacketParser } from "../dist/index.js"; import { spawn } from "child_process"; const TSHARK_PATH = "C:\\Program Files\\Wireshark\\tshark.exe"; @@ -54,8 +54,8 @@ spawned.on("close", (code) => { let comment = ""; try { - const data = Utils.hexToBuf(hexData); - const packets = NiimbotPacket.fromBytesMultiPacket(data); + const data = Utils.hexToBuf(hexData.startsWith("03") ? hexData.substring(2) : hexData); + const packets = PacketParser.parsePacketBundle(data); if (packets.length === 0) { comment = "Parse error (no packets found)"; @@ -79,7 +79,7 @@ spawned.on("close", (code) => { } else { comment += ResponseCommandId[packet.command] ?? "???"; } - + if (display === "data") { comment += `(${packet.dataLength}: ${Utils.bufToHex(packet.data)}); `; } else {