Show ASCII translation for each hex line

This commit is contained in:
ImBenji
2025-08-29 16:22:26 +01:00
parent fd75a36381
commit e28a66a9f8

View File

@@ -166,9 +166,25 @@ class ProtocolBlockingService {
// If this is hex data and we're tracking a peer packet // If this is hex data and we're tracking a peer packet
else if (packetLine.contains('0x') && _currentPeerIP != null) { else if (packetLine.contains('0x') && _currentPeerIP != null) {
_currentPacketHex.add(packetLine); _currentPacketHex.add(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'); print('📦 HEX LINE: $packetLine');
} }
} }
}
static Future<void> _analyzeAccumulatedHex(String peerIP, String hexData) async { static Future<void> _analyzeAccumulatedHex(String peerIP, String hexData) async {
print('🔍 ANALYZING COMPLETE PACKET FROM $peerIP'); print('🔍 ANALYZING COMPLETE PACKET FROM $peerIP');