PiRearrangeDeviceInstances

VOID __stdcall PiRearrangeDeviceInstances(
        VOID *ServiceEnumHandle,
        UINT64 InstanceCount,
        UINT64 InstanceDeleted,
        INT64 a4,
        INT64 a5,
        INT64 a6,
        INT64 a7,
        INT64 a8){
  __int64 v9; 
  _OBJECT_TYPE *v10; 
  _KEY_VALUE_FULL_INFORMATION *v11; 
  __int64 v12; 
  _KEY_VALUE_FULL_INFORMATION *v13; 
  UINT64 pszFormat; 
  _NTSTRSAFE_PWSTR ppszDestEnd[2]; 
  _UNICODE_STRING ValueName; 
  UINT64 dwFlags; 
  _KEY_VALUE_FULL_INFORMATION *Information; 
  __int128 KeyInformation[3]; 
  __int16 pszDest[12]; 

  *(_DWORD *)(&ValueName.MaximumLength + 1) = 0;
  LODWORD(dwFlags) = 0;
  Information = 0i64;
  memset(KeyInformation, 0, sizeof(KeyInformation));
  ZwQueryKey(ServiceEnumHandle, KeyFullInformation, KeyInformation, 0x30ui64, &dwFlags);
  *(_QWORD *)ppszDestEnd = pszDest;
  RtlStringCchPrintfExW((WCHAR *)pszDest, 0xAui64, (WCHAR **)ppszDestEnd, 0i64, 0i64, (WCHAR *)L"%u");
  v9 = (__int64)(*(_QWORD *)ppszDestEnd - (_QWORD)pszDest) >> 1;
  ValueName.MaximumLength = 20;
  if( (_DWORD)v9 == -1 )
    ValueName.Length = 20;
  else
    ValueName.Length = 2 * v9;
  ValueName.Buffer = (wchar_t *)pszDest;
  if( IopGetRegistryValue(ServiceEnumHandle, (PWCHAR)pszDest, 0i64, &Information) >= 0 )
  {
    ZwDeleteValueKey(ServiceEnumHandle, &ValueName, v10);
    *(_QWORD *)ppszDestEnd = pszDest;
    RtlStringCchPrintfExW((WCHAR *)pszDest, 0xAui64, (WCHAR **)ppszDestEnd, 0i64, 0i64, (WCHAR *)L"%u");
    ValueName.MaximumLength = 20;
    v12 = (__int64)(*(_QWORD *)ppszDestEnd - (_QWORD)pszDest) >> 1;
    if( (_DWORD)v12 == -1 )
      ValueName.Length = 20;
    else
      ValueName.Length = 2 * v12;
    v13 = Information;
    ValueName.Buffer = (wchar_t *)pszDest;
    LODWORD(pszFormat) = Information->DataLength;
    ZwSetValueKey(ServiceEnumHandle, &ValueName, 0i64, 1ui64, (char *)Information + Information->DataOffset, pszFormat);
    ExFreePoolWithTag(v13, 0);
    v11 = 0i64;
  }
  else
  {
    v11 = Information;
  }
  if( v11 )
    ExFreePoolWithTag(v11, 0);
}

Referenced by:

PiProcessDriverInstance