PipChangeDeviceObjectFromRegistryProperties

NTSTATUS __stdcall PipChangeDeviceObjectFromRegistryProperties(
        DEVICE_OBJECT *PhysicalDeviceObject,
        PVOID DeviceInstanceKey,
        PWCHAR ClassGuid,
        PVOID InstallerClassKey,
        UINT8 UsePdoCharacteristics){
  __int64 v9; 
  __int64 v10; 
  int v11; 
  PVOID v12; 
  const wchar_t *v13; 
  int v14; 
  char RegistryDwordWithFallback; 
  const wchar_t *v16; 
  char v17; 
  const wchar_t *v18; 
  DEVICE_OBJECT *v19; 
  int v20; 
  unsigned int v21; 
  const wchar_t *v22; 
  unsigned int v23; 
  PVOID RegistrySecurityWithFallback; 
  UINT8 *v25; 
  VOID *v26; 
  char v27; 
  __int64 i; 
  NTSTATUS OwnerSecurityDescriptor; 
  char v30; 
  DEVICE_OBJECT *v31; 
  int v33; 
  int v34; 
  VOID *v35; 
  unsigned __int8 SaclPresent; 
  unsigned __int8 OwnerDefaulted; 
  char v38; 
  char v39; 
  char v40; 
  UINT64 DeviceType; 
  int v42; 
  PSID Owner; 
  PVOID SecurityInformation; 
  PACL Sacl; 
  PVOID P; 
  unsigned __int64 v47; 
  ACL *AllocatedAcl[2]; 
  __int128 v49; 
  __int64 v50; 
  v47 = (unsigned __int64)InstallerClassKey;
  Sacl = (PACL)ClassGuid;
  SaclPresent = 0;
  v9 = *((_QWORD *)PhysicalDeviceObject + 39);
  Owner = 0i64;
  if( PhysicalDeviceObject )
    v10 = *(_QWORD *)(v9 + 40);
  else
    v10 = 0i64;
  v11 = *(_DWORD *)(v9 + 32);
  v12 = 0i64;
  v13 = *(const wchar_t **)(v10 + 48);
  v39 = 0;
  P = 0i64;
  SecurityInformation = 0i64;
  v14 = v11 & 0x800;
  v42 = 0;
  DeviceType = 0i64;
  RegistryDwordWithFallback = PipGetRegistryDwordWithFallback(
                                26,
                                v13,
                                (__int64)DeviceInstanceKey,
                                (__int64)ClassGuid,
                                (__int64)InstallerClassKey,
                                (_DWORD *)&DeviceType + 1);
  v16 = *(const wchar_t **)(v10 + 48);
  v38 = RegistryDwordWithFallback;
  v17 = PipGetRegistryDwordWithFallback(
          27,
          v16,
          (__int64)DeviceInstanceKey,
          (__int64)ClassGuid,
          (__int64)InstallerClassKey,
          &v42);
  v18 = *(const wchar_t **)(v10 + 48);
  v40 = v17;
  PipGetRegistryDwordWithFallback(
    28,
    v18,
    (__int64)DeviceInstanceKey,
    (__int64)ClassGuid,
    (__int64)InstallerClassKey,
    &DeviceType);
  if( UsePdoCharacteristics || (v19 = (DEVICE_OBJECT *)*((_QWORD *)PhysicalDeviceObject + 3)) == 0i64 )
    v19 = PhysicalDeviceObject;
  v20 = 0;
  while( v19 )
  {
    v20 |= *((_DWORD *)v19 + 13);
    v19 = (DEVICE_OBJECT *)*((_QWORD *)v19 + 3);
  }
  v21 = 0;
  v22 = *(const wchar_t **)(v10 + 48);
  v23 = (DeviceType | v20) & 0x5010F;
  LODWORD(DeviceType) = 0;
  RegistrySecurityWithFallback = PipGetRegistrySecurityWithFallback(
                                   v47 & -(__int64)(v14 != 0),
                                   v22,
                                   (__int64)DeviceInstanceKey,
                                   (unsigned __int64)Sacl & -(__int64)(v14 != 0),
                                   v47 & -(__int64)(v14 != 0));
  v26 = RegistrySecurityWithFallback;
  if( RegistrySecurityWithFallback )
  {
    OwnerSecurityDescriptor = RtlGetOwnerSecurityDescriptor(RegistrySecurityWithFallback, &Owner, &OwnerDefaulted);
    if( OwnerSecurityDescriptor < 0 )
      goto LABEL_22;
    v33 = 0;
    if( Owner )
    {
      v21 = 1;
      v33 = 1;
    }
    OwnerSecurityDescriptor = RtlGetGroupSecurityDescriptor(v26, &Owner, &OwnerDefaulted);
    if( OwnerSecurityDescriptor < 0 )
      goto LABEL_22;
    if( Owner )
    {
      v21 = v33 | 2;
      v33 |= 2u;
    }
    OwnerSecurityDescriptor = RtlGetSaclSecurityDescriptor(v26, &SaclPresent, &Sacl, &OwnerDefaulted);
    if( OwnerSecurityDescriptor < 0 )
      goto LABEL_22;
    if( SaclPresent )
    {
      v21 = v33 | 8;
      v33 |= 8u;
    }
    OwnerSecurityDescriptor = RtlGetDaclSecurityDescriptor(v26, &SaclPresent, &Sacl, &OwnerDefaulted);
    if( OwnerSecurityDescriptor < 0 )
      goto LABEL_22;
    v34 = HIDWORD(DeviceType);
    if( SaclPresent )
      v21 = v33 | 4;
    v27 = v38;
    goto LABEL_41;
  }
  v27 = v38;
  if( v38 )
  {
    v34 = HIDWORD(DeviceType);
    v50 = 0i64;
    *(_OWORD *)AllocatedAcl = 0i64;
    v49 = 0i64;
    LODWORD(v35) = IopCreateDefaultDeviceSecurityDescriptor(
                     HIDWORD(DeviceType),
                     v23,
                     v25,
                     AllocatedAcl,
                     (ACL **)&P,
                     (UINT64 *)&SecurityInformation,
                     (UINT64)&DeviceType);
    v26 = v35;
    if( !v35 )
    {
      v12 = SecurityInformation;
      OwnerSecurityDescriptor = -1073741823;
      goto LABEL_23;
    }
    v21 = DeviceType;
    v39 = 1;
LABEL_41:
    if( v27 )
      *((_DWORD *)PhysicalDeviceObject + 18) = v34;
  }
  if( v40 && v42 )
    *((_DWORD *)PhysicalDeviceObject + 12) |= 8u;
  *((_DWORD *)PhysicalDeviceObject + 13) = v23 | *((_DWORD *)PhysicalDeviceObject + 13) & 0xFFFAFEF0;
  for( i = *((_QWORD *)PhysicalDeviceObject + 3); i; i = *(_QWORD *)(i + 24) )
    *(_DWORD *)(i + 52) |= v23;
  OwnerSecurityDescriptor = 0;
  if( v26 )
    OwnerSecurityDescriptor = ObSetSecurityObjectByPointer(PhysicalDeviceObject, v21, v26);
  v30 = v39;
  v31 = PhysicalDeviceObject;
  do
  {
    if( (*(_DWORD *)(*((_QWORD *)v31 + 1) + 16i64) & 0x100) != 0 )
      *(_DWORD *)(*(_QWORD *)(*((_QWORD *)PhysicalDeviceObject + 39) + 40i64) + 396i64) |= 0xC00000u;
    if( v30 && *((_QWORD *)v31 + 34) )
      *(_DWORD *)(*((_QWORD *)v31 + 39) + 32i64) |= 0x800u;
    v31 = (DEVICE_OBJECT *)*((_QWORD *)v31 + 3);
  }
  while( v31 );
  v12 = SecurityInformation;
LABEL_22:
  if( v26 && !v39 )
    ExFreePoolWithTag(v26, 0);
LABEL_23:
  if( P )
    ExFreePoolWithTag(P, 0);
  if( v12 )
    ExFreePoolWithTag(v12, 0);
  return OwnerSecurityDescriptor;
}

Referenced by:

PipCallDriverAddDevice