Exemple #1
0
        /// <summary>
        /// Create a VBS enclave.
        /// </summary>
        /// <param name="process">The process to create the enclave in.</param>
        /// <param name="size">Size of the enclave.</param>
        /// <param name="flags">Flags for the enclave.</param>
        /// <param name="owner_id">Owner ID. Must be 32 bytes.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The created enclave.</returns>
        public static NtResult <NtEnclaveVBS> Create(
            SafeKernelObjectHandle process,
            long size,
            LdrEnclaveVBSFlags flags,
            byte[] owner_id,
            bool throw_on_error)
        {
            if (owner_id is null)
            {
                owner_id = new byte[32];
            }

            if (owner_id.Length != 32)
            {
                throw new ArgumentException("Owner ID must be 32 bytes.", nameof(owner_id));
            }

            IntPtr base_address_value = IntPtr.Zero;
            var    create_info        = new EnclaveCreateInfoVBS()
            {
                Flags   = flags,
                OwnerID = owner_id
            };

            using (var buffer = create_info.ToBuffer())
            {
                return(NtLdrNative.LdrCreateEnclave(process, ref base_address_value,
                                                    IntPtr.Zero, new IntPtr(size), IntPtr.Zero,
                                                    LdrEnclaveType.VBS, buffer, buffer.Length, out int error)
                       .CreateResult(throw_on_error, () => new NtEnclaveVBS(new SafeEnclaveHandle(base_address_value), process)));
            }
        }
Exemple #2
0
 /// <summary>
 /// Create a VBS enclave.
 /// </summary>
 /// <param name="process">The process to create the enclave in.</param>
 /// <param name="size">Size of the enclave.</param>
 /// <param name="flags">Flags for the enclave.</param>
 /// <param name="owner_id">Owner ID. Must be 32 bytes.</param>
 /// <returns>The created enclave.</returns>
 public static NtEnclaveVBS Create(
     SafeKernelObjectHandle process,
     long size,
     LdrEnclaveVBSFlags flags,
     byte[] owner_id)
 {
     return(Create(process, size, flags, owner_id, true).Result);
 }