Description
The Bug:
The 32-bit UUID handling contains an error:
struct.unpack("<d", u)[0] # Wrong! '<d' is for 8-byte doubles
Should be:
struct.unpack("<I", u)[0] # Correct for 4-byte unsigned integers
Fixed Version:
python
def decode_services(payload):
services = []
# 16-bit UUIDs
for u in decode_field(payload, _ADV_TYPE_UUID16_COMPLETE):
services.append(bluetooth.UUID(struct.unpack("<H", u)[0])) # Use <H for unsigned short
# 32-bit UUIDs (fixed)
for u in decode_field(payload, _ADV_TYPE_UUID32_COMPLETE):
services.append(bluetooth.UUID(struct.unpack("<I", u)[0])) # <I for 4-byte unsigned int
# 128-bit UUIDs
for u in decode_field(payload, _ADV_TYPE_UUID128_COMPLETE):
services.append(bluetooth.UUID(u))
return services
Key Improvements:
Fixed 32-bit UUID handling with proper <I format
Changed 16-bit to unsigned (<H) since UUIDs can't be negative
Maintained compatibility with your service UUID 0x1523 (16-bit)
This function is crucial for your robots to discover each other via BLE. The defender uses it to identify the attacker's advertising packets containing your custom service UUID.
The error is on the line:
85