From e28a66a9f858f151b4a467a3d3b3a56e61c41fed Mon Sep 17 00:00:00 2001 From: ImBenji Date: Fri, 29 Aug 2025 16:22:26 +0100 Subject: [PATCH] Show ASCII translation for each hex line --- lib/services/protocol_blocking_service.dart | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/services/protocol_blocking_service.dart b/lib/services/protocol_blocking_service.dart index d0ec02e..7e50753 100644 --- a/lib/services/protocol_blocking_service.dart +++ b/lib/services/protocol_blocking_service.dart @@ -166,7 +166,23 @@ class ProtocolBlockingService { // If this is hex data and we're tracking a peer packet else if (packetLine.contains('0x') && _currentPeerIP != null) { _currentPacketHex.add(packetLine); - print('📦 HEX LINE: $packetLine'); + + // Extract and show ASCII for this hex line + final hexPattern = RegExp(r'0x[0-9a-f]+:\s*([0-9a-f\s]+)', caseSensitive: false); + final match = hexPattern.firstMatch(packetLine); + if (match != null) { + final hexData = match.group(1)?.replaceAll(' ', '') ?? ''; + String ascii = ''; + for (int i = 0; i < hexData.length; i += 2) { + if (i + 1 < hexData.length) { + final byte = int.tryParse(hexData.substring(i, i + 2), radix: 16) ?? 0; + ascii += (byte >= 32 && byte <= 126) ? String.fromCharCode(byte) : '.'; + } + } + print('📦 HEX LINE: $packetLine | ASCII: $ascii'); + } else { + print('📦 HEX LINE: $packetLine'); + } } }