PiPnpRtlSetObjectProperty

NTSTATUS __stdcall PiPnpRtlSetObjectProperty(
        WCHAR *ObjectName,
        PNP_OBJECT_TYPE ObjectType,
        VOID *ObjectBaseKey,
        WCHAR *PropertyLocaleName,
        _DEVPROPKEY *PropertyKey,
        UINT64 PropertyType,
        UINT8 *PropertyBuffer,
        UINT64 PropertySize){
  ULONG v8; 
  unsigned int v9; 
  WCHAR *v10; 
  int v11; 
  int v12; 
  DEVPROPKEY **v13; 
  unsigned int i; 
  DEVPROPKEY *v15; 
  __int64 v16; 
  INT64 v17; 
  PNP_AUDIT_OPERATION_TYPE v18; 
  int v19; 
  HPNPCTX *v20; 
  NTSTATUS v21; 
  unsigned int v22; 
  int v23; 
  __int64 v25; 
  __int64 v26; 
  int v27; 
  __int64(**v28)[3]; 
  unsigned int v29; 
  __int64(*v30)[3]; 
  __int64 v31; 
  bool v32; 
  __int64 v33; 
  __int64 v34; 
  __int64 v35; 
  _ETHREAD *CurrentThread; 
  __int64 v37; 
  __int64 v38; 
  __int64 v39; 
  __int64 v40; 
  __int64 v41; 
  INT64 v42; 
  __int64 v43; 
  __int64 v44; 
  bool v45; 
  INT64 v46; 
  INT64 v47; 
  char v48; 
  UINT64 v49; 
  UINT8 v50[4]; 
  INT64 CmRegPropType; 
  UINT64 NewConfigFlags; 
  INT64 v53; 
  UINT64 a4; 
  HPNPCTX *hPnpCtx; 
  _UNICODE_STRING DestinationString; 
  __int64 v57; 
  INT64 v58[2]; 
  _GUID Guid; 
  unsigned int v60; 
  int v61; 

  v8 = (unsigned int)ObjectName;
  hPnpCtx = (HPNPCTX *)ObjectName;
  v9 = (unsigned int)ObjectBaseKey;
  v53 = (INT64)PropertyLocaleName;
  v57 = (__int64)PropertyKey;
  v10 = *(WCHAR **)&ObjectType;
  v11 = 0;
  a4 = 0i64;
  v49 = 0i64;
  *(_DWORD *)v50 = 0;
  LODWORD(NewConfigFlags) = 0;
  CmRegPropType = 0i64;
  v48 = 0;
  DestinationString = 0i64;
  Guid = 0i64;
  *(_OWORD *)v58 = 0i64;
  if( (_DWORD)ObjectBaseKey != 1 )
  {
    if( (_DWORD)ObjectBaseKey == 3 )
    {
      if( *(_DWORD *)(PropertyType + 16) == 256 )
      {
        v44 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_InstanceId.fmtid.Data1;
        if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_InstanceId.fmtid.Data1 )
          v44 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_InstanceId.fmtid.Data4;
        v45 = v44 == 0;
LABEL_95:
        if( v45 )
          return -1073741790;
      }
    }
    else if( (_DWORD)ObjectBaseKey == 5 )
    {
      v27 = *(_DWORD *)(PropertyType + 16);
      v28 = PiPnpRtlContainerReadOnlyProps;
      v29 = 0;
      while( 1 )
      {
        v30 = *v28;
        if( v27 == LODWORD((**v28)[2]) )
        {
          v40 = *(_QWORD *)PropertyType - (*v30)[0];
          if( *(_QWORD *)PropertyType == (*v30)[0] )
            v40 = *(_QWORD *)(PropertyType + 8) - (*v30)[1];
          if( !v40 )
            return -1073741790;
        }
        ++v29;
        ++v28;
        if( v29 >= 2 )
        {
          if( v27 == 105 )
          {
            v31 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_DeviceContainer_ConfigFlags.fmtid.Data1;
            if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_DeviceContainer_ConfigFlags.fmtid.Data1 )
              v31 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_DeviceContainer_ConfigFlags.fmtid.Data4;
            if( !v31 )
            {
              v32 = (_DWORD)PropertyBuffer == 7;
              goto LABEL_43;
            }
          }
          break;
        }
      }
    }
LABEL_9:
    v16 = *(_QWORD *)DEVPKEY_Device_ConfigFlags.fmtid.Data4;
    v17 = *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1;
    goto LABEL_10;
  }
  v12 = *(_DWORD *)(PropertyType + 16);
  v13 = PiPnpRtlDeviceReadOnlyProps;
  for( i = 0; i < 0xD; ++i )
  {
    v15 = *v13;
    if( v12 == (*v13)->pid )
    {
      v26 = *(_QWORD *)PropertyType - *(_QWORD *)&v15->fmtid.Data1;
      if( *(_QWORD *)PropertyType == *(_QWORD *)&v15->fmtid.Data1 )
        v26 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)v15->fmtid.Data4;
      if( !v26 )
        return -1073741790;
    }
    ++v13;
  }
  if( v12 != 12 )
  {
    if( v12 == 3 )
    {
      v34 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_HardwareIds.fmtid.Data1;
      if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_HardwareIds.fmtid.Data1 )
        v34 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_HardwareIds.fmtid.Data4;
      if( !v34 )
        goto LABEL_94;
    }
    if( v12 == 4 )
    {
      v39 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_CompatibleIds.fmtid.Data1;
      if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_CompatibleIds.fmtid.Data1 )
        v39 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_CompatibleIds.fmtid.Data4;
      if( !v39 )
      {
LABEL_94:
        v45 = CmIsRootEnumeratedDevice(v10) == 0;
        goto LABEL_95;
      }
    }
    else if( v12 == 2 )
    {
      v33 = *(_QWORD *)PropertyType - DEVPKEY_Device_PanelId;
      if( *(_QWORD *)PropertyType == DEVPKEY_Device_PanelId )
        v33 = *(_QWORD *)(PropertyType + 8) + 0x5292C1A216403965i64;
      if( !v33 )
      {
        if( !PropertySize
          || v60 < 2
          || (_DWORD)PropertyBuffer != 18
          || *(_WORD *)(PropertySize + 2 * ((unsigned __int64)v60 >> 1) - 2)
          || CmSplitDevicePanelId((STRSAFE_PCNZWCH)PropertySize, &Guid, (UINT64 *)((char *)&a4 + 4), &a4) < 0
          || PnpGetObjectProperty(
               v8,
               (INT64)v10,
               1i64,
               v53,
               0i64,
               (INT64)&DEVPKEY_Device_ContainerId,
               (INT64)&v49 + 4,
               (INT64)v58) < 0
          || v49 != 0xD00000010i64 )
        {
          return -1073741811;
        }
        v46 = v58[0] - *(_QWORD *)&Guid.Data1;
        if( v58[0] == *(_QWORD *)&Guid.Data1 )
          v46 = v58[1] - *(_QWORD *)Guid.Data4;
        v32 = v46 == 0;
LABEL_43:
        if( !v32 )
          return -1073741811;
      }
    }
    goto LABEL_9;
  }
  v17 = *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1;
  v16 = *(_QWORD *)DEVPKEY_Device_ConfigFlags.fmtid.Data4;
  v41 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1;
  if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1 )
    v41 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_ConfigFlags.fmtid.Data4;
  if( !v41 && (!PropertySize || v60 != 4) )
    return -1073741811;
LABEL_10:
  v18 = PNP_AUDIT_OPERATION_INSTALL_BLOCKED;
  if( v9 == 1 )
  {
    v19 = *(_DWORD *)(PropertyType + 16);
    switch( v19 )
    {
      case 10:
        v35 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_ClassGuid.fmtid.Data1;
        if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_ClassGuid.fmtid.Data1 )
          v35 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_ClassGuid.fmtid.Data4;
        if( !v35 )
        {
          CurrentThread = (_ETHREAD *)KeGetCurrentThread();
          --CurrentThread->Tcb.KernelApcDisable;
          ExAcquireResourceExclusiveLite((UINT64)&PnpReplaceEvent + 6688, 1, v17);
          v48 = 1;
        }
        break;
      case 12:
        v42 = *(_QWORD *)PropertyType - v17;
        if( *(_QWORD *)PropertyType == v17 )
          v42 = *(_QWORD *)(PropertyType + 8) - v16;
        if( !v42 && SeAuditingWithTokenForSubcategory(137i64, 0i64) )
        {
          LODWORD(v47) = 0;
          LODWORD(v49) = 4;
          if( CmGetDeviceRegProp(
                 hPnpCtx,
                 v10,
                 (VOID *)v53,
                 11i64,
                 (UINT64 *)((char *)&CmRegPropType + 4),
                 v50,
                 &v49,
                 v47) < 0
            || (_DWORD)v49 != 4
            || HIDWORD(CmRegPropType) != 4 )
          {
            *(_DWORD *)v50 = 0;
          }
          LODWORD(NewConfigFlags) = *(_DWORD *)PropertySize;
        }
        break;
      case 5:
        v37 = *(_QWORD *)PropertyType - DEVPKEY_Device_InstallError;
        if( *(_QWORD *)PropertyType == DEVPKEY_Device_InstallError )
          v37 = *(_QWORD *)(PropertyType + 8) - 0x293B573F92A15394i64;
        if( !v37 && SeAuditingWithTokenForSubcategory(137i64, 0i64) )
        {
          LODWORD(v49) = 4;
          if( PnpGetObjectProperty(
                 (ULONG)hPnpCtx,
                 (INT64)v10,
                 1i64,
                 v53,
                 0i64,
                 (INT64)&DEVPKEY_Device_InstallError,
                 (INT64)&v49 + 4,
                 (INT64)&CmRegPropType) < 0
            || v49 != 0x1700000004i64 )
          {
            LODWORD(CmRegPropType) = 0;
          }
          if( v60 == 4 && (_DWORD)PropertyBuffer == 23 )
            v11 = *(_DWORD *)PropertySize;
        }
        break;
    }
  }
  v20 = hPnpCtx;
  v21 = PnpSetObjectProperty(
          (INT64)hPnpCtx,
          (INT64)v10,
          v9,
          v53,
          v57,
          PropertyType,
          (int)PropertyBuffer,
          PropertySize,
          v60,
          v61);
  v22 = v9 - 1;
  if( v22 )
  {
    if( v22 == 2 && v21 >= 0 && *(_DWORD *)(PropertyType + 16) == 9 )
    {
      v25 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_PhysicalDeviceLocation.fmtid.Data1;
      if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_PhysicalDeviceLocation.fmtid.Data1 )
        v25 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_PhysicalDeviceLocation.fmtid.Data4;
      if( !v25 )
        CmUpdateDevicePanelInterface(v20, v10, (VOID *)v53);
    }
    goto LABEL_17;
  }
  v23 = *(_DWORD *)(PropertyType + 16);
  if( v23 == 12 )
  {
    v43 = *(_QWORD *)PropertyType - *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1;
    if( *(_QWORD *)PropertyType == *(_QWORD *)&DEVPKEY_Device_ConfigFlags.fmtid.Data1 )
      v43 = *(_QWORD *)(PropertyType + 8) - *(_QWORD *)DEVPKEY_Device_ConfigFlags.fmtid.Data4;
    if( !v43 && SeAuditingWithTokenForSubcategory(137i64, 0i64) )
    {
      RtlInitUnicodeString(&DestinationString, v10);
      PiAuditDeviceEnableDisableRequest(
        &DestinationString,
        *(unsigned int *)v50,
        (unsigned int)NewConfigFlags,
        v21 >= 0);
    }
    goto LABEL_17;
  }
  if( v23 == 5 )
  {
    v38 = *(_QWORD *)PropertyType - DEVPKEY_Device_InstallError;
    if( *(_QWORD *)PropertyType == DEVPKEY_Device_InstallError )
      v38 = *(_QWORD *)(PropertyType + 8) - 0x293B573F92A15394i64;
    if( !v38 && SeAuditingWithTokenForSubcategory(137i64, 0i64) )
    {
      RtlInitUnicodeString(&DestinationString, v10);
      if( (_DWORD)CmRegPropType == -536870328 )
      {
        if( v11 == -536870328 )
          goto LABEL_17;
        v18 = PNP_AUDIT_OPERATION_INSTALL_UNBLOCKED;
      }
      else if( v11 != -536870328 )
      {
        goto LABEL_17;
      }
      PiAuditDeviceOperation(&DestinationString, v18, v21 >= 0);
    }
  }
LABEL_17:
  if( v48 )
  {
    ExReleaseResourceLite((PERESOURCE)((char *)&PnpReplaceEvent + 6688));
    KeLeaveCriticalRegionThread(KeGetCurrentThread());
  }
  return v21;
}

Referenced by:

PiCMSetObjectProperty
PiDevCfgSetObjectProperty
PiDqIrpPropertySet
PiSwPropertySet
PnpSetDeviceInterfacePropertyData
PnpSetDevicePropertyData