-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Support long module path #33505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support long module path #33505
Changes from 1 commit
638594b
ff306e0
20187cf
ed89f18
0b1c57e
969b96b
c3db3e6
e26b516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -131,7 +131,9 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul | |
|
|
||
| var modules = new ProcessModuleCollection(firstModuleOnly ? 1 : modulesCount); | ||
|
|
||
| char[] chars = ArrayPool<char>.Shared.Rent(1024); | ||
| const int MaxShortPath = 260; | ||
| int minimumLength = MaxShortPath; | ||
| char[]? chars = ArrayPool<char>.Shared.Rent(minimumLength); | ||
| try | ||
| { | ||
| for (int i = 0; i < modulesCount; i++) | ||
|
|
@@ -171,14 +173,29 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul | |
|
|
||
| module.ModuleName = new string(chars, 0, length); | ||
|
|
||
| length = Interop.Kernel32.GetModuleFileNameEx(processHandle, moduleHandle, chars, chars.Length); | ||
| for (; ; ) | ||
jeffhandley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| length = Interop.Kernel32.GetModuleFileNameEx(processHandle, moduleHandle, chars, chars.Length); | ||
| if (length == chars.Length) | ||
| { | ||
| char[] toReturn = chars; | ||
| chars = null; | ||
| ArrayPool<char>.Shared.Return(toReturn); | ||
|
||
| minimumLength = Math.Min(minimumLength * 2, short.MaxValue); | ||
jeffhandley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
jeffhandley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
jeffhandley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| chars = ArrayPool<char>.Shared.Rent(minimumLength); | ||
| continue; | ||
| } | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| if (length == 0) | ||
| { | ||
| HandleLastWin32Error(); | ||
| continue; | ||
| } | ||
|
|
||
| module.FileName = (length >= 4 && chars[0] == '\\' && chars[1] == '\\' && chars[2] == '?' && chars[3] == '\\') ? | ||
| module.FileName = chars.AsSpan().StartsWith(@"\\?\") ? | ||
| new string(chars, 4, length - 4) : | ||
| new string(chars, 0, length); | ||
|
|
||
|
|
@@ -187,7 +204,10 @@ private static ProcessModuleCollection GetModules(int processId, bool firstModul | |
| } | ||
| finally | ||
| { | ||
| ArrayPool<char>.Shared.Return(chars); | ||
| if (chars != null) | ||
| { | ||
| ArrayPool<char>.Shared.Return(chars); | ||
| } | ||
| } | ||
|
|
||
| return modules; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.