public static extern NtStatus NtQueryWnfStateData(
     ref ulong StateName,
     [In, Optional] WnfTypeId TypeId,
     [Optional] IntPtr ExplicitScope,
     out int ChangeStamp,
     SafeBuffer Buffer,
     ref int BufferSize
     );
Exemplo n.º 2
0
 /// <summary>
 /// Update state data for the WNF object.
 /// </summary>
 /// <param name="data">The data to set.</param>
 /// <param name="type_id">Optional Type ID.</param>
 /// <param name="explicit_scope">Optional explicit scope.</param>
 /// <param name="matching_changestamp">Optional matching changestamp.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The status from the update.</returns>
 public NtStatus UpdateStateData(byte[] data, WnfTypeId type_id, IntPtr explicit_scope, int?matching_changestamp, bool throw_on_error)
 {
     using (var buffer = data.ToBuffer()) {
         return(NtSystemCalls.NtUpdateWnfStateData(StateName, buffer,
                                                   buffer.Length, type_id, explicit_scope,
                                                   matching_changestamp ?? 0, matching_changestamp.HasValue).ToNtException(throw_on_error));
     }
 }
Exemplo n.º 3
0
 public static extern NtStatus NtQueryWnfStateData(
     ref WnfStateName StateName,
     ref WnfTypeId TypeId,
     IntPtr ExplicitScope,
     uint ChangeStamp,
     IntPtr Buffer,
     out int BufferSize
     );
 public static extern NtStatus NtCreateWnfStateName(
     out ulong StateName,
     WnfStateNameLifetime NameLifetime,
     WnfDataScope DataScope,
     bool PersistData,
     [In, Optional] WnfTypeId TypeId,
     int MaximumStateSize,
     SafeBuffer SecurityDescriptor
     );
 public static extern NtStatus NtUpdateWnfStateData(
     ref ulong StateName,
     SafeBuffer Buffer,
     int Length,
     [In, Optional] WnfTypeId TypeId,
     [Optional] IntPtr ExplicitScope,
     int MatchingChangeStamp,
     [MarshalAs(UnmanagedType.Bool)] bool CheckChangeStamp
     );
Exemplo n.º 6
0
 public static extern NtStatus NtCreateWnfStateName(
     ref WnfStateName StateName,
     WnfStateNameLifetime NameLifetime,
     WnfDataScope DataScope,
     bool PersistData,
     ref WnfTypeId TypeId,
     uint MaximumStateSize,
     SafeBuffer SecurityDescriptor
     );
 /// <summary>
 /// Create a new WNF state name.
 /// </summary>
 /// <param name="name_lifetime">The lifetime of the name.</param>
 /// <param name="data_scope">The scope of the data.</param>
 /// <param name="persist_data">Whether to persist data.</param>
 /// <param name="type_id">Optional type ID.</param>
 /// <param name="maximum_state_size">Maximum state size.</param>
 /// <param name="security_descriptor">Mandatory security descriptor.</param>
 /// <returns>The created object.</returns>
 public static NtWnf Create(
     WnfStateNameLifetime name_lifetime,
     WnfDataScope data_scope,
     bool persist_data,
     WnfTypeId type_id,
     int maximum_state_size,
     SecurityDescriptor security_descriptor)
 {
     return(Create(name_lifetime, data_scope, persist_data, type_id, maximum_state_size, security_descriptor, true).Result);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Query state data for the WNF object.
        /// </summary>
        /// <param name="type_id">Optional Type ID.</param>
        /// <param name="explicit_scope">Optional explicit scope.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The state data.</returns>
        public NtResult <WnfStateData> QueryStateData(WnfTypeId type_id, IntPtr explicit_scope, bool throw_on_error)
        {
            int tries = 10;
            int size  = 4096;

            while (tries-- > 0)
            {
                using (var buffer = new SafeHGlobalBuffer(size)) {
                    NtStatus status = NtSystemCalls.NtQueryWnfStateData(StateName, type_id,
                                                                        explicit_scope, out int changestamp, buffer, ref size);
                    if (status == NtStatus.STATUS_BUFFER_TOO_SMALL)
                    {
                        continue;
                    }

                    return(status.CreateResult(throw_on_error, () => new WnfStateData(buffer.ReadBytes(size), changestamp)));
                }
            }

            return(NtStatus.STATUS_BUFFER_TOO_SMALL.CreateResultFromError <WnfStateData>(throw_on_error));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Create a new WNF state name.
 /// </summary>
 /// <param name="name_lifetime">The lifetime of the name.</param>
 /// <param name="data_scope">The scope of the data.</param>
 /// <param name="persist_data">Whether to persist data.</param>
 /// <param name="type_id">Optional type ID.</param>
 /// <param name="maximum_state_size">Maximum state size.</param>
 /// <param name="security_descriptor">Mandatory security descriptor.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The created object.</returns>
 public static NtResult <NtWnf> Create(
     WnfStateNameLifetime name_lifetime,
     WnfDataScope data_scope,
     bool persist_data,
     WnfTypeId type_id,
     int maximum_state_size,
     SecurityDescriptor security_descriptor,
     bool throw_on_error)
 {
     if (security_descriptor == null)
     {
         throw new ArgumentNullException("Must specify a security descriptor");
     }
     using (var sd_buffer = security_descriptor.ToSafeBuffer()) {
         return(NtSystemCalls.NtCreateWnfStateName(out ulong state_name, name_lifetime,
                                                   data_scope, persist_data, type_id, maximum_state_size, sd_buffer)
                .CreateResult(throw_on_error, () => new NtWnf(state_name)
         {
             _security_descriptor = security_descriptor
         }));
     }
 }
 /// <summary>
 /// Query state data for the WNF object.
 /// </summary>
 /// <param name="type_id">Optional Type ID.</param>
 /// <param name="explicit_scope">Optional explicit scope.</param>
 /// <returns>The state data.</returns>
 public WnfStateData QueryStateData(WnfTypeId type_id, IntPtr explicit_scope)
 {
     return(QueryStateData(type_id, explicit_scope, true).Result);
 }
 public static extern NtStatus NtQueryWnfStateData(
      ref WnfStateName StateName,
      ref WnfTypeId TypeId,
      IntPtr ExplicitScope,
      uint ChangeStamp,
      IntPtr Buffer,
      out int BufferSize
  );
 public static extern NtStatus NtCreateWnfStateName(
     ref WnfStateName StateName,
     WnfStateNameLifetime NameLifetime,
     WnfDataScope DataScope,
     bool PersistData,
     ref WnfTypeId TypeId,
     uint MaximumStateSize,
     IntPtr SecurityDescriptor
 );