mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-06 06:32:52 +08:00
handle CreateToolhelp32Snapshot ERROR_BAD_LENGTH
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.ComponentModel;
|
using Microsoft.Win32.SafeHandles;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Windows.Win32;
|
using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
using Windows.Win32.Foundation;
|
||||||
@@ -76,10 +77,20 @@ internal sealed unsafe class GameProcess {
|
|||||||
}
|
}
|
||||||
// Get lib base address in target process
|
// Get lib base address in target process
|
||||||
byte* baseAddress = null;
|
byte* baseAddress = null;
|
||||||
using (var hSnap = Native.CreateToolhelp32Snapshot_SafeHandle(CREATE_TOOLHELP_SNAPSHOT_FLAGS.TH32CS_SNAPMODULE, Id)) {
|
SafeFileHandle hSnap;
|
||||||
if (hSnap.IsInvalid) {
|
do
|
||||||
throw new Win32Exception { Data = { { "api", "CreateToolhelp32Snapshot" } } };
|
{
|
||||||
|
hSnap = Native.CreateToolhelp32Snapshot_SafeHandle(CREATE_TOOLHELP_SNAPSHOT_FLAGS.TH32CS_SNAPMODULE, Id);
|
||||||
|
if (Marshal.GetLastSystemError() is not (0 or 24)) // ERROR_BAD_LENGTH
|
||||||
|
{
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
while (hSnap.IsInvalid);
|
||||||
|
if (hSnap.IsInvalid) {
|
||||||
|
throw new Win32Exception { Data = { { "api", "CreateToolhelp32Snapshot" } } };
|
||||||
|
}
|
||||||
|
using (hSnap) {
|
||||||
var moduleEntry = new MODULEENTRY32 {
|
var moduleEntry = new MODULEENTRY32 {
|
||||||
dwSize = (uint) sizeof(MODULEENTRY32)
|
dwSize = (uint) sizeof(MODULEENTRY32)
|
||||||
};
|
};
|
||||||
@@ -124,4 +135,4 @@ internal sealed unsafe class GameProcess {
|
|||||||
|
|
||||||
public bool Terminate(uint exitCode) => Native.TerminateProcess(Handle, exitCode);
|
public bool Terminate(uint exitCode) => Native.TerminateProcess(Handle, exitCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user