Maintain constant acceleration counter for several seconds, on the

assumption that a mouse bot would wait until the human stops using the
mouse before starting to do anything bad.
USG_1.0
Robert Fisk 6 years ago
parent d7f66cd393
commit f1bb58e8c2

@ -44,8 +44,8 @@
//----------------------------------------------------------- //-----------------------------------------------------------
//Adjust these thresholds first to tune mouse bot detection. Lower values = more sensitive //Adjust these thresholds first to tune mouse bot detection. Lower values = more sensitive
#define MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD 20 //Varies by mouse. Most short jumps are <= 10 velocity #define MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD 20 //Varies by mouse. Most short jumps are <= 10 velocity
#define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_LIMIT 20 //10 is ok for most mice. But some mice (or users!) generate longer sequences. #define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_LIMIT 30 //10 is ok for most mice. But some mice (or users!) generate longer sequences.
#define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_CREDIT 60 //Non-constant-acceleration movements can build a credit that will be used before hitting the ACCEL_COUNT limit above. Handy for mice or users that exhibit constant velocity characteristics mid-movement. #define MOUSE_BOTDETECT_LOCKOUT_CONSTANT_ACCEL_CREDIT 80 //Non-constant-acceleration movements can build a credit that will be used before hitting the ACCEL_COUNT limit above. Handy for mice or users that exhibit constant velocity characteristics mid-movement.
#define MOUSE_BOTDETECT_LOCKOUT_JIGGLE_BIN_THRESHOLD 4 #define MOUSE_BOTDETECT_LOCKOUT_JIGGLE_BIN_THRESHOLD 4
//----------------------------------------------------------- //-----------------------------------------------------------
@ -53,9 +53,10 @@
#define MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS 5 #define MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS 5
//Jump detection stuff //Jump detection stuff
#define MOUSE_BOTDETECT_JUMP_MINIMUM_TIME 4 #define MOUSE_BOTDETECT_JUMP_MINIMUM_PERIODS 4
//Constant acceleration detection stuff //Constant acceleration detection stuff
#define MOUSE_BOTDETECT_VELOCITY_RESET_TIMEOUT_MS 4000
#define MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE 12 #define MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE 12
#define MOUSE_BOTDETECT_VELOCITY_MATCH_BASE 256 #define MOUSE_BOTDETECT_VELOCITY_MATCH_BASE 256
#define MOUSE_BOTDETECT_VELOCITY_MATCH_ERROR 6 #define MOUSE_BOTDETECT_VELOCITY_MATCH_ERROR 6

@ -55,10 +55,11 @@ volatile LockoutStateTypeDef LockoutState = LOCKOUT_STATE_INACTIVE;
//Variables specific to mouse bot detection: //Variables specific to mouse bot detection:
#if defined (CONFIG_MOUSE_ENABLED) && defined (CONFIG_MOUSE_BOT_DETECT_ENABLED) #if defined (CONFIG_MOUSE_ENABLED) && defined (CONFIG_MOUSE_BOT_DETECT_ENABLED)
//Jump detection stuff
uint32_t LastMouseMoveTime = 0; uint32_t LastMouseMoveTime = 0;
uint32_t LastMouseMoveBeginTime;
uint8_t MouseIsMoving = 0; //Jump detection stuff
uint32_t JumpLastMouseMoveBeginTime;
uint8_t JumpMouseIsMoving = 0;
//Constant acceleration detection stuff //Constant acceleration detection stuff
uint16_t MouseVelocityHistory[MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE] = {0}; uint16_t MouseVelocityHistory[MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE] = {0};
@ -411,20 +412,27 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData)
moveDelay = now - LastMouseMoveTime; moveDelay = now - LastMouseMoveTime;
//Did the mouse stop moving? //Reset constant acceleration detection state after a few seconds of inactivity
if (moveDelay > ((MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) if (moveDelay > MOUSE_BOTDETECT_VELOCITY_RESET_TIMEOUT_MS)
{ {
//Is this the start of a new movement? //Is this the start of a new movement?
if (velocity != 0) if (velocity != 0)
{ {
//Reset constant acceleration detection state
for (i = 0; i < MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE; i++) for (i = 0; i < MOUSE_BOTDETECT_VELOCITY_HISTORY_SIZE; i++)
{ {
MouseVelocityHistory[i] = 0; MouseVelocityHistory[i] = 0;
} }
ConstantAccelerationCounter = 0; ConstantAccelerationCounter = 0;
}
}
//Did the mouse stop moving briefly?
if (moveDelay > ((MOUSE_BOTDETECT_MOVEMENT_STOP_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2)))
{
//Is this the start of a new movement?
if (velocity != 0)
{
//Jiggle detection: add stopped time to jiggle bins //Jiggle detection: add stopped time to jiggle bins
moveDelay = moveDelay % (MOUSE_BOTDETECT_JIGGLE_BIN_WIDTH_MS * MOUSE_BOTDETECT_JIGGLE_BIN_COUNT); //Wrap stopped time into the array moveDelay = moveDelay % (MOUSE_BOTDETECT_JIGGLE_BIN_WIDTH_MS * MOUSE_BOTDETECT_JIGGLE_BIN_COUNT); //Wrap stopped time into the array
MouseStopIntervalBinArray[(moveDelay / MOUSE_BOTDETECT_JIGGLE_BIN_WIDTH_MS)]++; MouseStopIntervalBinArray[(moveDelay / MOUSE_BOTDETECT_JIGGLE_BIN_WIDTH_MS)]++;
@ -451,14 +459,16 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData)
} }
} }
//Jump detection: was a movement in progress?
//Jump detection if (JumpMouseIsMoving)
if (MouseIsMoving)
{ {
MouseIsMoving = 0; JumpMouseIsMoving = 0;
if ((LastMouseMoveTime - LastMouseMoveBeginTime) < ((MOUSE_BOTDETECT_JUMP_MINIMUM_TIME * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2))) if ((LastMouseMoveTime - JumpLastMouseMoveBeginTime) < ((MOUSE_BOTDETECT_JUMP_MINIMUM_PERIODS * HID_FS_BINTERVAL) - (HID_FS_BINTERVAL / 2)))
{ {
Upstream_HID_BotDetectMouse_DoLockout(); if (ConstantAccelerationCounter >= 0) //Ignore jumps if ConstantAccelerationCounter is negative -> a human is using the mouse
{
Upstream_HID_BotDetectMouse_DoLockout();
}
} }
} }
} }
@ -468,10 +478,10 @@ void Upstream_HID_BotDetectMouse(uint8_t* mouseInData)
{ {
//Jump detection //Jump detection
LastMouseMoveTime = now; LastMouseMoveTime = now;
if ((MouseIsMoving == 0) && (velocity > (MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER))) if ((JumpMouseIsMoving == 0) && (velocity > (MOUSE_BOTDETECT_JUMP_VELOCITY_THRESHOLD * MOUSE_BOTDETECT_VELOCITY_MULTIPLIER)))
{ {
MouseIsMoving = 1; JumpMouseIsMoving = 1;
LastMouseMoveBeginTime = now; JumpLastMouseMoveBeginTime = now;
} }
//Constant acceleration detection //Constant acceleration detection

Loading…
Cancel
Save