private static string FormatText(HandleEntry ent) { NativeHandle h = NativeBridge.DuplicateHandleFromProcess(ent.ProcessId, ent.Handle, 0, DuplicateHandleOptions.DuplicateSameAccess); try { StringBuilder builder = new StringBuilder(); if ((ent.GrantedAccess & (int)HandleUtils.AccessRights.SectionMapRead) != 0) { builder.Append("R"); } if ((ent.GrantedAccess & (int)HandleUtils.AccessRights.SectionMapWrite) != 0) { builder.Append("W"); } return String.Format("[{0}/0x{0:X}] {1} Size: {2} Access: {3}", ent.Handle.ToInt64(), ent.ObjectName, NativeBridge.GetSectionSize(h), builder.ToString()); } finally { h.Close(); } }
private static string FormatText(HandleEntry ent) { NativeHandle h = NativeBridge.DuplicateHandleFromProcess(ent.ProcessId, ent.Handle, 0, DuplicateHandleOptions.DuplicateSameAccess); try { StringBuilder builder = new StringBuilder(); if ((ent.GrantedAccess & (int)HandleUtils.AccessRights.SectionMapRead) != 0) { builder.Append("R"); } if ((ent.GrantedAccess & (int)HandleUtils.AccessRights.SectionMapWrite) != 0) { builder.Append("W"); } return(String.Format("[{0}/0x{0:X}] {1} Size: {2} Access: {3}", ent.Handle.ToInt64(), ent.ObjectName, NativeBridge.GetSectionSize(h), builder.ToString())); } finally { h.Close(); } }
public bool Remove(IntPtr handle) { lock (this) { int num = ComputeHash(handle); if (System.ComponentModel.CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { _ = System.ComponentModel.CompModSwitches.HandleLeak.Level; _ = 4; } HandleEntry handleEntry = buckets[num]; HandleEntry handleEntry2 = null; while (handleEntry != null && handleEntry.handle != handle) { handleEntry2 = handleEntry; handleEntry = handleEntry.next; } if (handleEntry != null) { if (handleEntry2 == null) { buckets[num] = handleEntry.next; } else { handleEntry2.next = handleEntry.next; } handleCount--; return(true); } return(false); } }
/// <summary> /// Checks and reports leaks for handle monitoring. /// </summary> public void CheckLeaks() { lock (this) { bool reportedFirstLeak = false; if (_handleCount > 0) { for (int i = 0; i < NumberOfBuckets; i++) { HandleEntry e = _buckets[i]; while (e != null) { if (!e.ignorableAsLeak) { if (!reportedFirstLeak) { Debug.WriteLine("\r\nHandle leaks detected for handles of type " + name + ":"); reportedFirstLeak = true; } Debug.WriteLine(e.ToString(this)); } e = e.next; } } } } }
/// <summary> /// Adds a handle to this handle type for monitoring. /// </summary> public void Add(IntPtr handle) { lock (this) { int hash = ComputeHash(handle); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { Debug.WriteLine("-------------------------------------------------"); Debug.WriteLine("Handle Allocating: " + Convert.ToString(unchecked ((int)handle), 16)); Debug.WriteLine("Handle Type : " + name); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Verbose) { Debug.WriteLine(Environment.StackTrace); } } HandleEntry entry = _buckets[hash]; while (entry != null) { Debug.Assert(entry.handle != handle, "Duplicate handle of type " + name); entry = entry.next; } _buckets[hash] = new HandleEntry(_buckets[hash], handle); _handleCount++; } }
public bool Remove(IntPtr handle) { lock (this) { int index = this.ComputeHash(handle); if (System.ComponentModel.CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { TraceLevel level = System.ComponentModel.CompModSwitches.HandleLeak.Level; } HandleEntry next = this.buckets[index]; HandleEntry entry2 = null; while ((next != null) && (next.handle != handle)) { entry2 = next; next = next.next; } if (next != null) { if (entry2 == null) { this.buckets[index] = next.next; } else { entry2.next = next.next; } this.handleCount--; return(true); } return(false); } }
private void openTokenToolStripMenuItem_Click(object sender, EventArgs e) { TreeNode selectedNode = treeViewProcesses.SelectedNode; if (selectedNode != null) { ProcessEntry process = selectedNode.Tag as ProcessEntry; HandleEntry handle = selectedNode.Tag as HandleEntry; if (process != null) { TokenForm.OpenForm(process.Token, true); } else if (handle != null) { try { TokenForm.OpenForm(new UserToken(NativeBridge.DuplicateHandleFromProcess(handle, (uint)(TokenAccessRights.Query | TokenAccessRights.QuerySource), 0)), false); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public HandleEntry(HandleEntry next, IntPtr handle) { this.handle = handle; this.next = next; if (System.ComponentModel.CompModSwitches.HandleLeak.Level > TraceLevel.Off) { callStack = Environment.StackTrace; } else { callStack = null; } }
public void IgnoreCurrentHandlesAsLeaks() { lock (this) { if (this.handleCount > 0) { for (int i = 0; i < 10; i++) { for (HandleEntry entry = this.buckets[i]; entry != null; entry = entry.next) { entry.ignorableAsLeak = true; } } } } }
public void Add(IntPtr handle) { lock (this) { int index = this.ComputeHash(handle); if (System.ComponentModel.CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { TraceLevel level = System.ComponentModel.CompModSwitches.HandleLeak.Level; } for (HandleEntry entry = this.buckets[index]; entry != null; entry = entry.next) { } this.buckets[index] = new HandleEntry(this.buckets[index], handle); this.handleCount++; } }
/// <include file='doc\DebugHandleTracker.uex' path='docs/doc[@for="DebugHandleTracker.HandleType.HandleEntry.HandleEntry"]/*' /> /// <devdoc> /// Creates a new handle entry /// </devdoc> public HandleEntry(HandleEntry next, IntPtr handle) { this.handle = handle; this.next = next; #if DEBUG if (CompModSwitches.HandleLeak.Level > TraceLevel.Off) { this.callStack = Environment.StackTrace; } else { this.callStack = null; } #endif // DEBUG }
public void IgnoreCurrentHandlesAsLeaks() { lock (this) { if (handleCount <= 0) { return; } for (int i = 0; i < 10; i++) { for (HandleEntry handleEntry = buckets[i]; handleEntry != null; handleEntry = handleEntry.next) { handleEntry.ignorableAsLeak = true; } } } }
public void Add(IntPtr handle) { lock (this) { int num = ComputeHash(handle); if (System.ComponentModel.CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { _ = System.ComponentModel.CompModSwitches.HandleLeak.Level; _ = 4; } for (HandleEntry handleEntry = buckets[num]; handleEntry != null; handleEntry = handleEntry.next) { } buckets[num] = new HandleEntry(buckets[num], handle); handleCount++; } }
/// <include file='doc\DebugHandleTracker.uex' path='docs/doc[@for="DebugHandleTracker.HandleType.IgnoreCurrentHandlesAsLeaks"]/*' /> /// <devdoc> /// Marks all the handles currently stored, as ignorable, so that they will not be reported as leaks later. /// </devdoc> public void IgnoreCurrentHandlesAsLeaks() { lock (this) { if (handleCount > 0) { for (int i = 0; i < BUCKETS; i++) { HandleEntry e = buckets[i]; while (e != null) { e.ignorableAsLeak = true; e = e.next; } } } } }
/// <include file='doc\DebugHandleTracker.uex' path='docs/doc[@for="DebugHandleTracker.HandleType.CheckLeaks"]/*' /> /// <devdoc> /// Checks and reports leaks for handle monitoring. /// </devdoc> public void CheckLeaks() { lock (this) { if (handleCount > 0) { Debug.WriteLine("\r\nHandle leaks detected for handles of type " + name + ":"); for (int i = 0; i < BUCKETS; i++) { HandleEntry e = buckets[i]; while (e != null) { Debug.WriteLine(e.ToString(this)); e = e.next; } } } } }
public static void Handle(IClientMessage clientMessage, HandleEntry handleEntry) { var messageType = clientMessage.GetMessageType(); if (messageType == EventMessageConst.EventEntry) { IData key = null; var key_isNull = clientMessage.GetBoolean(); if (!key_isNull) { key = clientMessage.GetData(); } IData value = null; var value_isNull = clientMessage.GetBoolean(); if (!value_isNull) { value = clientMessage.GetData(); } IData oldValue = null; var oldValue_isNull = clientMessage.GetBoolean(); if (!oldValue_isNull) { oldValue = clientMessage.GetData(); } IData mergingValue = null; var mergingValue_isNull = clientMessage.GetBoolean(); if (!mergingValue_isNull) { mergingValue = clientMessage.GetData(); } int eventType; eventType = clientMessage.GetInt(); string uuid = null; uuid = clientMessage.GetStringUtf8(); int numberOfAffectedEntries; numberOfAffectedEntries = clientMessage.GetInt(); handleEntry(key, value, oldValue, mergingValue, eventType, uuid, numberOfAffectedEntries); return; } Logger.GetLogger(typeof(AbstractEventHandler)) .Warning("Unknown message type received on event handler :" + clientMessage.GetMessageType()); }
public void CheckLeaks() { lock (this) { bool flag = false; if (this.handleCount > 0) { for (int i = 0; i < 10; i++) { for (HandleEntry entry = this.buckets[i]; entry != null; entry = entry.next) { if (!entry.ignorableAsLeak && !flag) { flag = true; } } } } } }
public static void Handle(IClientMessage clientMessage, HandleEntry handleEntry) { var messageType = clientMessage.GetMessageType(); if (messageType == EventMessageConst.EventEntry) { IData key = null; var key_isNull = clientMessage.GetBoolean(); if (!key_isNull) { key = clientMessage.GetData(); } IData value = null; var value_isNull = clientMessage.GetBoolean(); if (!value_isNull) { value = clientMessage.GetData(); } IData oldValue = null; var oldValue_isNull = clientMessage.GetBoolean(); if (!oldValue_isNull) { oldValue = clientMessage.GetData(); } IData mergingValue = null; var mergingValue_isNull = clientMessage.GetBoolean(); if (!mergingValue_isNull) { mergingValue = clientMessage.GetData(); } int eventType; eventType = clientMessage.GetInt(); string uuid = null; uuid = clientMessage.GetStringUtf8(); int numberOfAffectedEntries; numberOfAffectedEntries = clientMessage.GetInt(); handleEntry(key, value, oldValue, mergingValue, eventType, uuid, numberOfAffectedEntries); return; } Logger.GetLogger(typeof (AbstractEventHandler)) .Warning("Unknown message type received on event handler :" + clientMessage.GetMessageType()); }
public void CheckLeaks() { lock (this) { bool flag = false; if (handleCount <= 0) { return; } for (int i = 0; i < 10; i++) { for (HandleEntry handleEntry = buckets[i]; handleEntry != null; handleEntry = handleEntry.next) { if (!handleEntry.ignorableAsLeak && !flag) { flag = true; } } } } }
/// <summary> /// Removes the given handle from our monitor list. /// </summary> public bool Remove(IntPtr handle) { lock (this) { int hash = ComputeHash(handle); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { Debug.WriteLine("-------------------------------------------------"); Debug.WriteLine("Handle Releaseing: " + Convert.ToString(unchecked ((int)handle), 16)); Debug.WriteLine("Handle Type : " + name); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Verbose) { Debug.WriteLine(Environment.StackTrace); } } HandleEntry e = _buckets[hash]; HandleEntry last = null; while (e != null && e.handle != handle) { last = e; e = e.next; } if (e != null) { if (last == null) { _buckets[hash] = e.next; } else { last.next = e.next; } _handleCount--; return(true); } return(false); } }
public SectionEditorForm(NativeMappedFile map, HandleEntry handle, bool readOnly) : this(map, readOnly) { TabText = String.Format("Process {0} - Handle {1} {2}", handle.ProcessId, handle.Handle.ToInt64(), _readOnly ? "(RO)" : ""); }
public SectionTreeNode(HandleEntry ent) : base(FormatText(ent)) { _ent = ent; }
/// <include file='doc\DebugHandleTracker.uex' path='docs/doc[@for="DebugHandleTracker.HandleType.HandleEntry.HandleEntry"]/*' /> /// <devdoc> /// Creates a new handle entry /// </devdoc> public HandleEntry(HandleEntry next, IntPtr handle) { this.handle = handle; this.next = next; if (CompModSwitches.HandleLeak.Level > TraceLevel.Off) { this.callStack = Environment.StackTrace; } else { this.callStack = null; } }
/// <include file='doc\DebugHandleTracker.uex' path='docs/doc[@for="DebugHandleTracker.HandleType.Add"]/*' /> /// <devdoc> /// Adds a handle to this handle type for monitoring. /// </devdoc> public void Add(IntPtr handle) { lock(this) { int hash = ComputeHash(handle); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Info) { Debug.WriteLine("-------------------------------------------------"); Debug.WriteLine("Handle Allocating: " + Convert.ToString(unchecked((int)handle), 16)); Debug.WriteLine("Handle Type : " + name); if (CompModSwitches.HandleLeak.Level >= TraceLevel.Verbose) Debug.WriteLine(Environment.StackTrace); } HandleEntry entry = buckets[hash]; while (entry != null) { Debug.Assert(entry.handle != handle, "Duplicate handle of type " + name); entry = entry.next; } buckets[hash] = new HandleEntry(buckets[hash], handle); handleCount++; } }