RtlUnicodeStringToUTF8String

NTSTATUS __fastcall RtlUnicodeStringToUTF8String(INT64 a1, UINT64 **a2, INT8 a3){
  int v4; 
  int v7; 
  NTSTATUS result; 
  UINT64 v9; 
  unsigned __int16 v10; 
  VOID *StringRoutine; 
  unsigned __int16 v12; 
  UINT32 v13; 
  int v14; 
  UINT64 UnicodeStringByteCount; 
  UINT64 NumberOfBytes; 
  UINT64 UTF8StringActualByteCount; 

  v4 = *(unsigned __int16 *)a2;
  LODWORD(NumberOfBytes) = 0;
  LODWORD(UTF8StringActualByteCount) = 0;
  v7 = 0;
  result = CountUnicodeToUTF8((PWCHAR)a2[1], (unsigned int)(v4 + 2), &NumberOfBytes);
  if( result >= 0 )
  {
    v9 = (unsigned int)NumberOfBytes;
    if( (unsigned int)NumberOfBytes > 0xFFFF )
      return -1073741584;
    v10 = NumberOfBytes - 1;
    *(_WORD *)a1 = NumberOfBytes - 1;
    if( a3 )
    {
      *(_WORD *)(a1 + 2) = v9;
      StringRoutine = ExpAllocateStringRoutine(v9);
      *(_QWORD *)(a1 + 8) = StringRoutine;
      if( !StringRoutine )
        return -1073741801;
      v10 = *(_WORD *)a1;
    }
    else
    {
      v12 = *(_WORD *)(a1 + 2);
      if( v10 >= v12 )
      {
        if( !v12 )
          return -2147483643;
        v10 = v12 - 1;
        v7 = -2147483643;
        *(_WORD *)a1 = v12 - 1;
      }
    }
    LODWORD(UnicodeStringByteCount) = *(unsigned __int16 *)a2;
    v14 = RtlUnicodeToUTF8N(
            *(PCHAR *)(a1 + 8),
            v10,
            (PULONG)&UTF8StringActualByteCount,
            (WCHAR *)a2[1],
            UnicodeStringByteCount);
    if( v14 < 0 )
    {
      if( a3 )
      {
        ExFreePoolWithTag(*(PVOID *)(a1 + 8), v13);
        *(_QWORD *)(a1 + 8) = 0i64;
      }
    }
    else
    {
      v14 = v7;
      *(_BYTE *)((unsigned int)UTF8StringActualByteCount + *(_QWORD *)(a1 + 8)) = 0;
    }
    return v14;
  }
  return result;
}

Referenced by:

No references.