CmSetDeviceRegPropWorker

NTSTATUS __stdcall CmSetDeviceRegPropWorker(
        HPNPCTX *hPnpCtx,
        WCHAR *DeviceInstanceId,
        VOID *BaseKeyHandle,
        _CM_REG_PROP CmRegProp,
        UINT64 CmRegPropType,
        UINT8 *SecurityDescriptorInput,
        UINT64 SecurityDescriptorLength,
        UINT64 Flags){
  int inited; 
  UINT8 *v13; 
  int v14; 
  HPNPCTX *v15; 
  wchar_t *v16; 
  VOID *v17; 
  NTSTATUS v18; 
  VOID *v19; 
  VOID *v21; 
  _OBJECT_TYPE *v22; 
  UINT64 CmRegPropa; 
  _CM_REG_PROP Create; 
  VOID *Handle; 
  _UNICODE_STRING DestinationString; 

  inited = 0;
  Handle = 0i64;
  if( (_WORD)Flags )
    return -1073741811;
  if( (_DWORD)SecurityDescriptorLength )
  {
    v13 = SecurityDescriptorInput;
    if( !SecurityDescriptorInput )
      return -1073741811;
  }
  else
  {
    v13 = 0i64;
  }
  if( (unsigned int)(CmRegProp - 1) > 0x24 || !CmDevicePropertyRead((INT64)hPnpCtx, (unsigned int)CmRegProp) )
    goto LABEL_54;
  if( !CmDevicePropertyWrite() )
    return -1073741790;
  v14 = MapCmDevicePropertyToRegType(CmRegProp);
  if( !v14 )
    return -1073741264;
  if( (_DWORD)CmRegPropType != v14 )
    return -1073741811;
  if( CmRegProp == CM_REG_PROP_CONFIGFLAGS )
  {
    if( !(_DWORD)SecurityDescriptorLength )
      goto LABEL_12;
    if( v13 && (_DWORD)SecurityDescriptorLength == 4 )
    {
      if( *(_DWORD *)v13 && CmIsRootDevice(DeviceInstanceId) )
        return -1073741808;
      goto LABEL_12;
    }
    return -1073741811;
  }
  if( CmRegProp == CM_REG_PROP_CLASS )
  {
    if( (unsigned int)SecurityDescriptorLength <= 0x40 )
      goto LABEL_12;
    return -1073741811;
  }
  if( CmRegProp == CM_REG_PROP_SECURITY
    && (_DWORD)SecurityDescriptorLength
    && (!RtlValidRelativeSecurityDescriptor((INT64)v13, (unsigned int)SecurityDescriptorLength, 0)
     || RtlLengthSecurityDescriptor((INT64)v13) != (_DWORD)SecurityDescriptorLength) )
  {
    inited = -1073741811;
    goto LABEL_25;
  }
LABEL_12:
  if( BaseKeyHandle
    || (LODWORD(CmRegPropa) = 33554434,
        inited = CmOpenDeviceRegKey(
                   hPnpCtx,
                   DeviceInstanceId,
                   CM_KEY_TYPE_DEVICE_INSTANCE,
                   0i64,
                   CmRegPropa,
                   0,
                   &Handle,
                   0i64),
        inited >= 0) )
  {
    if( CmRegProp == CM_REG_PROP_CLASS )
      goto LABEL_21;
    v16 = (wchar_t *)MapCmDevicePropertyToRegValue(v15, CmRegProp);
    if( v16 )
    {
      if( (_DWORD)SecurityDescriptorLength )
      {
        v17 = Handle;
        if( BaseKeyHandle )
          v17 = BaseKeyHandle;
        LODWORD(CmRegPropa) = SecurityDescriptorLength;
        v18 = RegRtlSetValue(v17, v16, CmRegPropType, v13, CmRegPropa);
        if( v18 == -1073741444 )
        {
          inited = -1073741810;
          goto LABEL_25;
        }
        if( v18 < 0 )
          inited = v18;
      }
      else
      {
        v21 = Handle;
        DestinationString = 0i64;
        if( BaseKeyHandle )
          v21 = BaseKeyHandle;
        inited = RtlInitUnicodeStringEx(&DestinationString, v16);
        if( inited >= 0 )
          inited = ZwDeleteValueKey(v21, &DestinationString, v22);
        if( inited == -1073741772 || inited == -1073741444 )
          inited = -1073741275;
      }
LABEL_21:
      if( inited >= 0 )
      {
        v19 = Handle;
        if( BaseKeyHandle )
          v19 = BaseKeyHandle;
        CmRaisePropertyChangeEvent(hPnpCtx, DeviceInstanceId, CM_OBJECT_TYPE_DEVICE, v19, CmRegProp, Create);
      }
      goto LABEL_25;
    }
LABEL_54:
    inited = -1073741264;
  }
LABEL_25:
  if( Handle )
    ZwClose((_HANDLE)Handle);
  return inited;
}

Referenced by:

CmSetDeviceRegProp