Windows VEH - 捕获并丢弃 SINGLE_STEP 异常

Windows VEH - catch and discard a SINGLE_STEP exception

在我通过 DLL 注入修改的第 3 方应用程序中,有一段代码毫无意义地抛出了 EXCEPTION_SINGLE_STEP 异常。我希望捕获该异常并将其完全丢弃。但是,Windows 一直在重新抛出它,因此我的异常处理程序陷入了无限循环。

我目前的代码:

LONG WINAPI VEH_Handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
    printf("Got an exception %X at address %X\n", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);

    if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP)
    {
        return EXCEPTION_CONTINUE_EXECUTION;
    }

    return EXCEPTION_CONTINUE_SEARCH;
}

//...

//in DllMain
AddVectoredExceptionHandler(1, VEH_Handler);

有没有办法让我强制Windows忘记异常并继续执行?

尝试将 EIP 移动到下一条指令:

LONG WINAPI VEH_Handler(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
  printf("Got an exception %X at address %X\n", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress);
  if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_SINGLE_STEP)
  {
    ExceptionInfo->ContextRecord->Eip++;
    return EXCEPTION_CONTINUE_EXECUTION;
  }
  return EXCEPTION_CONTINUE_SEARCH;
}