private bool ShowTokenPermissions(TokenAccessRights access, bool throw_on_error) { using (var result = _token.Duplicate(access, AttributeFlags.None, DuplicateObjectOptions.None, throw_on_error)) { if (result.IsSuccess) { Win32Utils.EditSecurity(Handle, result.Result, "Token", false); return(true); } } return(false); }
static void Main(string[] args) { try { if (args.Length == 0) { MessageBox.Show("Usage: ViewSecurityDescriptor.exe (handle [--readonly]|Name SDDL NtType)", "Usage", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (args.Length < 3) { var handle = new SafeKernelObjectHandle(new IntPtr(int.Parse(args[0])), true); bool read_only = args.Length > 1 ? args[1].Equals("--readonly") : false; using (var obj = NtGeneric.FromHandle(handle)) { Win32Utils.EditSecurity(IntPtr.Zero, obj, obj.Name, read_only); } } else { SecurityDescriptor sd = new SecurityDescriptor(args[1]); NtType type = NtType.GetTypeByName(args[2], false); if (type == null) { throw new ArgumentException($"Unknown NT type {args[2]}"); } Win32Utils.EditSecurity(IntPtr.Zero, args[0], sd, type); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnEditPermissions_Click(object sender, System.EventArgs e) { Win32Utils.EditSecurity(this.Handle, _obj, _obj.Name, false); }