public static extern NtStatus NtQuerySystemInformationEx(
     SystemInformationClass SystemInformationClass,
     SafeBuffer InputBuffer,
     int InputBufferLength,
     SafeBuffer SystemInformation,
     int SystemInformationLength,
     out int ReturnLength);
Exemplo n.º 2
0
 public static extern NtStatus NtQuerySystemInformation(
     [In] SystemInformationClass systemInformationClass,
     IntPtr systemInformation,
     [In] int systemInformationLength,
     // ReSharper disable once OptionalParameterRefOut
     [Out][Optional] out int returnLength
     );
        private static void AllocateSafeBuffer(SafeHGlobalBuffer buffer, SystemInformationClass info_class)
        {
            NtStatus status        = 0;
            int      return_length = 0;

            while ((status = NtSystemCalls.NtQuerySystemInformation(info_class,
                                                                    buffer,
                                                                    buffer.Length,
                                                                    out return_length)) == NtStatus.STATUS_INFO_LENGTH_MISMATCH)
            {
                int length = buffer.Length * 2;
                buffer.Resize(length);
            }
            status.ToNtException();
        }
Exemplo n.º 4
0
 private static T QueryCached <T>(SystemInformationClass info_class) where T : new()
 {
     if (!_cached_info.ContainsKey(info_class))
     {
         var value = Query(info_class, default(T), false);
         if (value.IsSuccess)
         {
             _cached_info[info_class] = value.Result;
         }
         else
         {
             _cached_info[info_class] = default(T);
         }
     }
     return((T)_cached_info[info_class]);
 }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="InfoClass"></param>
        /// <param name="Info"></param>
        /// <param name="InfoLength"></param>
        /// <param name="ReturnLength"></param>
        /// <returns></returns>
        public static NTSTATUS NtQuerySystemInformation(SystemInformationClass InfoClass, IntPtr Info, uint InfoLength, out uint ReturnLength, [CallerMemberName] string callerName = "")
        {
            if (!PInvokeDebugger.LoggingEnabled)
            {
                return(PInvoke_NtQuerySystemInformation(InfoClass, Info, InfoLength, out ReturnLength));
            }

            NTSTATUS         returnValue = PInvoke_NtQuerySystemInformation(InfoClass, Info, InfoLength, out ReturnLength);
            PInvokeDebugInfo debugInfo   = PInvokeDebugInfo.TraceDebugInfo(
                ModuleName,
                nameof(NtQuerySystemInformation),
                callerName,
                returnValue,
                nameof(InfoClass), InfoClass,
                nameof(Info), Info,
                nameof(InfoLength), InfoLength,
                nameof(ReturnLength), ReturnLength
                );

            PInvokeDebugger.SafeCapture(debugInfo);
            return(returnValue);
        }
Exemplo n.º 6
0
        public static IntPtr NtQuerySystemInformation(SystemInformationClass systemInformationClass, uint infoLength = 0)
        {
            if (infoLength == 0)
            {
                infoLength = 0x10000;
            }

            var infoPtr = Marshal.AllocHGlobal((int)infoLength);

            var tries = 0;

            while (true)
            {
                var result = NtQuerySystemInformation(SystemInformationClass.SystemHandleInformation, infoPtr, infoLength, out infoLength);

                if (result == NtStatus.Success)
                {
                    return(infoPtr);
                }

                Marshal.FreeHGlobal(infoPtr);  //free pointer when not Successful

                if (result != NtStatus.InfoLengthMismatch && result != NtStatus.BufferOverflow && result != NtStatus.BufferTooSmall)
                {
                    //throw new Exception("Unhandled NtStatus " + result);
                    return(IntPtr.Zero);
                }

                if (++tries > 5)
                {
                    return(IntPtr.Zero);
                }

                infoPtr = Marshal.AllocHGlobal((int)infoLength);
            }
        }
Exemplo n.º 7
0
 public static extern NtStatus NtQuerySystemInformation(
     [In] SystemInformationClass systemInformationClass,
     [In] IntPtr systemInformation,
     [In] int systemInformationLength,
     [Out] out int returnedLength);
 public static extern NtStatus RtlGetNativeSystemInformation(
     SystemInformationClass SystemInformationClass,
     SafeBuffer SystemInformation,
     int SystemInformationLength,
     out int ReturnLength
     );
Exemplo n.º 9
0
 public static extern int NtQuerySystemInformation(SystemInformationClass infoClass, IntPtr info, uint size, out uint length);
Exemplo n.º 10
0
 public static unsafe extern int NtQuerySystemInformationEx(SystemInformationClass infoClass, void *inputBuffer, int inputBufferLen, void *buffer, uint size, int *actualSize = null);
Exemplo n.º 11
0
 public static extern int NtQuerySystemInformation(
     SystemInformationClass SystemInformationClass,
     IntPtr SystemInformation,
     uint SystemInformationLength,
     out uint ReturnLength);
Exemplo n.º 12
0
 /// <summary>
 /// Query a variable buffer from the object and return as bytes.
 /// </summary>
 /// <param name="info_class">The information class to query.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static byte[] QueryRawBytes(SystemInformationClass info_class)
 {
     return(_system_info_object.QueryRawBytes(info_class));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Query a variable buffer from the object and return as bytes.
 /// </summary>
 /// <param name="info_class">The information class to query.</param>
 /// <param name="init_buffer">A buffer to initialize the initial query. Can be null.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static byte[] QueryRawBytes(SystemInformationClass info_class, byte[] init_buffer)
 {
     return(_system_info_object.QueryRawBytes(info_class, init_buffer));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Query a variable buffer from the object and return as bytes.
 /// </summary>
 /// <param name="info_class">The information class to query.</param>
 /// <param name="init_buffer">A buffer to initialize the initial query. Can be null.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtResult <byte[]> QueryRawBytes(SystemInformationClass info_class, byte[] init_buffer, bool throw_on_error)
 {
     return(_system_info_object.QueryRawBytes(info_class, init_buffer, throw_on_error));
 }
Exemplo n.º 15
0
 /// <summary>
 /// Query a variable buffer from the object.
 /// </summary>
 /// <param name="info_class">The information class to query.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static SafeHGlobalBuffer QueryRawBuffer(SystemInformationClass info_class)
 {
     return(_system_info_object.QueryRawBuffer(info_class));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Query a variable buffer from the object.
 /// </summary>
 /// <typeparam name="T">The type of structure to return.</typeparam>
 /// <param name="info_class">The information class to query.</param>
 /// <param name="default_value">A default value for the query.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtResult <SafeStructureInOutBuffer <T> > QueryBuffer <T>(SystemInformationClass info_class, T default_value, bool throw_on_error) where T : new()
 {
     return(_system_info_object.QueryBuffer(info_class, default_value, throw_on_error));
 }
Exemplo n.º 17
0
 public static extern uint NtQuerySystemInformation([In] SystemInformationClass SystemInformationClass, [Out] IntPtr SystemInformation, [In] int SystemInformationLength, [Optional] out int ReturnLength);
Exemplo n.º 18
0
 /// <summary>
 /// Query a variable buffer from the object.
 /// </summary>
 /// <typeparam name="T">The type of structure to return.</typeparam>
 /// <param name="info_class">The information class to query.</param>
 /// <returns>The result of the query.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static SafeStructureInOutBuffer <T> QueryBuffer <T>(SystemInformationClass info_class) where T : new()
 {
     return(_system_info_object.QueryBuffer <T>(info_class));
 }
Exemplo n.º 19
0
 public unsafe static extern int NtQuerySystemInformation(SystemInformationClass infoClass, IntPtr buffer, int size, int *actualSize = null);
Exemplo n.º 20
0
 /// <summary>
 /// Set a value to the object.
 /// </summary>
 /// <typeparam name="T">The type of structure to set.</typeparam>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="value">The value to set. If you specify a SafeBuffer then it'll be passed directly.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtStatus Set <T>(SystemInformationClass info_class, T value, bool throw_on_error) where T : struct
 {
     return(_system_info_object.Set(info_class, value, throw_on_error));
 }
Exemplo n.º 21
0
 internal static extern NtStatus NtQuerySystemInformation(
     [In] SystemInformationClass SystemInformationClass,
     [In] IntPtr SystemInformation,
     [In] int SystemInformationLength,
     [Out] out int ReturnLength);
Exemplo n.º 22
0
 /// <summary>
 /// Set a value to the object.
 /// </summary>
 /// <typeparam name="T">The type of structure to set.</typeparam>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="value">The value to set.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static void Set <T>(SystemInformationClass info_class, T value) where T : struct
 {
     _system_info_object.Set(info_class, value);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Set a value to the object from a buffer.
 /// </summary>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="buffer">The value to set.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtStatus SetBuffer(SystemInformationClass info_class, SafeBuffer buffer, bool throw_on_error)
 {
     return(_system_info_object.SetBuffer(info_class, buffer, throw_on_error));
 }
Exemplo n.º 24
0
 /// <summary>
 /// Set a value to the object from a buffer..
 /// </summary>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="buffer">The value to set.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static void SetBuffer(SystemInformationClass info_class, SafeBuffer buffer)
 {
     _system_info_object.SetBuffer(info_class, buffer);
 }
Exemplo n.º 25
0
 internal static extern NTSTATUS PInvoke_NtQuerySystemInformation(SystemInformationClass InfoClass, IntPtr Info, uint InfoLength, out uint ReturnLength);
Exemplo n.º 26
0
 /// <summary>
 /// Set a raw value to the object.
 /// </summary>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="value">The raw value to set.</param>
 /// <param name="throw_on_error">True to throw on error.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static NtStatus SetBytes(SystemInformationClass info_class, byte[] value, bool throw_on_error)
 {
     return(_system_info_object.SetBytes(info_class, value, throw_on_error));
 }
 public static extern NtStatus NtSetSystemInformation(
     SystemInformationClass SystemInformationClass,
     SafeBuffer SystemInformation,
     int SystemInformationLength
     );
Exemplo n.º 28
0
 /// <summary>
 /// Set a raw value to the object.
 /// </summary>
 /// <param name="info_class">The information class to set.</param>
 /// <param name="value">The raw value to set.</param>
 /// <returns>The NT status code of the set.</returns>
 /// <exception cref="NtException">Thrown on error.</exception>
 public static void SetBytes(SystemInformationClass info_class, byte[] value)
 {
     _system_info_object.SetBytes(info_class, value);
 }
Exemplo n.º 29
0
 public static extern int NtQuerySystemInformation(SystemInformationClass infoClass, IntPtr buffer, uint size, out uint actualSize);
Exemplo n.º 30
0
 public static extern int NtQuerySystemInformation(
     SystemInformationClass informationClass,
     [Out] SystemProcessorPerformanceInformation[] informations,
     int structSize, out IntPtr returnLength);
Exemplo n.º 31
0
 public static extern int NtQuerySystemInformation(SystemInformationClass informationClass,
                                                   [Out] SystemProcessorPerformanceInformation[] informations,
                                                   int structSize, out IntPtr returnLength);
 public static extern NtStatus NtQuerySystemInformation(
   SystemInformationClass SystemInformationClass,
   IntPtr SystemInformation,
   int SystemInformationLength,
   out int ReturnLength
 );