RtlUTF8StringToUnicodeString

NTSTATUS __stdcall RtlUTF8StringToUnicodeString(_CM_KEY_CONTROL_BLOCK *Kcb, VOID *Context){
  char v2; 
  char v4; 
  UINT64 v6; 
  char *v7; 
  NTSTATUS result; 
  UINT64 v9; 
  unsigned __int16 RefCount; 
  VOID *StringRoutine; 
  unsigned __int64 v12; 
  UINT32 v13; 
  int v14; 
  UINT64 UTF8StringByteCount; 
  UINT64 NumberOfBytes; 
  UINT64 UnicodeStringActualByteCount; 

  v4 = v2;
  v6 = (unsigned int)*(unsigned __int16 *)Context + 1;
  LODWORD(NumberOfBytes) = 0;
  v7 = (char *)*((_QWORD *)Context + 1);
  LODWORD(UnicodeStringActualByteCount) = 0;
  result = CountUTF8ToUnicode(v7, v6, &NumberOfBytes);
  if( result >= 0 )
  {
    v9 = (unsigned int)NumberOfBytes;
    if( (unsigned int)NumberOfBytes > 0xFFFE )
      return -1073741584;
    RefCount = NumberOfBytes - 2;
    LOWORD(Kcb->RefCount) = NumberOfBytes - 2;
    if( v4 )
    {
      WORD1(Kcb->RefCount) = v9;
      StringRoutine = ExpAllocateStringRoutine(v9);
      *(_QWORD *)&Kcb->_bf_8 = StringRoutine;
      if( !StringRoutine )
        return -1073741801;
      RefCount = Kcb->RefCount;
    }
    else
    {
      v12 = RefCount + 2i64;
      if( v12 > WORD1(Kcb->RefCount) || v12 < 2 )
        return -2147483643;
    }
    LODWORD(UTF8StringByteCount) = *(unsigned __int16 *)Context;
    v14 = RtlUTF8ToUnicodeN(
            *(WCHAR **)&Kcb->_bf_8,
            RefCount,
            &UnicodeStringActualByteCount,
            *((INT8 **)Context + 1),
            UTF8StringByteCount);
    if( v14 < 0 )
    {
      if( v4 )
      {
        ExFreePoolWithTag(*(PVOID *)&Kcb->_bf_8, v13);
        *(_QWORD *)&Kcb->_bf_8 = 0i64;
      }
    }
    else
    {
      v14 = 0;
      *(_WORD *)(*(_QWORD *)&Kcb->_bf_8 + 2 * ((unsigned __int64)(unsigned int)UnicodeStringActualByteCount >> 1)) = 0;
    }
    return v14;
  }
  return result;
}

Referenced by:

PiGetDefaultMessageString