KiConnectInterrupt

__int64 __fastcall KiConnectInterrupt(__int64 a1){
  __int64 v1; 
  char v2; 
  int v3; 
  char v4; 
  unsigned int v5; 
  unsigned __int8 v7; 
  __int64 v8; 
  char *v9; 
  __int64 v10; 
  INT64(__fastcall *v12)(); 
  __int64 v13; 
  __int64 v14; 
  char OldIrql[8]; 
  char *v16; 
  struct _GROUP_AFFINITY PreviousAffinity; 
  v1 = *(unsigned int *)(a1 + 88);
  v2 = 0;
  v3 = *(unsigned __int8 *)(a1 + 92);
  v4 = 0;
  v5 = *(_DWORD *)(a1 + 96);
  OldIrql[0] = 0;
  PreviousAffinity = 0i64;
  if( (unsigned int)v1 > 0xFF || (unsigned __int8)v3 > 0xFu || v3 != (unsigned int)v1 >> 4 && (_BYTE)v3 )
    return 3221225711i64;
  if( v5 >= (unsigned int)KeNumberProcessors_0 )
    return 3221225711i64;
  v7 = *(_BYTE *)(a1 + 93);
  if( v7 < (unsigned __int8)v3 )
  {
    if( v7 )
      return 3221225711i64;
  }
  KiAcquireInterruptConnectLock(v5, (UINT8 *)OldIrql, &PreviousAffinity);
  v8 = *((_QWORD *)KeGetPcr() + 7) + 16 * v1;
  LOWORD(v16) = *(_WORD *)v8;
  WORD1(v16) = *(_WORD *)(v8 + 6);
  HIDWORD(v16) = *(_DWORD *)(v8 + 8);
  if( !*(_BYTE *)(a1 + 95) )
  {
    v9 = (char *)KiIsrThunkShadow;
    if( !(_BYTE)KiKvaShadow )
      v9 = (char *)KxUnexpectedInterrupt0;
    if( v16 == &v9[8 * v1] )
    {
      v10 = *((_QWORD *)KeGetCurrentPrcb() + v1 + 1576);
      if( !v10 )
      {
        if( !*(_BYTE *)(a1 + 93) )
        {
          *(_QWORD *)(a1 + 16) = a1 + 8;
          *(_QWORD *)(a1 + 8) = a1 + 8;
          *(_QWORD *)(a1 + 80) = KiChainedDispatch;
        }
        v4 = 1;
        *(_BYTE *)(a1 + 95) = 1;
        goto LABEL_14;
      }
      if( (unsigned int)v1 >= 0x30 )
      {
        v2 = 1;
        if( *(_DWORD *)(a1 + 108) == *(_DWORD *)(v10 + 108) )
        {
          if( *(_BYTE *)(a1 + 100) )
          {
            if( *(_BYTE *)(v10 + 100) )
            {
              if( *(INT64(__fastcall **)())(a1 + 80) == KiInterruptDispatch )
              {
                v12 = *(INT64(__fastcall **)())(v10 + 80);
                if( v12 == KiInterruptDispatch || v12 == KiChainedDispatch )
                {
                  *(_BYTE *)(a1 + 95) = 1;
                  v4 = 1;
                  if( *(INT64(__fastcall **)())(v10 + 80) != KiChainedDispatch )
                  {
                    *(_QWORD *)(v10 + 80) = KiChainedDispatch;
                    *(_QWORD *)(v10 + 16) = v10 + 8;
                    *(_QWORD *)(v10 + 8) = v10 + 8;
                  }
                  KiInsertInterruptObjectOrdered((_KINTERRUPT *)v10, (_KINTERRUPT *)a1);
                  if( !*(_BYTE *)(v14 + 93) )
                  {
                    if( *(_BYTE *)(a1 + 93) )
                    {
                      *(_QWORD *)(a1 + 80) = v13;
LABEL_14:
                      *((_QWORD *)KeGetCurrentPrcb() + v1 + 1576) = a1;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  __writecr8((unsigned __int8)OldIrql[0]);
  KeRevertToUserGroupAffinityThread(&PreviousAffinity);
  if( v4 )
    return v2 != 0 ? 0x127 : 0;
  return 3221225711i64;
}

Referenced by:

KeConnectInterrupt