HalpInitChipHacks

NTSTATUS __stdcall HalpInitChipHacks(){
  INT64 v0; 
  VOID **PoolWithTag; 
  int v2; 
  unsigned int v3; 
  NTSTATUS v4; 
  __int128 v5; 
  __int16 v6; 
  __int64 v7; 
  UINT64 *ResultLength; 
  UINT64 *ResultLengtha; 
  UINT64 *v11; 
  UINT64 Length; 
  VOID *KeyHandle; 
  UINT64 v14; 
  WCHAR *endptr; 
  __int64 v16[2]; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  __int128 KeyInformation[2]; 
  __int128 v19; 
  WCHAR v20[12]; 

  *(_QWORD *)&ObjectAttributes.Length = 48i64;
  LODWORD(v14) = 0;
  endptr = 0i64;
  v16[1] = (__int64)L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET\\Control\\HAL";
  *(_QWORD *)&ObjectAttributes.Attributes = 64i64;
  ObjectAttributes.ObjectName = (_UNICODE_STRING *)v16;
  v16[0] = 7209068i64;
  byte_140C507C0 = 1;
  memset(KeyInformation, 0, sizeof(KeyInformation));
  PoolWithTag = 0i64;
  LODWORD(Length) = 0;
  v19 = 0i64;
  ObjectAttributes.RootDirectory = 0i64;
  *(_OWORD *)&ObjectAttributes.SecurityDescriptor = 0i64;
  v2 = ZwOpenKey(&KeyHandle, 0x20019ui64, &ObjectAttributes, v0, (INT64)ResultLength, (INT64)v11, Length, 0i64);
  if( v2 < 0 )
    goto LABEL_16;
  v2 = ZwQueryKey(KeyHandle, KeyFullInformation, KeyInformation, 0x30ui64, &v14);
  if( v2 < 0 )
    goto LABEL_16;
  dword_140C507BC = v19;
  if( !(_DWORD)v19 )
    goto LABEL_16;
  qword_140C507C8 = (__int64)ExAllocatePoolWithTag(0x101ui64, 8i64 * (unsigned int)v19, 543973704i64);
  if( !qword_140C507C8 )
  {
    v2 = -1073741670;
    goto LABEL_16;
  }
  v3 = 0;
  if( !dword_140C507BC )
    goto LABEL_16;
  while( 1 )
  {
    LODWORD(ResultLengtha) = Length;
    v4 = ZwEnumerateValueKey(KeyHandle, v3, KeyValueFullInformation, PoolWithTag, (UINT64)ResultLengtha, &Length);
    v2 = v4;
    if( v4 >= 0 )
    {
      if( PoolWithTag
        && (unsigned int)Length >= 0x14
        && *((_DWORD *)PoolWithTag + 3) == 4
        && *((_DWORD *)PoolWithTag + 4) >= 0x10u )
      {
        v5 = *(_OWORD *)((char *)PoolWithTag + 20);
        v20[8] = 0;
        *(_OWORD *)v20 = v5;
        v6 = wcstoul(&v20[4], &endptr, 16i64);
        v7 = qword_140C507C8;
        *(_WORD *)(qword_140C507C8 + 8i64 * v3 + 2) = v6;
        v20[4] = 0;
        *(_WORD *)(v7 + 8i64 * v3) = wcstoul(v20, &endptr, 16i64);
        *(_DWORD *)(v7 + 8i64 * v3 + 4) = *(_DWORD *)((char *)PoolWithTag + *((unsigned int *)PoolWithTag + 2));
      }
      ++v3;
      goto LABEL_13;
    }
    if( v4 != -1073741789 && v4 != -2147483643 )
      goto LABEL_14;
    if( PoolWithTag )
      ExFreePoolWithTag(PoolWithTag, 0);
    PoolWithTag = ExAllocatePoolWithTag(1ui64, (unsigned int)Length, 543973704i64);
    if( !PoolWithTag )
      break;
LABEL_13:
    if( v3 >= dword_140C507BC )
      goto LABEL_14;
  }
  v2 = -1073741670;
LABEL_14:
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
LABEL_16:
  if( KeyHandle )
    ZwClose((_HANDLE)KeyHandle);
  return v2;
}

Referenced by:

HalpErrataInitSystem