KiTpHandleTrap

BOOL __fastcall KiTpHandleTrap(INT64 a1, INT64 rdx0, UINT8 a3, CHAR a4){
  INT64 v7; 
  BOOL result; 
  struct _KPRCB *CurrentPrcb; 
  unsigned __int64 v10; 
  __int64 v11; 
  INT64 i; 
  int v13; 
  __int64 v14; 
  int v15; 
  __int64 v16; 
  int v17; 
  __int64 v18; 
  bool v19; 
  INT64 a2[2]; 
  __int64 v21; 
  INT64 v22[2]; 
  __int64 v23; 
  INT64 v24[2]; 
  __int64 v25; 
  v7 = a1;
  result = KiDynamicTraceEnabled & 2;
  if( !result && (!a3 || (KiDynamicTraceEnabled & 1) == 0) )
  {
    LOBYTE(result) = 0;
    return result;
  }
  v19 = 0;
  CurrentPrcb = 0i64;
  v10 = *(_QWORD *)(rdx0 + 248);
  v11 = *((_QWORD *)KeGetCurrentThread() + 68);
  _InterlockedAdd(&KiTpActiveTrapsCount, 1u);
  for( i = *(_QWORD *)(KiTpHashTable + 8 * ((v10 >> 4) & 0x3FFF)); ; i = *(_QWORD *)i )
  {
    if( !i )
    {
      result = *(_BYTE *)v10 != 0xCC;
      v19 = *(_BYTE *)v10 != 0xCC;
      goto LABEL_34;
    }
    if( v10 == *(_QWORD *)(i + 8) && (!*(_BYTE *)(i + 50) || v11 == *(_QWORD *)(i + 16)) )
      break;
  }
  if( KeGetCurrentIrql() < 2u )
  {
LABEL_16:
    if( a4 )
    {
      v14 = *(_QWORD *)(i + 16);
      if( !v14 || *(_BYTE *)(i + 50) || v14 == v11 )
      {
        if( *(_BYTE *)(i + 24) )
        {
          v16 = 4i64;
          if( *(_BYTE *)(i + 50) )
            v16 = 6i64;
          result = ((__int64(__fastcall *)(INT64, _QWORD, __int64, INT64))KiDynamicTraceCallouts[v16])(
                     rdx0,
                     *(_QWORD *)(i + 32),
                     v11,
                     a1);
          if( result )
            goto LABEL_14;
          v7 = a1;
        }
        v24[0] = v7;
        v24[1] = rdx0;
        v25 = a3;
        v17 = KiTpEmulateInstruction((UINT8 *)(i + 52), (INT64)v24);
        if( v17 >= 0 && *(_BYTE *)(i + 25) )
        {
          v18 = 5i64;
          if( *(_BYTE *)(i + 50) )
            v18 = 7i64;
          ((void(__fastcall *)(INT64, _QWORD))KiDynamicTraceCallouts[v18])(rdx0, *(_QWORD *)(i + 40));
        }
LABEL_33:
        result = v17 >= 0;
        v19 = v17 >= 0;
        goto LABEL_34;
      }
      v22[0] = a1;
      v22[1] = rdx0;
      v23 = a3;
      v15 = KiTpEmulateInstruction((UINT8 *)(i + 52), (INT64)v22);
    }
    else
    {
      v15 = KiTpWriteBreakpoint(i, 0);
    }
    v17 = v15;
    goto LABEL_33;
  }
  CurrentPrcb = KeGetCurrentPrcb();
  v13 = *((_DWORD *)CurrentPrcb + 59);
  if( (v13 & 0x800) == 0 )
  {
    *((_DWORD *)CurrentPrcb + 59) = v13 | 0x800;
    goto LABEL_16;
  }
  CurrentPrcb = 0i64;
  a2[0] = a1;
  a2[1] = rdx0;
  v21 = a3;
  result = KiTpEmulateInstruction((UINT8 *)(i + 52), (INT64)a2);
  if( result >= 0 )
LABEL_14:
    v19 = 1;
LABEL_34:
  if( CurrentPrcb )
    *((_DWORD *)CurrentPrcb + 59) &= ~0x800u;
  _InterlockedDecrement(&KiTpActiveTrapsCount);
  LOBYTE(result) = v19;
  return result;
}

Referenced by:

KiDispatchException