IopSetDeviceSecurityDescriptor

NTSTATUS __stdcall IopSetDeviceSecurityDescriptor(
        DEVICE_OBJECT *DeviceObject,
        UINT64 *SecurityInformation,
        PVOID SecurityDescriptor,
        POOL_TYPE PoolType,
        GENERIC_MAPPING *GenericMapping){
  _ETHREAD *CurrentThread; 
  UINT64 *v8; 
  _GENERIC_MAPPING *v9; 
  volatile signed __int64 *v11; 
  NTSTATUS v12; 
  UINT64 v13; 
  PVOID OutputSecurityDescriptor; 
  PSECURITY_DESCRIPTOR ObjectsSecurityDescriptor; 
  ObjectsSecurityDescriptor = 0i64;
  OutputSecurityDescriptor = 0i64;
  CurrentThread = (_ETHREAD *)KeGetCurrentThread();
  v8 = SecurityInformation;
  v9 = GenericMapping;
  while( 1 )
  {
    --*((_WORD *)CurrentThread + 242);
    LOBYTE(SecurityInformation) = 1;
    ExAcquireResourceSharedLite(&IopSecurityResource, (BOOL)SecurityInformation);
    v11 = (volatile signed __int64 *)*((_QWORD *)DeviceObject + 34);
    if( v11 && _InterlockedExchangeAdd64(v11 - 3, 1ui64) <= 0 )
      __fastfail(0xEu);
    ExReleaseResourceLite(&IopSecurityResource);
    KeLeaveCriticalRegionThread((__int64)CurrentThread);
    ObjectsSecurityDescriptor = (PSECURITY_DESCRIPTOR)v11;
    v12 = SeSetSecurityDescriptorInfo(0i64, v8, SecurityDescriptor, &ObjectsSecurityDescriptor, PoolType, v9);
    if( v12 < 0 )
      break;
    v12 = ObLogSecurityDescriptor(ObjectsSecurityDescriptor, &OutputSecurityDescriptor, 1ui64);
    ExFreePoolWithTag(ObjectsSecurityDescriptor, 0);
    if( v12 < 0 )
      goto LABEL_13;
    --*((_WORD *)CurrentThread + 242);
    ExAcquireResourceExclusiveLite(&IopSecurityResource, 1u);
    if( *((volatile signed __int64 **)DeviceObject + 34) == v11 )
    {
      *((_QWORD *)DeviceObject + 34) = OutputSecurityDescriptor;
      *(_DWORD *)(*((_QWORD *)DeviceObject + 39) + 32i64) &= ~0x800u;
      ExReleaseResourceLite(&IopSecurityResource);
      KeLeaveCriticalRegionThread((__int64)CurrentThread);
      v13 = 2i64;
LABEL_9:
      ObDereferenceSecurityDescriptor((PVOID)v11, v13);
      return v12;
    }
    ExReleaseResourceLite(&IopSecurityResource);
    KeLeaveCriticalRegionThread((__int64)CurrentThread);
    ObDereferenceSecurityDescriptor((PVOID)v11, 1ui64);
    ObDereferenceSecurityDescriptor(OutputSecurityDescriptor, 1ui64);
  }
  if( v11 )
  {
LABEL_13:
    v13 = 1i64;
    goto LABEL_9;
  }
  return v12;
}

Referenced by:

IopGetSetSecurityObject
IopSetDeviceSecurityDescriptors