mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-07 07:02:50 +08:00
invoke libMain by CRT
Co-authored-by: HolographicHat <holographichat@outlook.com> Co-authored-by: 34736384 <34736384@users.noreply.github.com>
This commit is contained in:
@@ -24,3 +24,5 @@ GetCurrentConsoleFontEx
|
||||
|
||||
OpenProcess
|
||||
GetModuleFileNameEx
|
||||
|
||||
LoadLibraryEx
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Win32.System.LibraryLoader;
|
||||
using Windows.Win32.System.Threading;
|
||||
using Spectre.Console;
|
||||
using static Windows.Win32.System.Memory.VIRTUAL_ALLOCATION_TYPE;
|
||||
@@ -72,6 +73,20 @@ public sealed unsafe class GameProcess {
|
||||
if (Native.WaitForSingleObject(hThread, 2000) == 0) {
|
||||
Native.VirtualFreeEx(Handle, lpLibPath, 0, MEM_RELEASE);
|
||||
}
|
||||
var libHandle = Native.LoadLibraryEx(libPath, LOAD_LIBRARY_FLAGS.DONT_RESOLVE_DLL_REFERENCES);
|
||||
if (libHandle.IsInvalid) {
|
||||
throw new Win32Exception { Data = { { "api", "LoadLibraryEx" } } };
|
||||
}
|
||||
var libMainProc = Native.GetProcAddress(libHandle, "YaeMain");
|
||||
if (libMainProc.IsNull) {
|
||||
throw new Win32Exception { Data = { { "api", "GetProcAddress" } } };
|
||||
}
|
||||
var lpStartAddress2 = (delegate*unmanaged[Stdcall]<void*, uint>) libMainProc.Value; // THREAD_START_ROUTINE
|
||||
var hThread2 = Native.CreateRemoteThread(Handle, null, 0, lpStartAddress2, null, 0);
|
||||
if (hThread2.IsNull) {
|
||||
throw new Win32Exception { Data = { { "api", "CreateRemoteThread2" } } };
|
||||
}
|
||||
Native.CloseHandle(hThread2);
|
||||
Native.CloseHandle(hThread);
|
||||
} catch (Win32Exception e) {
|
||||
_ = Terminate(0);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Elysia.Bootstrap" Version="1.0.14"/>
|
||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
@@ -34,7 +33,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<LibraryEntrypoint Include="YaeMain"/>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute"/>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -43,8 +41,4 @@
|
||||
<Using Include="System.Diagnostics.CodeAnalysis"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="obj\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user