IopProcessSetInterfaceState

NTSTATUS __stdcall IopProcessSetInterfaceState(_UNICODE_STRING *SymbolicLinkName, UINT8 dl0, INT8 r8_0){
  char v5; 
  UINT8 v6; 
  VOID **v7; 
  _PI_DM_OBJECT *v8; 
  _DEVICE_OBJECT *v9; 
  _GUID *v10; 
  int v11; 
  WCHAR *v12; 
  int DeviceInterfaceClassGuid; 
  INT64 v14; 
  UINT64 v15; 
  VOID **PoolWithTag; 
  NTSTATUS ObjectProperty; 
  _DEVICE_OBJECT *v18; 
  _DEVICE_NODE *DeviceNode; 
  int State; 
  GUID *v21; 
  __int64 v23; 
  char v24; 
  __int16 v25; 
  UINT64 NumberOfBytes; 
  _PI_DM_OBJECT *Object; 
  int v28; 
  _GUID *ClassGuid; 
  PCWSTR SourceString; 
  _UNICODE_STRING GlobalString; 
  _OBJECT_ATTRIBUTES ObjectAttributes; 
  _UNICODE_STRING DestinationString; 
  _UNICODE_STRING LinkTarget; 
  __int128 v35; 

  v25 = dl0;
  SourceString = 0i64;
  v5 = 0;
  v6 = dl0;
  NumberOfBytes = 0i64;
  v7 = 0i64;
  Object = 0i64;
  v8 = 0i64;
  v9 = 0i64;
  v28 = 0;
  v10 = 0i64;
  ClassGuid = 0i64;
  v24 = 0;
  LinkTarget = 0i64;
  GlobalString = 0i64;
  v35 = 0i64;
  memset(&ObjectAttributes, 0, sizeof(ObjectAttributes));
  DestinationString = 0i64;
  if( !SymbolicLinkName || !SymbolicLinkName->Buffer || !SymbolicLinkName->Length )
  {
    DeviceInterfaceClassGuid = -1073741811;
    goto LABEL_38;
  }
  v11 = PnpUnicodeStringToWstr((__int16 **)&ClassGuid, 0i64, &SymbolicLinkName->Length);
  v10 = ClassGuid;
  DeviceInterfaceClassGuid = v11;
  if( v11 < 0 )
    goto LABEL_44;
  DeviceInterfaceClassGuid = CmGetDeviceInterfaceClassGuid(v12, ClassGuid);
  if( DeviceInterfaceClassGuid < 0 )
    goto LABEL_44;
  DeviceInterfaceClassGuid = IopBuildGlobalSymbolicLinkString(SymbolicLinkName, &GlobalString, v14, v15);
  if( DeviceInterfaceClassGuid < 0 )
    goto LABEL_44;
  PoolWithTag = ExAllocatePoolWithTag(1ui64, 0x190ui64, 538996816i64);
  SourceString = (PCWSTR)PoolWithTag;
  if( !PoolWithTag )
  {
    DeviceInterfaceClassGuid = -1073741670;
    goto LABEL_44;
  }
  ObjectProperty = PnpGetObjectProperty(
                     *(&stru_140CF2E80 + 1214),
                     (INT64)v10,
                     3i64,
                     0i64,
                     0i64,
                     (INT64)&DEVPKEY_Device_InstanceId,
                     (INT64)&NumberOfBytes + 4,
                     (INT64)PoolWithTag);
  DeviceInterfaceClassGuid = ObjectProperty;
  if( ObjectProperty == -1073741275 )
    goto LABEL_64;
  if( ObjectProperty < 0 )
    goto LABEL_44;
  if( HIDWORD(NumberOfBytes) != 18 )
    goto LABEL_64;
  DeviceInterfaceClassGuid = RtlInitUnicodeStringEx(&DestinationString, (WCHAR *)SourceString);
  if( DeviceInterfaceClassGuid < 0 )
    goto LABEL_44;
  v18 = (_DEVICE_OBJECT *)PnpDeviceObjectFromDeviceInstanceWithTag((__int64)&DestinationString, 0x49706E50u);
  v9 = v18;
  if( !v18 )
  {
    if( !(_BYTE)v25 )
    {
      DeviceNode = 0i64;
      goto LABEL_14;
    }
LABEL_64:
    DeviceInterfaceClassGuid = -1073741808;
    goto LABEL_44;
  }
  DeviceNode = (_DEVICE_NODE *)v18->DeviceObjectExtension->DeviceNode;
LABEL_14:
  if( (_BYTE)v25 )
  {
    State = DeviceNode->State;
    if( State <= 769 || State > 781 && (State <= 783 || State != 784) )
      goto LABEL_64;
  }
  if( r8_0 && DeviceNode && (v9->DeviceObjectExtension->ExtensionFlags & 0x10) != 0 )
  {
    if( (_BYTE)v25 )
      DeviceInterfaceClassGuid = PiDeferSetInterfaceState(DeviceNode, SymbolicLinkName);
    else
      PiRemoveDeferredSetInterfaceState((PDEVICE_NODE)DeviceNode, SymbolicLinkName);
    goto LABEL_44;
  }
  if( !(_BYTE)v25 )
  {
    DeviceInterfaceClassGuid = PiDmGetObject(3, (WCHAR *)v10, &Object);
    if( DeviceInterfaceClassGuid >= 0 )
    {
      v8 = Object;
      KsepCacheLock(Object);
      v23 = *((_QWORD *)v8 + 5);
      if( !v23 )
      {
        DeviceInterfaceClassGuid = -1073741772;
        goto LABEL_37;
      }
      ZwClose(v23);
      *((_QWORD *)v8 + 5) = 0i64;
      HIBYTE(v25) = 1;
LABEL_57:
      v24 = 1;
LABEL_37:
      PiDmObjectReleaseLock(v8);
      v5 = HIBYTE(v25);
      v6 = v25;
LABEL_38:
      if( v5 )
      {
        v21 = &GUID_DEVICE_INTERFACE_ARRIVAL;
        if( !v6 )
          v21 = &GUID_DEVICE_INTERFACE_REMOVAL;
        PnpSetDeviceClassChange(v21, &v35, (const VOID **)SymbolicLinkName);
        PnpObjectRaisePropertyChangeEvent(
          *(&stru_140CF2E80 + 607),
          (INT64)v10,
          3i64,
          0i64,
          0i64,
          (__int64)&DEVPKEY_DeviceInterface_Enabled);
      }
      if( v24 )
        PiDmRemoveCacheReferenceForObject(3, (WCHAR *)v10, 0i64);
      goto LABEL_44;
    }
LABEL_60:
    v8 = Object;
    goto LABEL_44;
  }
  LODWORD(NumberOfBytes) = 512;
  while( 1 )
  {
    if( v7 )
      ExFreePoolWithTag(v7, 0);
    v7 = ExAllocatePoolWithTag(1ui64, (unsigned int)NumberOfBytes, 538996816i64);
    if( !v7 )
      break;
    DeviceInterfaceClassGuid = IoGetDeviceProperty(v9, 11, (unsigned int)NumberOfBytes, v7, &NumberOfBytes);
    if( DeviceInterfaceClassGuid != -1073741789 )
      goto LABEL_28;
  }
  DeviceInterfaceClassGuid = -1073741670;
LABEL_28:
  if( DeviceInterfaceClassGuid >= 0 && (_DWORD)NumberOfBytes )
  {
    RtlInitUnicodeString(&LinkTarget, (PCWSTR)v7);
    DeviceInterfaceClassGuid = PiDmAddCacheReferenceForObject(3, (WCHAR *)v10, &Object);
    if( DeviceInterfaceClassGuid >= 0 )
    {
      v8 = Object;
      KsepCacheLock(Object);
      if( (v8[8] & 1) != 0 )
      {
        if( !*((_QWORD *)v8 + 5) )
        {
          ObjectAttributes.RootDirectory = 0i64;
          ObjectAttributes.ObjectName = &GlobalString;
          ObjectAttributes.SecurityQualityOfService = 0i64;
          ObjectAttributes.SecurityDescriptor = (void *)SePublicDefaultUnrestrictedSd;
          ObjectAttributes.Length = 48;
          ObjectAttributes.Attributes = 576;
          DeviceInterfaceClassGuid = ZwOpenSymbolicLinkObject((VOID **)v8 + 5, 983041, &ObjectAttributes);
          if( DeviceInterfaceClassGuid == -1073741772 )
            DeviceInterfaceClassGuid = ZwCreateSymbolicLinkObject(
                                         (VOID **)v8 + 5,
                                         983041,
                                         &ObjectAttributes,
                                         &LinkTarget);
          if( DeviceInterfaceClassGuid >= 0 )
            HIBYTE(v25) = 1;
          goto LABEL_37;
        }
        DeviceInterfaceClassGuid = 0x40000000;
      }
      else
      {
        DeviceInterfaceClassGuid = -1073741772;
      }
      goto LABEL_57;
    }
    goto LABEL_60;
  }
LABEL_44:
  RtlFreeAnsiString(&GlobalString);
  PnpUnicodeStringToWstrFree(v10, (__int64)SymbolicLinkName);
  if( v9 )
    ObfDereferenceObjectWithTag(v9, 0x49706E50ui64);
  if( v7 )
    ExFreePoolWithTag(v7, 0);
  if( SourceString )
    ExFreePoolWithTag((PVOID)SourceString, 0);
  if( v8 )
    PiDmObjectRelease(v8);
  return DeviceInterfaceClassGuid;
}

Referenced by:

IoSetDeviceInterfaceState
IopDoDeferredSetInterfaceState