NtCompactKeys

NTSTATUS __stdcall NtCompactKeys(UINT64 Count, VOID **KeyArray){
  unsigned int v3; 
  UINT8 *TransientPoolWithQuotaTag; 
  unsigned int v5; 
  bool v6; 
  NTSTATUS v7; 
  INT64 v8; 
  char v9; 
  UINT64 v10; 
  INT8 v11; 
  PVOID *v12; 
  PVOID *v13; 
  _ETHREAD *CurrentThread; 
  unsigned int v15; 
  __int64 *v16; 
  __int64 v17; 
  __int64 v18; 
  __int16 v19; 
  PADAPTER_OBJECT *v20; 
  __int64 v21; 
  INT8 Object; 
  __int64 v24; 
  __int64 v25; 
  char v26; 
  bool v27; 
  v3 = Count;
  TransientPoolWithQuotaTag = 0i64;
  v5 = 0;
  v26 = 0;
  v6 = 0;
  v7 = CmCheckNoTxContext();
  if( v7 < 0 )
  {
LABEL_4:
    v9 = 0;
  }
  else
  {
    Object = *((_BYTE *)KeGetCurrentThread() + 562);
    if( !SeSinglePrivilegeCheck(*(_QWORD *)&SeBackupPrivilege, Object) )
    {
      v7 = -1073741727;
      goto LABEL_4;
    }
    if( !v3 )
    {
      v7 = 0;
      goto LABEL_4;
    }
    if( v3 >= 0x1FFFFFFF )
    {
      v7 = -1073741811;
      goto LABEL_4;
    }
    v10 = 8 * v3;
    TransientPoolWithQuotaTag = (UINT8 *)CmpAllocateTransientPoolWithQuotaTag(v8, v10, 0x61624D43ui64);
    if( !TransientPoolWithQuotaTag )
    {
      v7 = -1073741670;
      v6 = 0;
      goto LABEL_4;
    }
    if( Object == 1 && (_DWORD)v10 )
    {
      if( ((unsigned __int8)KeyArray & 3) != 0 )
        ExRaiseDatatypeMisalignment();
      if( (unsigned __int64)&KeyArray[v10 / 8] > 0x7FFFFFFF0000i64 || &KeyArray[v10 / 8] < KeyArray )
        MEMORY[0x7FFFFFFF0000] = 0;
    }
    memmove(TransientPoolWithQuotaTag, (UINT8 *)KeyArray, (unsigned int)v10);
    v13 = (PVOID *)TransientPoolWithQuotaTag;
    do
    {
      LOBYTE(v12) = Object;
      v7 = CmObReferenceObjectByHandle(
             *v13,
             0x20006ui64,
             v11,
             v12,
             (OBJECT_HANDLE_INFORMATION *)&TransientPoolWithQuotaTag[8 * v5]);
      if( v7 < 0 )
      {
        v6 = 0;
        v9 = 0;
        goto LABEL_44;
      }
      ++v5;
      ++v13;
    }
    while( v5 < v3 );
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    v6 = ExAcquireRundownProtection((PEX_RUNDOWN_REF)&CmpShutdownRundown);
    v27 = v6;
    if( !v6 )
      KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
    if( v6 )
    {
      CmpLockRegistryExclusive();
      v26 = 1;
      v24 = 0i64;
      v15 = 0;
      v16 = (__int64 *)TransientPoolWithQuotaTag;
      while( 1 )
      {
        v25 = *v16;
        v7 = CmpPerformKeyBodyDeletionCheck(*v16, 0i64);
        if( v7 < 0 )
          goto LABEL_42;
        v17 = *(_QWORD *)(v25 + 8);
        if( v15 )
        {
          v18 = v24;
        }
        else
        {
          v18 = *(_QWORD *)(v17 + 32);
          v24 = v18;
        }
        if( v18 != *(_QWORD *)(v17 + 32) )
          break;
        v19 = *(_WORD *)(v17 + 186);
        if( (v19 & 4) != 0 || (v19 & 0x10) != 0 )
          break;
        if( *(_WORD *)(v17 + 66) )
        {
          v7 = -1073741822;
LABEL_42:
          v6 = v27;
          goto LABEL_43;
        }
        ++v15;
        ++v16;
        if( v15 >= v3 )
        {
          v6 = v27;
          v7 = 0;
          CmpUnlockRegistry();
          CmpLogUnsupportedOperation(7i64);
          goto LABEL_4;
        }
      }
      v7 = -1073741811;
      goto LABEL_42;
    }
    v7 = -1073741431;
LABEL_43:
    v9 = v26;
  }
LABEL_44:
  if( v9 )
    CmpUnlockRegistry();
  if( v6 )
  {
    ExReleaseRundownProtection((PEX_RUNDOWN_REF)&CmpShutdownRundown);
    KeLeaveCriticalRegionThread((__int64)KeGetCurrentThread());
  }
  if( TransientPoolWithQuotaTag )
  {
    if( v5 )
    {
      v20 = (PADAPTER_OBJECT *)TransientPoolWithQuotaTag;
      v21 = v5;
      do
      {
        HalPutDmaAdapter(*v20++);
        --v21;
      }
      while( v21 );
    }
    CmSiFreeMemory((PPRIVILEGE_SET)TransientPoolWithQuotaTag);
  }
  return v7;
}

Referenced by:

No references.