IoGetDeviceDirectory

INT64 __fastcall IoGetDeviceDirectory(INT64 a1, INT64 a2, INT64 a3, INT64 a4, _QWORD *a5){
  int v6; 
  void *v7; 
  WCHAR *v8; 
  int v10; 
  WCHAR v11; 
  WCHAR v12; 
  WCHAR v13; 
  __int64 v14; 
  int StateRootPath; 
  int ObjectProperty; 
  _UNICODE_STRING *v17; 
  __int64 v18; 
  unsigned __int64 v19; 
  __int64 v20; 
  __int64 v21; 
  int v22; 
  int v23; 
  unsigned __int16 Length; 
  int v25; 
  __int64 v26; 
  wchar_t *Buffer; 
  int v28; 
  INT64 v30; 
  INT64 v31; 
  INT64 v32; 
  UINT64 v33; 
  __int64 v34; 
  struct _UNICODE_STRING Destination; 
  struct _UNICODE_STRING DestinationString; 
  PCWSTR SourceString; 
  struct _UNICODE_STRING UnicodeString; 
  UNICODE_STRING v39; 
  UUID Uuid; 
  v6 = a2;
  v7 = 0i64;
  v34 = 0i64;
  v8 = 0i64;
  v33 = 0i64;
  SourceString = 0i64;
  v10 = a3;
  DestinationString = 0i64;
  UnicodeString = 0i64;
  Uuid = 0i64;
  Destination = 0i64;
  v39 = 0i64;
  RtlInitUnicodeString(&DestinationString, 0i64, a3);
  RtlInitUnicodeString(&UnicodeString, 0i64, v11);
  RtlInitUnicodeString(&Destination, 0i64, v12);
  RtlInitUnicodeString(&v39, 0i64, v13);
  if( !a1
    || v10
    || a4
    || !a5
    || (v14 = *(_QWORD *)(*(_QWORD *)(a1 + 312) + 40i64)) == 0
    || !*(_WORD *)(v14 + 40)
    || !*(_QWORD *)(v14 + 48)
    || v6 )
  {
    StateRootPath = -1073741811;
    goto LABEL_46;
  }
  StateRootPath = PiGetStateRootPath(L"DriverState");
  if( StateRootPath < 0 )
    goto LABEL_46;
  LODWORD(v32) = 0;
  ObjectProperty = PnpGetObjectProperty(
                     1869181008i64,
                     78i64,
                     *(_QWORD *)(v14 + 48),
                     1i64,
                     0i64,
                     0i64,
                     (INT64 *)&DEVPKEY_Device_StateDirectoryId,
                     (UINT64)&v33 + 4,
                     (INT64)&SourceString,
                     (ULONG *)&v33,
                     v32);
  v8 = (WCHAR *)SourceString;
  v18 = -1i64;
  StateRootPath = ObjectProperty;
  if( ObjectProperty >= 0 )
  {
    if( HIDWORD(v33) == 18 && (unsigned int)v33 >= 2 )
    {
      v19 = -1i64;
      do
        ++v19;
      while( SourceString[v19] );
      v17 = 0i64;
      if( v19 )
      {
        v20 = 0i64;
        do
        {
          v21 = SourceString[v20];
          if( (unsigned int)v21 > 0x7F || (*((_BYTE *)qword_140011770 + v21) & 1) == 0 )
            goto LABEL_26;
          v17 = (_UNICODE_STRING *)(unsigned int)((_DWORD)v17 + 1);
          v20 = (unsigned int)v17;
        }
        while( (unsigned int)v17 < v19 );
      }
    }
    else
    {
      StateRootPath = -1073741275;
    }
    if( StateRootPath >= 0 )
    {
      StateRootPath = RtlInitUnicodeStringEx(&v39, (WCHAR *)SourceString);
      if( StateRootPath < 0 )
        goto LABEL_46;
      v22 = PiBuildAndOpenDeviceDirectoryPath(&DestinationString, (INT64)&v39);
LABEL_42:
      StateRootPath = v22;
      if( v22 >= 0 )
      {
        v7 = 0i64;
        *a5 = v34;
        goto LABEL_46;
      }
      goto LABEL_44;
    }
  }
  if( StateRootPath != -1073741275 )
    goto LABEL_46;
LABEL_26:
  PnpConcatenateUnicodeStrings(&Destination, (_UNICODE_STRING *)(v14 + 40), v17, 0i64, v30, v31);
  StateRootPath = v23;
  if( v23 >= 0 )
  {
    Length = Destination.Length;
    v25 = 0;
    if( (Destination.Length & 0xFFFE) != 0 )
    {
      while( 1 )
      {
        v26 = Destination.Buffer[v25];
        if( (unsigned int)v26 > 0x7F )
          break;
        if( (*((_BYTE *)qword_140011770 + v26) & 1) == 0 )
        {
          Destination.Buffer[v25] = (*((_BYTE *)qword_140011770 + v26) & 1) + 35;
          Length = Destination.Length;
        }
        if( ++v25 >= (unsigned int)(Length >> 1) )
          goto LABEL_34;
      }
      StateRootPath = -1073741811;
    }
LABEL_34:
    if( StateRootPath >= 0 )
    {
      Buffer = Destination.Buffer;
      v28 = PiBuildAndOpenDeviceDirectoryPath(&DestinationString, (INT64)&Destination);
      StateRootPath = v28;
      if( v28 == -1073741766 )
      {
        StateRootPath = ExUuidCreate(&Uuid);
        if( StateRootPath < 0 )
          goto LABEL_44;
        StateRootPath = RtlStringFromGUIDEx(&Uuid, &UnicodeString, 1u);
        if( StateRootPath < 0 )
          goto LABEL_44;
        Buffer = UnicodeString.Buffer;
        v28 = PiBuildAndOpenDeviceDirectoryPath(&DestinationString, (INT64)&UnicodeString);
        StateRootPath = v28;
      }
      if( v28 >= 0 )
      {
        do
          ++v18;
        while( Buffer[v18] );
        v22 = PnpSetObjectProperty(
                PiPnpRtlCtx,
                *(_QWORD *)(v14 + 48),
                1u,
                0i64,
                0i64,
                (__int64)&DEVPKEY_Device_StateDirectoryId,
                18,
                (__int64)Buffer,
                2 * (int)v18 + 2,
                0);
        goto LABEL_42;
      }
LABEL_44:
      v7 = (void *)v34;
    }
  }
LABEL_46:
  RtlFreeAnsiString(&DestinationString);
  RtlFreeAnsiString(&UnicodeString);
  RtlFreeAnsiString(&Destination);
  if( v8 )
    ExFreePoolWithTag(v8, 0x6F697050u);
  if( v7 )
    ZwClose(v7);
  return(unsigned int)StateRootPath;
}

Referenced by:

No references.