BiCreateKey

INT64 __fastcall BiCreateKey(
        VOID *ParentHandle,
        WCHAR *KeyName,
        UINT64 Access,
        UINT64 Flags,
        VOID **Handle,
        UINT8 *KeyCreated){
  unsigned int v6; 
  WCHAR *v7; 
  unsigned int i; 
  void *v10; 
  int v11; 
  unsigned int v12; 
  char v13; 
  int v14; 
  void *KeySecurityDescriptor; 
  UINT64 v16; 
  void *v17; 
  UINT64 v18; 
  NTSTATUS v19; 
  UINT64 *v21; 
  PVOID KeyHandle; 
  PVOID v23; 
  struct _UNICODE_STRING DestinationString; 
  OBJECT_ATTRIBUTES ObjectAttributes; 
  void *v26; 
  char v28; 
  v28 = Flags;
  v6 = Access;
  v7 = KeyName;
  v23 = 0i64;
  DestinationString = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  for( i = 0; ; ++i )
  {
    KeyHandle = 0i64;
    RtlInitUnicodeString(&DestinationString, v7, Access);
    LODWORD(v10) = BiSanitizeHandle(ParentHandle);
    v26 = v10;
    v6 |= 0x40000u;
    v11 = 64;
    v12 = v6;
    v13 = 0;
    if( (v28 & 1) != 0 )
    {
      v11 = 192;
      if( (v6 & 0x60019) != v6 )
      {
        v12 = 0x40000;
        v13 = 1;
      }
    }
    v14 = v11 | 0x200;
    KeySecurityDescriptor = BiCreateKeySecurityDescriptor(0xF003Fui64);
    v17 = KeySecurityDescriptor;
    if( KeySecurityDescriptor )
    {
      ObjectAttributes.Length = 48;
      ObjectAttributes.RootDirectory = v26;
      ObjectAttributes.Attributes = v14;
      ObjectAttributes.ObjectName = &DestinationString;
      ObjectAttributes.SecurityDescriptor = KeySecurityDescriptor;
      ObjectAttributes.SecurityQualityOfService = 0i64;
      v19 = BiZwCreateKey(&KeyHandle, v12, &ObjectAttributes, v16, v21);
      if( v19 < 0 )
        goto LABEL_14;
      if( v13 )
      {
        v19 = BiZwSetSecurityObject(KeyHandle, v18, v17);
        if( v19 < 0 )
          goto LABEL_14;
        v19 = BiZwOpenKey(&v23, v6, &ObjectAttributes);
        if( v19 < 0 )
          goto LABEL_14;
        CmSiCloseSection(KeyHandle);
        KeyHandle = v23;
      }
      if( KeyCreated )
        *KeyCreated = 0;
      *Handle = KeyHandle;
LABEL_14:
      if( v19 >= 0 )
        goto LABEL_15;
      goto LABEL_20;
    }
    v19 = -1073741703;
LABEL_20:
    if( KeyHandle )
      CmSiCloseSection(KeyHandle);
LABEL_15:
    if( v17 )
      ExFreePoolWithTag(v17, 0x4B444342u);
    if( v19 != -1073741443 )
      break;
    __debugbreak();
    ParentHandle = v26;
    if( i >= 5 )
      break;
    v7 = KeyName;
  }
  return(unsigned int)v19;
}

Referenced by:

BcdSetElementDataWithFlags
BiAddStoreFromFile
BiCreateObject
BiSetObjectDescription