Skip to content

Conversation

@dumitory-dev
Copy link

@dumitory-dev dumitory-dev commented Nov 14, 2025

This PR fixes an issue in the HID short item generator where the size field (bSize) was derived directly from the number of data bytes. According to the HID specification, the size bits do not represent the literal number of bytes, but instead use a 2-bit code:

  • 00 → 0 bytes
  • 01 → 1 byte
  • 10 → 2 bytes
  • 11 → 4 bytes

The previous implementation incorrectly used len(octets) as the value for these bits, resulting in malformed descriptors (for example, a 4-byte item still produced bSize = 0).

Small example:

from facedancer.classes.hid.usage import *
from facedancer.classes.hid.descriptor import *
from facedancer.classes.hid.keyboard import *
from facedancer.classes.hid.descriptor import _hid_item_generator


REPORT_SIZE        = _hid_item_generator(0b0111_01_00)
reports = REPORT_SIZE(0xFF,0xFF,0xFF,0xFF)
print(f'reports (bin): {bin(reports[0])}') # Will "0b1110100", but must be "0b1110111"
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants