KiTpHandleTrap

BOOL __stdcall KiTpHandleTrap(INT64 a1, INT64 a2, UINT8 a3, CHAR a4){
  INT64 v7; 
  struct _KPRCB *CurrentPrcb; 
  unsigned __int64 v10; 
  _EPROCESS *Process; 
  INT64 i; 
  _KPRCBFLAG v13; 
  _EPROCESS *v14; 
  int v15; 
  __int64 v16; 
  int v17; 
  __int64 v18; 
  bool v19; 
  INT64 v20[2]; 
  __int64 v21; 
  INT64 v22[2]; 
  __int64 v23; 
  INT64 v24[2]; 
  __int64 v25; 

  v7 = a1;
  if( (KiDynamicTraceEnabled & 2) == 0 && (!a3 || (KiDynamicTraceEnabled & 1) == 0) )
    return 0;
  v19 = 0;
  CurrentPrcb = 0i64;
  v10 = *(_QWORD *)(a2 + 248);
  Process = KeGetCurrentThread()->Process;
  _InterlockedAdd(&KiTpActiveTrapsCount, 1u);
  for( i = *(_QWORD *)(KiTpHashTable + 8 * ((v10 >> 4) & 0x3FFF)); ; i = *(_QWORD *)i )
  {
    if( !i )
    {
      v19 = *(_BYTE *)v10 != 0xCC;
      goto LABEL_34;
    }
    if( v10 == *(_QWORD *)(i + 8) && (!*(_BYTE *)(i + 50) || Process == *(_EPROCESS **)(i + 16)) )
      break;
  }
  if( KeGetCurrentIrql() < 2u )
  {
LABEL_16:
    if( a4 )
    {
      v14 = *(_EPROCESS **)(i + 16);
      if( !v14 || *(_BYTE *)(i + 50) || v14 == Process )
      {
        if( *(_BYTE *)(i + 24) )
        {
          v16 = 4i64;
          if( *(_BYTE *)(i + 50) )
            v16 = 6i64;
          if( ((unsigned __int8(__fastcall *)(INT64, _QWORD, _EPROCESS *, INT64))KiDynamicTraceCallouts[v16])(
                 a2,
                 *(_QWORD *)(i + 32),
                 Process,
                 a1) )
          {
            goto LABEL_14;
          }
          v7 = a1;
        }
        v24[0] = v7;
        v24[1] = a2;
        v25 = a3;
        v17 = KiTpEmulateInstruction((UINT8 *)(i + 52), v24);
        if( v17 >= 0 && *(_BYTE *)(i + 25) )
        {
          v18 = 5i64;
          if( *(_BYTE *)(i + 50) )
            v18 = 7i64;
          ((void(__fastcall *)(INT64, _QWORD))KiDynamicTraceCallouts[v18])(a2, *(_QWORD *)(i + 40));
        }
LABEL_33:
        v19 = v17 >= 0;
        goto LABEL_34;
      }
      v22[0] = a1;
      v22[1] = a2;
      v23 = a3;
      v15 = KiTpEmulateInstruction((UINT8 *)(i + 52), v22);
    }
    else
    {
      v15 = KiTpWriteBreakpoint(i, 0);
    }
    v17 = v15;
    goto LABEL_33;
  }
  CurrentPrcb = KeGetCurrentPrcb();
  v13.PrcbFlags = (volatile int)CurrentPrcb->PrcbFlags;
  if( (v13.PrcbFlags & 0x800) == 0 )
  {
    CurrentPrcb->PrcbFlags._bf_0 = v13._bf_0 | 0x800;
    goto LABEL_16;
  }
  CurrentPrcb = 0i64;
  v20[0] = a1;
  v20[1] = a2;
  v21 = a3;
  if( (int)KiTpEmulateInstruction((UINT8 *)(i + 52), v20) >= 0 )
LABEL_14:
    v19 = 1;
LABEL_34:
  if( CurrentPrcb )
    CurrentPrcb->PrcbFlags._bf_0 &= ~0x800u;
  _InterlockedDecrement(&KiTpActiveTrapsCount);
  return v19;
}

Referenced by:

KiDispatchException