From 5a9e2b501fd730981b7db8728d5ede71f7cf0224 Mon Sep 17 00:00:00 2001 From: ImBenji Date: Fri, 29 Aug 2025 15:48:39 +0100 Subject: [PATCH] Enhance packet processing to accumulate and analyze hex data from monitored peers --- lib/services/protocol_blocking_service.dart | 50 ++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/lib/services/protocol_blocking_service.dart b/lib/services/protocol_blocking_service.dart index 7bad745..55d76c8 100644 --- a/lib/services/protocol_blocking_service.dart +++ b/lib/services/protocol_blocking_service.dart @@ -139,33 +139,43 @@ class ProtocolBlockingService { } } + static String? _currentPeerIP; + static final List _currentPacketHex = []; + static Future _processCapturedPacket(String packetLine) async { - // Print all packet lines to see what we're getting - print('📋 RAW PACKET LINE: $packetLine'); - - // Check if it's from our monitored peers first - bool isFromPeer = false; - String? peerIP; - - for (final ip in _activePeerIPs) { - if (packetLine.contains(ip)) { - isFromPeer = true; - peerIP = ip; - break; + // Check if this is a new packet header (timestamp line) + if (packetLine.contains('IP ') && !packetLine.contains('0x')) { + // If we have accumulated hex data from previous packet, analyze it + if (_currentPeerIP != null && _currentPacketHex.isNotEmpty) { + await _analyzeAccumulatedHex(_currentPeerIP!, _currentPacketHex.join('\n')); } - } - - if (isFromPeer && peerIP != null) { - print('🎯 PEER TRAFFIC FROM $peerIP'); - // For hex data lines, do deep payload analysis - if (packetLine.contains('0x')) { - print('🔍 HEX DATA DETECTED - ANALYZING PAYLOAD'); - await _analyzeFullPayload(packetLine, peerIP); + // Reset for new packet + _currentPacketHex.clear(); + _currentPeerIP = null; + + // Check if new packet is from our monitored peers + for (final ip in _activePeerIPs) { + if (packetLine.contains(ip)) { + _currentPeerIP = ip; + print('🎯 NEW PACKET FROM PEER $ip'); + break; + } } + } + // If this is hex data and we're tracking a peer packet + else if (packetLine.contains('0x') && _currentPeerIP != null) { + _currentPacketHex.add(packetLine); + print('📦 Collecting hex data for ${_currentPeerIP}: ${_currentPacketHex.length} lines'); } } + static Future _analyzeAccumulatedHex(String peerIP, String hexData) async { + print('🔍 ANALYZING COMPLETE PACKET FROM $peerIP'); + print('📊 Hex data lines: ${_currentPacketHex.length}'); + await _analyzeFullPayload(hexData, peerIP); + } + static Future _analyzeFullPayload(String hexPacketLine, String peerIP) async { print('🔍 DEEP PAYLOAD ANALYSIS for peer $peerIP');