Beispiel #1
0
 /// <summary>
 /// Get a list of accessible desktop objects.
 /// </summary>
 /// <param name="desired_access">The desired access for the desktops.</param>
 /// <returns>The list of desktops.</returns>
 public IEnumerable <NtDesktop> GetAccessibleDesktops(DesktopAccessRights desired_access)
 {
     using (var list = new DisposableList <NtDesktop>()) {
         foreach (string desktop in Desktops)
         {
             using (ObjectAttributes obj_attr = new ObjectAttributes(desktop, AttributeFlags.CaseInsensitive, this)) {
                 var result = NtDesktop.Open(obj_attr, 0, desired_access, false);
                 if (result.IsSuccess)
                 {
                     list.Add(result.Result);
                 }
             }
         }
         return(list.ToArrayAndClear());
     }
 }
Beispiel #2
0
        /// <summary>
        /// Return a list of subkeys which can be accessed.
        /// </summary>
        /// <param name="desired_access">The required access rights for the subkeys</param>
        /// <returns>The disposable list of subkeys.</returns>
        /// <exception cref="NtException">Thrown on error.</exception>
        public DisposableList <NtKey> QueryAccessibleKeys(KeyAccessRights desired_access)
        {
            DisposableList <NtKey> ret = new DisposableList <NtKey>();

            foreach (string name in QueryKeys())
            {
                try
                {
                    ret.Add(Open(name, desired_access));
                }
                catch (NtException)
                {
                }
            }
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// Get a list of accessible Window Station objects.
        /// </summary>
        /// <param name="desired_access">The desired access for the Window Stations.</param>
        /// <returns>The list of desktops.</returns>
        public static IEnumerable <NtWindowStation> GetAccessibleWindowStations(WindowStationAccessRights desired_access)
        {
            using (var list = new DisposableList <NtWindowStation>()) {
                string base_path = GetWindowStationBase();

                foreach (string name in WindowStations)
                {
                    string full_path = $@"{base_path}\{name}";
                    using (ObjectAttributes obj_attr = new ObjectAttributes(full_path, AttributeFlags.CaseInsensitive)) {
                        var result = Open(obj_attr, desired_access, false);
                        if (result.IsSuccess)
                        {
                            list.Add(result.Result);
                        }
                    }
                }
                return(list.ToArrayAndClear());
            }
        }
Beispiel #4
0
        /// <summary>
        /// For the current process
        /// </summary>
        /// <param name="process_create_flags">Process create flags.</param>
        /// <param name="thread_create_flags">Thread create flags.</param>
        /// <param name="throw_on_error">True to throw on error.</param>
        /// <returns>The new forked process result</returns>
        public static NtResult <CreateUserProcessResult> Fork(ProcessCreateFlags process_create_flags,
                                                              ThreadCreateFlags thread_create_flags, bool throw_on_error)
        {
            using (var attrs = new DisposableList <ProcessAttribute>()) {
                ProcessCreateInfo create_info = new ProcessCreateInfo();

                SafeStructureInOutBuffer <ClientId> client_id = new SafeStructureInOutBuffer <ClientId>();
                attrs.Add(ProcessAttribute.ClientId(client_id));

                ProcessAttributeList attr_list = new ProcessAttributeList(attrs);

                return(NtSystemCalls.NtCreateUserProcess(
                           out SafeKernelObjectHandle process_handle, out SafeKernelObjectHandle thread_handle,
                           ProcessAccessRights.MaximumAllowed, ThreadAccessRights.MaximumAllowed,
                           null, null, process_create_flags | ProcessCreateFlags.InheritFromParent,
                           thread_create_flags, IntPtr.Zero, create_info, attr_list).CreateResult(throw_on_error,
                                                                                                  () => new CreateUserProcessResult(process_handle, thread_handle,
                                                                                                                                    create_info.Data, new SectionImageInformation(), client_id.Result, false)));
            }
        }