Structure because structure
This commit is contained in:
parent
01d1ea3573
commit
2b2a53466f
17 changed files with 693 additions and 674 deletions
33
Tools/WindowsAPI/WindowsUtils.cs
Normal file
33
Tools/WindowsAPI/WindowsUtils.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Xorog.UniversalExtensions.WindowsAPI;
|
||||
|
||||
public class WindowsUtils
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static FileInfo? GetMainModuleFilepath(int pid)
|
||||
{
|
||||
var processHandle = kernel32.OpenProcess(0x0400 | 0x0010, false, pid);
|
||||
|
||||
if (processHandle == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
const int lengthSb = 4000;
|
||||
|
||||
var sb = new StringBuilder(lengthSb);
|
||||
|
||||
string? result = null;
|
||||
|
||||
if (psapi.GetModuleFileNameEx(processHandle, IntPtr.Zero, sb, lengthSb) > 0)
|
||||
{
|
||||
result = Path.GetFullPath(sb.ToString());
|
||||
}
|
||||
|
||||
kernel32.CloseHandle(processHandle);
|
||||
|
||||
if (result == null)
|
||||
return null;
|
||||
|
||||
return new FileInfo(result);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue