SepLoadNgenLocations

NTSTATUS __stdcall SepLoadNgenLocations(){
  __int64 v0; 
  INT64 v1; 
  unsigned int v2; 
  NTSTATUS v3; 
  int v4; 
  unsigned int v5; 
  unsigned int v6; 
  unsigned int v7; 
  unsigned int v8; 
  VOID **PoolWithTag; 
  VOID **v10; 
  signed __int64 v11; 
  __int16 v12; 
  unsigned int v13; 
  unsigned int v14; 
  __int16 v15; 
  unsigned int v16; 
  unsigned int v17; 
  unsigned int v18; 
  VOID *v19; 
  unsigned int v20; 
  __int64 v21; 
  __int64 v22; 
  __int64 v23; 
  UINT64 *ResultLength; 
  UINT64 *ResultLengtha; 
  UINT64 *v27; 
  UINT64 v28; 
  VOID *KeyHandle; 
  UINT64 Length; 
  VOID *v31; 
  __int64 v32; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  __int128 KeyValueInformation; 
  __int128 KeyInformation[2]; 
  __int128 v36; 

  v32 = v0;
  v2 = 0;
  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  *(_QWORD *)&ObjectAttributes.Attributes = 576i64;
  LODWORD(v28) = 0;
  ObjectAttributes.RootDirectory = 0i64;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)L"tv";
  memset(KeyInformation, 0, sizeof(KeyInformation));
  v36 = 0i64;
  KeyValueInformation = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v3 = ZwOpenKey(&KeyHandle, 0x20019ui64, &ObjectAttributes, v1, (INT64)ResultLength, (INT64)v27, v28, 0i64);
  v4 = v3;
  if( v3 < 0 )
  {
    if( v3 == -1073741772 )
LABEL_39:
      v4 = 0;
  }
  else
  {
    v4 = ZwQueryKey(KeyHandle, KeyFullInformation, KeyInformation, 0x30ui64, &v28);
    if( v4 >= 0 && (_DWORD)v36 && (unsigned int)(DWORD1(v36) - 1) <= 0xFFFE )
    {
      v5 = 0;
      v6 = 0;
      v7 = 0;
      while( 1 )
      {
        LODWORD(ResultLengtha) = 16;
        v4 = ZwEnumerateValueKey(
               KeyHandle,
               v5,
               KeyValueBasicInformation,
               &KeyValueInformation,
               (UINT64)ResultLengtha,
               &v28);
        if( ((v4 + 0x80000000) & 0x80000000) == 0 && v4 != -2147483643 )
          break;
        if( DWORD1(KeyValueInformation) == 4 && DWORD2(KeyValueInformation) >= 2 )
        {
          v6 += DWORD2(KeyValueInformation) + 16;
          if( v6 < DWORD2(KeyValueInformation) + 16 )
            goto LABEL_44;
          ++v7;
        }
        if( ++v5 >= (unsigned int)v36 )
        {
          if( !v7 )
            goto LABEL_39;
          v8 = v6 + 8;
          if( v6 + 8 < v6 )
          {
LABEL_44:
            v4 = -1073741675;
            break;
          }
          v4 = 0;
          LODWORD(Length) = DWORD1(v36) + 16;
          PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)(DWORD1(v36) + 16), 1668499779i64);
          if( PoolWithTag )
          {
            v10 = ExAllocatePoolWithTag(1ui64, v8, 1668499779i64);
            v11 = (signed __int64)v10;
            if( v10 )
            {
              v12 = -1;
              *((_DWORD *)v10 + 1) = 0xFFFF;
              v13 = 0;
              v31 = &v10[2 * v7 + 1];
              v14 = v8 - (16 * v7 + 8);
              v15 = 0;
              if( (_DWORD)v36 )
              {
                while( 1 )
                {
                  LODWORD(ResultLengtha) = Length;
                  v4 = ZwEnumerateValueKey(
                         KeyHandle,
                         v13,
                         KeyValueBasicInformation,
                         PoolWithTag,
                         (UINT64)ResultLengtha,
                         &v28);
                  if( v4 < 0 )
                    break;
                  if( *((_DWORD *)PoolWithTag + 1) == 4 )
                  {
                    v16 = *((_DWORD *)PoolWithTag + 2);
                    if( v16 >= 2 )
                    {
                      v17 = *((_DWORD *)PoolWithTag + 2);
                      do
                      {
                        if( *((_WORD *)PoolWithTag + ((unsigned __int64)v16 >> 1) + 5) )
                          break;
                        *((_DWORD *)PoolWithTag + 2) = v16 - 2;
                        v16 -= 2;
                        v17 = v16;
                      }
                      while( v16 >= 2 );
                      if( v17 )
                      {
                        if( v17 > v14 || v2 >= v7 )
                        {
                          v4 = -2147483643;
                          break;
                        }
                        v18 = *(unsigned __int16 *)(v11 + 4);
                        v19 = v31;
                        if( v18 >= v17 )
                          LOWORD(v18) = v17;
                        v20 = *(unsigned __int16 *)(v11 + 6);
                        *(_WORD *)(v11 + 4) = v18;
                        if( v20 <= *((_DWORD *)PoolWithTag + 2) )
                          LOWORD(v20) = *((_DWORD *)PoolWithTag + 2);
                        *(_WORD *)(v11 + 6) = v20;
                        v21 = 2i64 * v2;
                        *(_QWORD *)(v11 + 8 * v21 + 16) = v19;
                        *(_WORD *)(v11 + 8 * v21 + 8) = *((_WORD *)PoolWithTag + 4);
                        *(_WORD *)(v11 + 8 * v21 + 10) = *((_WORD *)PoolWithTag + 4);
                        memmove(v19, (char *)PoolWithTag + 12, *((_DWORD *)PoolWithTag + 2));
                        v22 = *((unsigned int *)PoolWithTag + 2);
                        v31 = (char *)v31 + v22;
                        v14 -= v22;
                        ++v2;
                      }
                    }
                  }
                  if( ++v13 >= (unsigned int)v36 )
                  {
                    v12 = *(_WORD *)(v11 + 4);
                    v15 = *(_WORD *)(v11 + 6);
                    goto LABEL_32;
                  }
                }
              }
              else
              {
LABEL_32:
                *(_DWORD *)v11 = v2;
                *(_WORD *)(v11 + 4) = v12 + 8;
                v23 = v32;
                *(_WORD *)(v11 + 6) = v15 + 8;
                v11 &= -(__int64)(_InterlockedCompareExchange64((volatile signed __int64 *)(v23 + 40), v11, 0i64) != 0);
              }
              if( v11 )
                ExFreePoolWithTag((PVOID)v11, 0x63734943u);
            }
            else
            {
              v4 = -1073741801;
            }
            ExFreePoolWithTag(PoolWithTag, 0x63734943u);
          }
          else
          {
            v4 = -1073741801;
          }
          break;
        }
      }
    }
  }
  if( KeyHandle )
    ZwClose((_HANDLE)KeyHandle);
  return v4;
}

Referenced by:

SepSetSystemPaths