Esempio n. 1
0
 private void buttonPermissions_Click(object sender, EventArgs e)
 {
     try
     {
         SecurityEditor.EditSecurity(
             this,
             SecurityEditor.GetSecurableWrapper((access) => _object.GetToken((TokenAccess)access)),
             "Token",
             NativeTypeFactory.GetAccessEntries(NativeTypeFactory.ObjectType.Token)
             );
     }
     catch (Exception ex)
     {
         PhUtils.ShowException("Unable to edit security", ex);
     }
 }
 private void buttonPermissions_Click(object sender, EventArgs e)
 {
     try
     {
         SecurityEditor.EditSecurity(
             this,
             SecurityEditor.GetSecurableWrapper(
                 (access) => new ServiceHandle(listServices.SelectedItems[0].Name, (ServiceAccess)access)
                 ),
             listServices.SelectedItems[0].Name,
             NativeTypeFactory.GetAccessEntries(NativeTypeFactory.ObjectType.Service)
             );
     }
     catch (Exception ex)
     {
         PhUtils.ShowException("Unable to edit security", ex);
     }
 }
 private void buttonPermissions_Click(object sender, EventArgs e)
 {
     if (_objectHandle != null)
     {
         try
         {
             SecurityEditor.EditSecurity(
                 this,
                 SecurityEditor.GetSecurable(NativeTypeFactory.GetObjectType(_typeName), _objectHandle),
                 _name,
                 NativeTypeFactory.GetAccessEntries(NativeTypeFactory.GetObjectType(_typeName))
                 );
         }
         catch (Exception ex)
         {
             MessageBox.Show("Unable to edit security: " + ex.Message, "Security Editor", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Esempio n. 4
0
        private void permissionsMenuItem_Click(object sender, EventArgs e)
        {
            if (listObjects.SelectedItems.Count != 1)
            {
                return;
            }

            string objectName = this.NormalizePath(
                treeDirectories.SelectedNode.FullPath + "\\" + listObjects.SelectedItems[0].Text
                );

            SecurityEditor.EditSecurity(
                this,
                SecurityEditor.GetSecurableWrapper((access) => NativeUtils.OpenObject((int)access, objectName, 0, null)),
                objectName,
                NativeTypeFactory.GetAccessEntries(NativeTypeFactory.GetObjectType(
                                                       listObjects.SelectedItems[0].SubItems[1].Text
                                                       ))
                );
        }
Esempio n. 5
0
        public static void ShowHandleProperties(SystemHandleEntry handleInfo)
        {
            try
            {
                IntPtr        handle    = new IntPtr(handleInfo.Handle);
                ProcessHandle phandle   = new ProcessHandle(handleInfo.ProcessId, ProcessAccess.DupHandle);
                GenericHandle dupHandle = null;

                // Try to get a handle, since we need one for security editing.
                try
                {
                    dupHandle = new GenericHandle(phandle, handle, 0);
                }
                catch
                { }

                PropSheetHeader64 header = new PropSheetHeader64
                {
                    dwSize     = (uint)PropSheetHeader64.SizeOf,
                    nPages     = 2,
                    dwFlags    = (uint)PropSheetFlags.PSH_DEFAULT,
                    pszCaption = "Handle Properties"
                };

                using (HandleDetails hw = new HandleDetails())
                {
                    hw.ObjectHandle              = handleInfo;
                    hw.HandlePropertiesCallback += (control, name, typeName) =>
                    {
                        switch (typeName.ToLowerInvariant())
                        {
                        // Objects with separate property windows:
                        case "file":
                        case "job":
                        case "key":
                        case "token":
                        case "process":
                        {
                            Button b = new Button
                            {
                                FlatStyle = FlatStyle.System,
                                Text      = "Properties"
                            };

                            b.Click += (sender, e) =>
                            {
                                try
                                {
                                    switch (typeName.ToLowerInvariant())
                                    {
                                    case "file":
                                    {
                                        FileUtils.ShowProperties(name);
                                    }
                                    break;

                                    case "job":
                                    {
                                        dupHandle = new GenericHandle(phandle, handle, (int)JobObjectAccess.Query);

                                        (new JobWindow(JobObjectHandle.FromHandle(dupHandle))).ShowDialog();
                                    }
                                    break;

                                    case "key":
                                    {
                                        try
                                        {
                                            PhUtils.OpenKeyInRegedit(PhUtils.GetForegroundWindow(), name);
                                        }
                                        catch (Exception ex)
                                        {
                                            PhUtils.ShowException("Unable to open the Registry Editor", ex);
                                        }
                                    }
                                    break;

                                    case "token":
                                    {
                                        using (TokenWindow twindow = new TokenWindow(new RemoteTokenHandle(phandle, handle)))
                                        {
                                            twindow.ShowDialog();
                                        }
                                    }
                                    break;

                                    case "process":
                                    {
                                        dupHandle = new GenericHandle(phandle, handle, (int)OSVersion.MinProcessQueryInfoAccess);
                                        int pid = ProcessHandle.FromHandle(dupHandle).ProcessId;

                                        Program.GetProcessWindow(Program.ProcessProvider.Dictionary[pid], Program.FocusWindow);
                                    }
                                    break;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    PhUtils.ShowException("Unable to show object properties", ex);
                                }
                            };

                            control.Controls.Add(b);
                        }
                        break;

                        case "event":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)EventAccess.QueryState);
                            var eventProps = new EventProperties(EventHandle.FromHandle(dupHandle));
                            control.Controls.Add(eventProps);
                        }
                        break;

                        case "eventpair":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)EventPairAccess.All);
                            var eventPairProps = new EventPairProperties(EventPairHandle.FromHandle(dupHandle));
                            control.Controls.Add(eventPairProps);
                        }
                        break;

                        case "mutant":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)MutantAccess.QueryState);
                            var mutantProps = new MutantProperties(MutantHandle.FromHandle(dupHandle));
                            control.Controls.Add(mutantProps);
                        }
                        break;

                        case "section":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)SectionAccess.Query);
                            var sectionProps = new SectionProperties(SectionHandle.FromHandle(dupHandle));
                            control.Controls.Add(sectionProps);
                        }
                        break;

                        case "semaphore":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)SemaphoreAccess.QueryState);
                            var semaphoreProps = new SemaphoreProperties(SemaphoreHandle.FromHandle(dupHandle));
                            control.Controls.Add(semaphoreProps);
                        }
                        break;

                        case "timer":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)TimerAccess.QueryState);
                            var timerProps = new TimerProperties(TimerHandle.FromHandle(dupHandle));
                            control.Controls.Add(timerProps);
                        }
                        break;

                        case "tmrm":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)ResourceManagerAccess.QueryInformation);
                            var tmRmProps = new TmRmProperties(ResourceManagerHandle.FromHandle(dupHandle));
                            control.Controls.Add(tmRmProps);
                        }
                        break;

                        case "tmtm":
                        {
                            dupHandle = new GenericHandle(phandle, handle, (int)TmAccess.QueryInformation);
                            var tmTmProps = new TmTmProperties(TmHandle.FromHandle(dupHandle));
                            control.Controls.Add(tmTmProps);
                        }
                        break;
                        }
                    };

                    hw.Init();

                    IntPtr[] pages = new IntPtr[2];
                    pages[0] = hw.CreatePageHandle();
                    pages[1] = CreateSecurityPage(SecurityEditor.EditSecurity2(
                                                      null,
                                                      SecurityEditor.GetSecurableWrapper(dupHandle),
                                                      hw._name,
                                                      NativeTypeFactory.GetAccessEntries(NativeTypeFactory.GetObjectType(hw._typeName))
                                                      ));

                    GCHandle gch = GCHandle.Alloc(pages, GCHandleType.Pinned);
                    header.phpage = gch.AddrOfPinnedObject();

                    PropertySheetW(ref header);

                    if (dupHandle != null)
                    {
                        dupHandle.Dispose();
                    }
                }
            }
            catch (Exception ex)
            {
                PhUtils.ShowException("Unable to show handle properties", ex);
            }
        }
Esempio n. 6
0
        private void Permissions_Click(object sender, RoutedEventArgs e)
        {
            var acl = (UrlAcl)((FrameworkElement)sender).DataContext;

            SecurityEditor.EditSecurity(null, acl, acl.Prefix, GetAccessEntries());
        }