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 {
// Print all packet lines to see what we're getting
print('📋 RAW PACKET LINE: $packetLine');
// 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'));
}
// Check if it's from our monitored peers first
bool isFromPeer = false;
String? 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)) {
isFromPeer = true;
peerIP = ip;
_currentPeerIP = ip;
print('🎯 NEW PACKET FROM PEER $ip');
break;
}
}
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);
}
// 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<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 {