IoReportRootDevice

NTSTATUS __stdcall IoReportRootDevice(PDRIVER_OBJECT DriverObject){
  _DRIVER_EXTENSION *DriverExtension; 
  HANDLE v3; 
  NTSTATUS result; 
  UNICODE_STRING *v5; 
  NTSTATUS appended; 
  _ETHREAD *CurrentThread; 
  signed __int64 v8; 
  __int16 v9; 
  int v10; 
  char v11; 
  __int64 v12; 
  wchar_t *pszFormat; 
  unsigned int v14; 
  __int64 v15; 
  struct _UNICODE_STRING Destination; 
  __int64 v17; 
  HANDLE v18; 
  struct _UNICODE_STRING DestinationString; 
  NTSTRSAFE_PWSTR ppszDestEnd; 
  PVOID P; 
  _WORD v22[200]; 
  char v23; 
  DriverExtension = DriverObject->DriverExtension;
  Destination.Buffer = v22;
  DestinationString.Buffer = (wchar_t *)&v23;
  *(_QWORD *)&DestinationString.Length = 26345472i64;
  *(_QWORD *)&Destination.Length = 26214400i64;
  LODWORD(v17) = 0;
  v3 = 0i64;
  LOWORD(v15) = 0;
  v18 = 0i64;
  P = 0i64;
  result = RtlAppendUnicodeToString(&Destination, (PWCHAR)L"ROOT\\");
  if( result < 0 )
    return result;
  result = RtlAppendUnicodeStringToString(&Destination, &DriverExtension->ServiceKeyName);
  if( result < 0 )
    return result;
  if( Destination.Length > 0x18Eu )
    return -1073741773;
  RtlCopyUnicodeString(&DestinationString, &Destination, v5);
  appended = PiPnpRtlBeginOperation((__int64 **)&P);
  if( appended >= 0 )
  {
    PpDevNodeLockTree(1);
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    ExAcquireResourceExclusiveLite(&PnpRegistryDeviceResource, 1u);
    appended = RtlAppendUnicodeToString(&Destination, (PWCHAR)L"\\");
    if( appended < 0 )
    {
      v3 = v18;
      goto LABEL_10;
    }
    ppszDestEnd = &v22[(unsigned __int64)Destination.Length >> 1];
    RtlStringCchPrintfExW(
      ppszDestEnd,
      (400 - (unsigned __int64)Destination.Length) >> 1,
      &ppszDestEnd,
      0i64,
      0i64,
      L"%04u",
      0i64);
    v8 = &ppszDestEnd[-((unsigned __int64)Destination.Length >> 1)] - v22;
    if( (_DWORD)v8 == -1 )
      v9 = 400 - Destination.Length;
    else
      v9 = 2 * v8;
    Destination.Length += v9;
    v10 = CmCreateDevice(PiPnpRtlCtx, Destination.Buffer, 983103, &v18, &v15, 0);
    v11 = v15;
    appended = v10;
    v3 = v18;
    if( v10 >= 0 )
    {
      if( !(_BYTE)v15 )
        goto LABEL_10;
      v12 = (__int64)v18;
      v14 = DestinationString.Length + 4;
      pszFormat = DestinationString.Buffer;
      *(_DWORD *)&DestinationString.Buffer[((unsigned __int64)v14 >> 1) - 2] = 0;
      appended = CmSetDeviceRegProp(PiPnpRtlCtx, Destination.Buffer, v12, 2u, 7u, (__int64)pszFormat, v14, 0);
      if( appended >= 0 )
      {
        LODWORD(v17) = 32;
        appended = CmSetDeviceRegProp(PiPnpRtlCtx, Destination.Buffer, (__int64)v3, 0xBu, 4u, (__int64)&v17, 4u, 0);
        if( appended >= 0 )
        {
          BYTE1(v15) = -1;
          appended = PnpSetObjectProperty(
                       PiPnpRtlCtx,
                       (__int64)Destination.Buffer,
                       1u,
                       (__int64)v3,
                       0i64,
                       (__int64)&DEVPKEY_Device_Reported,
                       17,
                       (__int64)&v15 + 1,
                       1u,
                       0);
          if( appended >= 0 )
          {
            appended = CmSetDeviceRegProp(
                         PiPnpRtlCtx,
                         Destination.Buffer,
                         (__int64)v3,
                         5u,
                         1u,
                         (__int64)DriverExtension->ServiceKeyName.Buffer,
                         (unsigned int)DriverExtension->ServiceKeyName.Length + 2,
                         0);
            if( appended >= 0 )
            {
              DriverObject->Flags |= 0x800u;
              PnpRequestDeviceAction(
                *((_DEVICE_OBJECT **)IopRootDeviceNode + 4),
                ReenumerateDeviceOnly,
                0,
                0i64,
                0i64,
                0i64);
              goto LABEL_10;
            }
          }
        }
      }
    }
    if( v11 )
    {
      CmDeleteDevice(PiPnpRtlCtx, Destination.Buffer, 0);
      PnpCleanupDeviceRegistryValues(&Destination);
    }
  }
LABEL_10:
  ExReleaseResourceLite(&PnpRegistryDeviceResource);
  KeLeaveCriticalRegion();
  PpDevNodeUnlockTree(1);
  if( v3 )
    ZwClose(v3);
  if( P )
    PiPnpRtlEndOperation(P);
  return appended;
}

Referenced by:

No references.