PopGenerateDeviceFriendlyName

NTSTATUS __stdcall PopGenerateDeviceFriendlyName(INT64 a1, _UNICODE_STRING *a2){
  _DEVICE_OBJECT *v2; 
  NTSTATUS DeviceProperty; 
  signed int v6; 
  const _UNICODE_STRING *v7; 
  unsigned int v8; 
  VOID **PoolWithTag; 
  __int64 v10; 
  VOID **v11; 
  unsigned __int64 Length; 
  unsigned __int16 v14; 
  VOID **v15; 
  UINT64 BufferLength; 

  *a2 = 0i64;
  v2 = *(_DEVICE_OBJECT **)(a1 + 32);
  LODWORD(BufferLength) = 0;
  DeviceProperty = IoGetDeviceProperty(v2, 0, 0i64, 0i64, &BufferLength);
  v6 = DeviceProperty;
  if( DeviceProperty == -1073741789 )
  {
    if( (unsigned int)BufferLength > 0xFFFF
      || (v7 = (const _UNICODE_STRING *)(a1 + 128), v8 = *(unsigned __int16 *)(a1 + 128) + BufferLength + 6, v8 > 0xFFFF) )
    {
      v6 = -2147483643;
      goto LABEL_25;
    }
    PoolWithTag = ExAllocatePoolWithTag(1ui64, v8, 1297630800i64);
    if( PoolWithTag )
    {
      v6 = IoGetDeviceProperty(v2, 0, (unsigned int)BufferLength, PoolWithTag, &BufferLength);
      if( v6 < 0 )
        goto LABEL_20;
      *a2 = 0i64;
      v10 = 0x7FFFi64;
      v11 = PoolWithTag;
      do
      {
        if( !*(_WORD *)v11 )
          break;
        v11 = (VOID **)((char *)v11 + 2);
        --v10;
      }
      while( v10 );
      v6 = v10 == 0 ? 0xC000000D : 0;
      if( v10 )
      {
        if( a2 )
        {
          a2->Buffer = (wchar_t *)PoolWithTag;
          a2->Length = 2 * (v10 != 0 ? 0x7FFF - v10 : 0);
        }
        else
        {
          v6 = -1073741811;
        }
      }
      a2->MaximumLength = v8;
      if( v6 < 0 )
        goto LABEL_20;
      v6 = RtlUnicodeStringCatString(a2);
      if( v6 < 0 )
        goto LABEL_20;
      v6 = RtlUnicodeStringCat(a2, v7);
      if( v6 < 0 )
        goto LABEL_20;
      v6 = RtlUnicodeStringCatString(a2);
      if( v6 < 0 )
        goto LABEL_20;
      Length = a2->Length;
      if( Length > (unsigned __int64)a2->MaximumLength - 2 )
        v6 = -2147483643;
      else
        a2->Buffer[Length >> 1] = 0;
      if( v6 < 0 )
        goto LABEL_20;
      goto LABEL_19;
    }
LABEL_27:
    v6 = -1073741670;
    goto LABEL_25;
  }
  if( DeviceProperty != -1073741772 )
    goto LABEL_22;
  v14 = *(_WORD *)(a1 + 128);
  v15 = ExAllocatePoolWithTag(1ui64, v14, 1297630800i64);
  if( !v15 )
    goto LABEL_27;
  a2->Buffer = (wchar_t *)v15;
  a2->Length = 0;
  a2->MaximumLength = v14;
  RtlCopyUnicodeString(a2, (PCUNICODE_STRING)(a1 + 128));
LABEL_19:
  PoolWithTag = 0i64;
  v6 = 0;
LABEL_20:
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0x4D584650u);
LABEL_22:
  if( v6 < 0 )
LABEL_25:
    *a2 = 0i64;
  return v6;
}

Referenced by:

PopDirectedDripsDiagCreateDeviceDescription
PopFxRegisterDevice