BiConvertElementToRegistryData

NTSTATUS __stdcall BiConvertElementToRegistryData(
        UINT64 ElementType,
        PVOID ElementData,
        UINT64 ElementDataLength,
        UINT64 Flags,
        PVOID *Data,
        UINT64 *DataLength){
  unsigned int v6; 
  UINT64 v7; 
  UINT8 *v9; 
  NTSTATUS v10; 
  unsigned int v11; 
  unsigned int v12; 
  unsigned int v13; 
  unsigned int v14; 
  unsigned int v15; 
  unsigned int v16; 
  unsigned int v17; 
  _BYTE *Buffer; 
  _WORD *v19; 
  unsigned int v20; 
  UINT8 *v21; 
  int v23; 
  _BYTE *PoolWithTag; 
  UINT8 *v25; 
  unsigned int v26; 
  int v27; 
  _WORD *v28; 
  __int64 v29; 
  UINT64 v30; 
  void *Src; 
  struct _UNICODE_STRING DestinationString; 
  int v33; 
  v6 = 0;
  v7 = (unsigned int)ElementDataLength;
  Src = 0i64;
  v9 = 0i64;
  v10 = 0;
  DestinationString = 0i64;
  v11 = (BYTE3(ElementType) & 0xF) - 1;
  if( !v11 )
  {
    if( *(_DWORD *)ElementData == 6 )
      v23 = BiConvertQualifiedPartitionToBootEnvironment((__int64)ElementData, ElementDataLength, &Src);
    else
      v23 = BiConvertNtDeviceToBootEnvironment((INT64 *)ElementData, (unsigned int)ElementDataLength, 0i64, &Src);
    v9 = (UINT8 *)Src;
    v10 = v23;
    if( v23 < 0 )
      goto LABEL_23;
    v17 = *((_DWORD *)Src + 2) + 16;
    if( *((_DWORD *)Src + 2) >= 0xFFFFFFF0 )
    {
      v10 = -1073741811;
    }
    else
    {
      PoolWithTag = ExAllocatePoolWithTag(PagedPool, (unsigned int)(*((_DWORD *)Src + 2) + 16), 0x4B444342ui64);
      Buffer = PoolWithTag;
      if( PoolWithTag )
      {
        *(_OWORD *)PoolWithTag = *(_OWORD *)((char *)ElementData + 4);
        memmove(PoolWithTag + 16, v9, *((unsigned int *)v9 + 2));
        ExFreePoolWithTag(v9, 0x4B444342u);
        v9 = 0i64;
        goto LABEL_21;
      }
      v10 = -1073741801;
    }
LABEL_23:
    if( v9 )
      ExFreePoolWithTag(v9, 0x4B444342u);
    return v10;
  }
  v12 = v11 - 1;
  if( !v12 )
  {
    if( (ElementDataLength & 1) != 0 )
      return -1073741788;
    v19 = ElementData;
    v20 = (unsigned int)ElementDataLength >> 1;
    if( (unsigned int)ElementDataLength >> 1 )
    {
      while( *v19 )
      {
        ++v19;
        if( !--v20 )
          goto LABEL_16;
      }
      LOBYTE(v6) = 1;
    }
LABEL_16:
    v17 = ElementDataLength;
    if( !(_BYTE)v6 )
    {
      if( (int)ElementDataLength + 2 < (unsigned int)ElementDataLength )
        return -1073741675;
      v17 = ElementDataLength + 2;
    }
    v21 = (UINT8 *)ExAllocatePoolWithTag(PagedPool, v17, 0x4B444342ui64);
    Buffer = v21;
    if( !v21 )
      return -1073741801;
    memmove(v21, (UINT8 *)ElementData, v7);
    if( !(_BYTE)v6 )
      *(_WORD *)&Buffer[v17 - 2] = 0;
    v10 = 0;
    goto LABEL_21;
  }
  v13 = v12 - 1;
  if( !v13 )
  {
    if( (_DWORD)ElementDataLength != 16 )
      return -1073741788;
    v10 = RtlStringFromGUIDEx((const _GUID *const)ElementData, &DestinationString, 1u);
    if( v10 < 0 )
      return v10;
    Buffer = DestinationString.Buffer;
    v17 = DestinationString.Length + 2;
    goto LABEL_21;
  }
  v14 = v13 - 1;
  if( v14 )
  {
    v15 = v14 - 1;
    if( v15 )
    {
      v16 = v15 - 1;
      if( v16 )
      {
        if( v16 != 1 || (ElementDataLength & 7) == 0 )
        {
          v17 = ElementDataLength;
          v25 = (UINT8 *)ExAllocatePoolWithTag(PagedPool, (unsigned int)ElementDataLength, 0x4B444342ui64);
          Buffer = v25;
          if( v25 )
          {
            memmove(v25, (UINT8 *)ElementData, v7);
            goto LABEL_22;
          }
          return -1073741801;
        }
      }
      else if( (unsigned int)(ElementDataLength - 1) <= 1 )
      {
        v17 = 1;
        Buffer = ExAllocatePoolWithTag(PagedPool, 1ui64, 0x4B444342ui64);
        if( Buffer )
        {
          *Buffer = *(_BYTE *)ElementData != 0;
LABEL_22:
          v10 = 0;
          *Data = Buffer;
          *(_DWORD *)DataLength = v17;
          goto LABEL_23;
        }
        return -1073741801;
      }
    }
    else
    {
      v17 = 8;
      if( (_DWORD)ElementDataLength == 8 )
      {
        Buffer = ExAllocatePoolWithTag(PagedPool, 8ui64, 0x4B444342ui64);
        if( Buffer )
        {
          *(_QWORD *)Buffer = *(_QWORD *)ElementData;
          goto LABEL_22;
        }
        return -1073741801;
      }
    }
    return -1073741788;
  }
  if( (ElementDataLength & 0xF) != 0 )
    return -1073741788;
  v26 = (unsigned int)ElementDataLength >> 4;
  v27 = 0;
  if( !((unsigned int)ElementDataLength >> 4) )
  {
LABEL_48:
    v17 = v27 + 2;
    v28 = ExAllocatePoolWithTag(PagedPool, v17, 0x4B444342ui64);
    Buffer = v28;
    if( !v28 )
      return -1073741801;
    v29 = 0i64;
    v33 = 0;
    Src = v28;
    if( v26 )
    {
      while( 1 )
      {
        v10 = RtlStringFromGUIDEx((const _GUID *const)ElementData + v29, &DestinationString, 1u);
        if( v10 < 0 )
          goto LABEL_60;
        v30 = (unsigned int)DestinationString.Length + 2;
        memmove((UINT8 *)Src, (UINT8 *)DestinationString.Buffer, v30);
        Src = (char *)Src + v30;
        RtlFreeAnsiString(&DestinationString);
        v29 = (unsigned int)(v33 + 1);
        v33 = v29;
        if( (unsigned int)v29 >= v26 )
        {
          v28 = Src;
          break;
        }
      }
    }
    *v28 = 0;
LABEL_21:
    if( v10 >= 0 )
      goto LABEL_22;
LABEL_60:
    if( !Buffer )
      return v10;
    ExFreePoolWithTag(Buffer, 0x4B444342u);
    goto LABEL_23;
  }
  while( 1 )
  {
    RtlInitUnicodeString(&DestinationString, 0i64, ElementDataLength);
    v10 = RtlStringFromGUIDEx((const _GUID *const)ElementData + v6, &DestinationString, 1u);
    if( v10 < 0 )
      return v10;
    v27 += DestinationString.Length + 2;
    RtlFreeAnsiString(&DestinationString);
    if( ++v6 >= v26 )
      goto LABEL_48;
  }
}

Referenced by:

BcdSetElementDataWithFlags