CmDeleteDeviceInterfaceWorker

NTSTATUS __stdcall CmDeleteDeviceInterfaceWorker(
        HPNPCTX *hPnpCtx,
        WCHAR *DeviceInterfaceName,
        WCHAR *Flags,
        UINT64 a4,
        UINT64 a5,
        INT64 a6,
        INT64 a7,
        INT64 a8,
        INT64 a9){
  NTSTATUS v9; 
  int *v12; 
  unsigned int v13; 
  int v14; 
  NTSTATUS v15; 
  INT64 v16; 
  VOID **PoolWithTag; 
  unsigned int v18; 
  NTSTATUS DeviceInterfaceMappedPropertyKeys; 
  INT64 v20; 
  __int64 v21; 
  NTSTATUS v22; 
  INT64 v23; 
  _CM_OBJECT_TYPE v24; 
  unsigned int v26; 
  UINT64 BufferLength; 
  UINT64 v28; 
  UINT64 PropertyCount; 
  int v30[4]; 

  v9 = 0;
  if( (_WORD)Flags )
    return -1073741811;
  v30[0] = 768;
  v12 = v30;
  v30[1] = 512;
  v13 = 0;
  v30[2] = 256;
  while( 1 )
  {
    v14 = *v12;
    v15 = CmDeleteDeviceInterfaceRegKey((UINT64)hPnpCtx, (INT64)DeviceInterfaceName, *v12 | 0x30u, a4, 1);
    if( v15 )
    {
      if( v15 != -1073741637 && v15 != -1073741772 && v15 != -1073741811 )
        break;
    }
    v15 = CmDeleteDeviceInterfaceRegKey((UINT64)hPnpCtx, (INT64)DeviceInterfaceName, v14 | 0x31u, v16, 0);
    if( v15 )
    {
      if( v15 != -1073741637 && v15 != -1073741772 && v15 != -1073741811 && v15 != -1073741535 )
        break;
    }
    ++v13;
    ++v12;
    if( v13 >= 3 )
      goto LABEL_8;
  }
  v9 = v15;
  if( v15 < 0 )
    return v9;
LABEL_8:
  PoolWithTag = 0i64;
  v18 = 0;
  LODWORD(PropertyCount) = 0;
  do
  {
    LODWORD(BufferLength) = v18;
    DeviceInterfaceMappedPropertyKeys = CmGetDeviceInterfaceMappedPropertyKeys(
                                          hPnpCtx,
                                          DeviceInterfaceName,
                                          0i64,
                                          1u,
                                          (_DEVPROPKEY *)PoolWithTag,
                                          BufferLength,
                                          &PropertyCount);
    v18 = PropertyCount;
    if( DeviceInterfaceMappedPropertyKeys != -1073741789 )
      goto LABEL_10;
    v26 = 20 * PropertyCount;
    if( 20 * (unsigned __int64)(unsigned int)PropertyCount > 0xFFFFFFFF )
    {
      DeviceInterfaceMappedPropertyKeys = -1073741811;
      goto LABEL_32;
    }
    if( PoolWithTag )
      ExFreePoolWithTag(PoolWithTag, 0);
    PoolWithTag = ExAllocatePoolWithTag(1ui64, v26, 1380994640i64);
  }
  while( PoolWithTag );
  DeviceInterfaceMappedPropertyKeys = -1073741801;
LABEL_10:
  if( DeviceInterfaceMappedPropertyKeys && DeviceInterfaceMappedPropertyKeys != -1073741275 )
  {
LABEL_32:
    v9 = DeviceInterfaceMappedPropertyKeys;
    goto LABEL_19;
  }
  v21 = 0i64;
  if( v18 )
  {
    while( 1 )
    {
      LODWORD(v28) = 0;
      LODWORD(BufferLength) = 0;
      v22 = CmSetDeviceInterfaceMappedProperty(
              hPnpCtx,
              DeviceInterfaceName,
              0i64,
              0i64,
              (_DEVPROPKEY *)PoolWithTag + v21,
              BufferLength,
              0i64,
              v28);
      if( v22 )
      {
        if( v22 != -1073741790 && v22 != -1073741275 && v22 != -1073741802 && v22 != -1073741637 )
          break;
      }
      v21 = (unsigned int)(v21 + 1);
      if( (unsigned int)v21 >= v18 )
        goto LABEL_15;
    }
    v9 = v22;
  }
LABEL_15:
  if( v9 >= 0 )
  {
    DeviceInterfaceMappedPropertyKeys = CmDeleteDeviceInterfaceRegKey(
                                          (UINT64)hPnpCtx,
                                          (INT64)DeviceInterfaceName,
                                          0x30ui64,
                                          v20,
                                          1);
    if( !DeviceInterfaceMappedPropertyKeys
      || DeviceInterfaceMappedPropertyKeys == -1073741772
      || DeviceInterfaceMappedPropertyKeys == -1073741811 )
    {
      DeviceInterfaceMappedPropertyKeys = CmDeleteDeviceInterfaceRegKey(
                                            (UINT64)hPnpCtx,
                                            (INT64)DeviceInterfaceName,
                                            0x31ui64,
                                            v23,
                                            0);
      if( !DeviceInterfaceMappedPropertyKeys
        || DeviceInterfaceMappedPropertyKeys == -1073741772
        || DeviceInterfaceMappedPropertyKeys == -1073741811
        || DeviceInterfaceMappedPropertyKeys == -1073741535 )
      {
        CmRaiseDeleteEvent(hPnpCtx, DeviceInterfaceName, CM_OBJECT_TYPE_DEVICE_INTERFACE, v24);
        goto LABEL_19;
      }
    }
    goto LABEL_32;
  }
LABEL_19:
  if( PoolWithTag )
    ExFreePoolWithTag(PoolWithTag, 0);
  return v9;
}

Referenced by:

CmDeleteDeviceInterface