PiDmObjectCreate

INT64 __fastcall PiDmObjectCreate(UINT64 a1, const WCHAR *a2, CHAR **a3){
  unsigned int v4; 
  __int64 v5; 
  char *PoolWithTag; 
  char *v7; 
  WCHAR **v8; 
  __int64 v9; 
  signed int PWSTR; 
  WCHAR *v11; 
  WCHAR *v12; 
  wchar_t *v13; 
  wchar_t *v14; 
  __int64 v15; 
  __int64 v16; 
  _DWORD *v17; 
  __int64 v18; 
  unsigned int v19; 
  __int64 *v20; 
  DEVPROPKEY **v21; 
  unsigned int CachedKeyIndex; 
  wchar_t *v24; 
  _QWORD *v25; 
  unsigned int v26; 
  DEVPROPKEY **v27; 
  UNICODE_STRING String; 
  int v30; 
  *a3 = 0i64;
  v27 = 0i64;
  v4 = a1;
  v26 = 0;
  LOBYTE(v30) = 0;
  PiDmGetCacheKeys(a1, &v27, &v26);
  v5 = v26;
  PoolWithTag = (char *)ExAllocatePoolWithTag(PagedPool, 24 * v26 + 112, 0x5A706E50ui64);
  v7 = PoolWithTag;
  if( !PoolWithTag )
    return(unsigned int)-1073741670;
  memset((INT64)PoolWithTag, 0i64);
  *(_QWORD *)v7 = 0i64;
  v8 = (WCHAR **)(v7 + 16);
  *((_DWORD *)v7 + 2) = 1;
  *((_DWORD *)v7 + 7) = v4;
  PWSTR = PnpAllocatePWSTR((WCHAR *)a2, 0x7FFFFFFFui64, 0x5A706E50ui64, (WCHAR **)v7 + 2);
  if( PWSTR < 0 )
    goto LABEL_41;
  v11 = *v8;
  if( v4 == 3 )
  {
    PWSTR = CmSetDeviceInterfacePathFormat(v9, v11, 0);
    if( PWSTR < 0 )
      goto LABEL_41;
    v12 = *v8;
    PWSTR = 0;
    String = 0i64;
    v13 = v12 + 4;
    if( v13 )
    {
      v14 = v13;
      v15 = 0x7FFFi64;
      do
      {
        if( !*v14 )
          break;
        ++v14;
        --v15;
      }
      while( v15 );
      goto LABEL_9;
    }
  }
  else
  {
    PWSTR = PnpValidateObjectName(v9, (__int64)v11, v4);
    if( PWSTR < 0 )
      goto LABEL_41;
    v13 = *v8;
    PWSTR = 0;
    String = 0i64;
    if( v13 )
    {
      v24 = v13;
      v15 = 0x7FFFi64;
      do
      {
        if( !*v24 )
          break;
        ++v24;
        --v15;
      }
      while( v15 );
LABEL_9:
      v16 = (0x7FFF - v15) & -(__int64)(v15 != 0);
      PWSTR = v15 == 0 ? 0xC000000D : 0;
      if( v15 )
      {
        String.Buffer = v13;
        String.Length = 2 * v16;
        String.MaximumLength = 2 * v16 + 2;
      }
    }
  }
  if( PWSTR < 0 )
    goto LABEL_41;
  PWSTR = RtlHashUnicodeString(&String, 1u, 0i64, (UINT64 *)v7 + 3);
  switch( v4 )
  {
    case 1u:
      v25 = v7 + 88;
      break;
    case 2u:
    case 4u:
      v25 = v7 + 40;
      break;
    case 5u:
    case 6u:
      *((_QWORD *)v7 + 6) = v7 + 40;
      *((_QWORD *)v7 + 5) = v7 + 40;
      v25 = v7 + 64;
      break;
    default:
      goto LABEL_17;
  }
  *v25 = v25;
  v25[1] = v25;
LABEL_17:
  if( (_DWORD)v5 )
  {
    v17 = v7 + 112;
    v18 = v5;
    do
    {
      *v17 = 1;
      v17 += 6;
      --v18;
    }
    while( v18 );
  }
  v19 = 0;
  v20 = (__int64 *)&off_140001528;
  v21 = v27;
  while( v4 != *((_DWORD *)v20 - 2) )
  {
LABEL_22:
    ++v19;
    v20 += 7;
    if( v19 >= 3 )
      goto LABEL_23;
  }
  CachedKeyIndex = PiDmGetCachedKeyIndex((__int64)v21, v5, *v20);
  if( CachedKeyIndex < (unsigned int)v5 )
  {
    PWSTR = PiDmCacheDataEncode(
              17,
              &v30,
              1u,
              (int)v21[3 * CachedKeyIndex + 1],
              HIDWORD(v21[3 * CachedKeyIndex + 1]),
              (__int64)&v7[24 * CachedKeyIndex + 112]);
    if( PWSTR < 0 )
      goto LABEL_41;
    goto LABEL_22;
  }
  PWSTR = -1073741595;
LABEL_23:
  if( PWSTR < 0 )
  {
LABEL_41:
    PiDmObjectRelease(v7);
    return(unsigned int)PWSTR;
  }
  *a3 = v7;
  return(unsigned int)PWSTR;
}

Referenced by:

PiDmAddCacheReferenceForObject
PiDmObjectManagerPopulate