mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-07 15:12: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
|
OpenProcess
|
||||||
GetModuleFileNameEx
|
GetModuleFileNameEx
|
||||||
|
|
||||||
|
LoadLibraryEx
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Windows.Win32;
|
using Windows.Win32;
|
||||||
using Windows.Win32.Foundation;
|
using Windows.Win32.Foundation;
|
||||||
|
using Windows.Win32.System.LibraryLoader;
|
||||||
using Windows.Win32.System.Threading;
|
using Windows.Win32.System.Threading;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
using static Windows.Win32.System.Memory.VIRTUAL_ALLOCATION_TYPE;
|
using static Windows.Win32.System.Memory.VIRTUAL_ALLOCATION_TYPE;
|
||||||
@@ -72,6 +73,20 @@ public sealed unsafe class GameProcess {
|
|||||||
if (Native.WaitForSingleObject(hThread, 2000) == 0) {
|
if (Native.WaitForSingleObject(hThread, 2000) == 0) {
|
||||||
Native.VirtualFreeEx(Handle, lpLibPath, 0, MEM_RELEASE);
|
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);
|
Native.CloseHandle(hThread);
|
||||||
} catch (Win32Exception e) {
|
} catch (Win32Exception e) {
|
||||||
_ = Terminate(0);
|
_ = Terminate(0);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Elysia.Bootstrap" Version="1.0.14"/>
|
|
||||||
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
|
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.183">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
@@ -34,7 +33,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<LibraryEntrypoint Include="YaeMain"/>
|
|
||||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute"/>
|
<AssemblyAttribute Include="System.Runtime.CompilerServices.DisableRuntimeMarshallingAttribute"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
@@ -43,8 +41,4 @@
|
|||||||
<Using Include="System.Diagnostics.CodeAnalysis"/>
|
<Using Include="System.Diagnostics.CodeAnalysis"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="obj\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user