private protected NtResult <O> ReOpen <O, X>(NtObjectWithDuplicate <O, X> obj) where O : NtObject where X : Enum
        {
            AccessMask mask = GenericAccessRights.MaximumAllowed;

            using (var o = obj.ReOpen(mask.ToSpecificAccess <X>(), false))
            {
                if (o.IsSuccess)
                {
                    return(o.Map(x => (O)x.DuplicateObject()));
                }
            }

            AccessMask granted_mask = 0;
            AccessMask valid_access = obj.NtType.ValidAccess;
            uint       test_mask    = 1;

            while (test_mask < 0x00200000)
            {
                if (valid_access.IsAccessGranted(test_mask))
                {
                    mask = test_mask;
                    using (var o = obj.ReOpen(mask.ToSpecificAccess <X>(), false))
                    {
                        if (o.IsSuccess)
                        {
                            granted_mask |= test_mask;
                        }
                    }
                }

                test_mask <<= 1;
            }

            if (granted_mask.IsEmpty)
            {
                return(NtResult <O> .CreateResultFromError(NtStatus.STATUS_ACCESS_DENIED, false));
            }
            return(obj.ReOpen(granted_mask.ToSpecificAccess <X>(), false));
        }
コード例 #2
0
        private protected NtResult <SecurityDescriptor> GetSecurityDescriptorReOpen <O, X>(NtObjectWithDuplicate <O, X> obj) where O : NtObject where X : Enum
        {
            AccessMask desired_access = GenericAccessRights.ReadControl;

            if (HasSecurityPrivilege())
            {
                desired_access |= GenericAccessRights.AccessSystemSecurity;
            }

            using (var o = obj.ReOpen(desired_access.ToSpecificAccess <X>(), false))
            {
                if (o.IsSuccess)
                {
                    return(GetSecurityDescriptor(o.Result));
                }
            }
            return(GetSecurityDescriptor(obj));
        }