Enhance packet processing to accumulate and analyze hex data from monitored peers

This commit is contained in:
ImBenji
2025-08-29 15:48:39 +01:00
parent 0731045bdd
commit 5a9e2b501f

View File

@@ -139,31 +139,41 @@ class ProtocolBlockingService {
} }
} }
static String? _currentPeerIP;
static final List<String> _currentPacketHex = [];
static Future<void> _processCapturedPacket(String packetLine) async { static Future<void> _processCapturedPacket(String packetLine) async {
// Print all packet lines to see what we're getting // Check if this is a new packet header (timestamp line)
print('📋 RAW PACKET LINE: $packetLine'); 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'));
}
// Check if it's from our monitored peers first // Reset for new packet
bool isFromPeer = false; _currentPacketHex.clear();
String? peerIP; _currentPeerIP = null;
// Check if new packet is from our monitored peers
for (final ip in _activePeerIPs) { for (final ip in _activePeerIPs) {
if (packetLine.contains(ip)) { if (packetLine.contains(ip)) {
isFromPeer = true; _currentPeerIP = ip;
peerIP = ip; print('🎯 NEW PACKET FROM PEER $ip');
break; break;
} }
} }
}
if (isFromPeer && peerIP != null) { // If this is hex data and we're tracking a peer packet
print('🎯 PEER TRAFFIC FROM $peerIP'); else if (packetLine.contains('0x') && _currentPeerIP != null) {
_currentPacketHex.add(packetLine);
// For hex data lines, do deep payload analysis print('📦 Collecting hex data for ${_currentPeerIP}: ${_currentPacketHex.length} lines');
if (packetLine.contains('0x')) {
print('🔍 HEX DATA DETECTED - ANALYZING PAYLOAD');
await _analyzeFullPayload(packetLine, peerIP);
} }
} }
static Future<void> _analyzeAccumulatedHex(String peerIP, String hexData) async {
print('🔍 ANALYZING COMPLETE PACKET FROM $peerIP');
print('📊 Hex data lines: ${_currentPacketHex.length}');
await _analyzeFullPayload(hexData, peerIP);
} }
static Future<void> _analyzeFullPayload(String hexPacketLine, String peerIP) async { static Future<void> _analyzeFullPayload(String hexPacketLine, String peerIP) async {