This commit is contained in:
nitrogenoliquido committed 2026-10-14 22:51:32 -05:00
1 parent 82004f6b5e
commit e0347fe1cb
8 files changed
+97 -13

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ public:
static std::vector<TargetWindow> FindMinecraftWindows();
static bool IsModuleLoaded(DWORD pid, const wchar_t* moduleName);
static bool WaitForModuleLoad(DWORD pid, const wchar_t* moduleName, DWORD timeoutMs);
static bool UnloadModule(DWORD pid, const wchar_t* moduleName);
};
} // namespace Slinky
+11 -2
View File
@@ -70,8 +70,12 @@ bool Injector::ExtractBundledDll(std::wstring& outDllPath, std::wstring& outLogP
bool Injector::InjectDll(DWORD pid, const std::wstring& dllPath) {
if (ProcessUtil::IsModuleLoaded(pid, L"SlinkyNative.dll")) {
ConsoleUI::SetStatusText("DLL already loaded.");
return true;
ConsoleUI::SetStatusText("Unloading previous instance...");
if (!ProcessUtil::UnloadModule(pid, L"SlinkyNative.dll")) {
ConsoleUI::SetStatusText("Could not unload previous instance.");
return false;
}
Sleep(300);
}
ConsoleUI::SetStatusText("Opening game process");
@@ -138,6 +142,11 @@ bool Injector::InjectDll(DWORD pid, const std::wstring& dllPath) {
VirtualFreeEx(hProcess, pRemotePath, 0, MEM_RELEASE);
CloseHandle(hProcess);
if (dwExitCode == 0) {
ConsoleUI::SetStatusText("LoadLibraryW failed in game process.");
return false;
}
if (!ProcessUtil::WaitForModuleLoad(pid, L"SlinkyNative.dll", 5000)) {
ConsoleUI::SetStatusText("DLL not in game after load attempt.");
return false;
+51
View File
@@ -97,4 +97,55 @@ bool ProcessUtil::WaitForModuleLoad(DWORD pid, const wchar_t* moduleName, DWORD
return false;
}
bool ProcessUtil::UnloadModule(DWORD pid, const wchar_t* moduleName) {
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
if (hSnap == INVALID_HANDLE_VALUE) return false;
MODULEENTRY32W me;
me.dwSize = sizeof(me);
HMODULE hTargetModule = nullptr;
if (Module32FirstW(hSnap, &me)) {
do {
if (_wcsicmp(me.szModule, moduleName) == 0 ||
wcsstr(me.szExePath, moduleName) != nullptr)
{
hTargetModule = me.hModule;
break;
}
} while (Module32NextW(hSnap, &me));
}
CloseHandle(hSnap);
if (!hTargetModule) return true;
HANDLE hProcess = OpenProcess(
PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_QUERY_INFORMATION,
FALSE, pid);
if (!hProcess) return false;
HMODULE hKernel32 = GetModuleHandleW(L"kernel32.dll");
LPTHREAD_START_ROUTINE pFreeLibrary = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32, "FreeLibrary");
if (!pFreeLibrary) {
CloseHandle(hProcess);
return false;
}
HANDLE hThread = CreateRemoteThread(hProcess, nullptr, 0, pFreeLibrary, (LPVOID)hTargetModule, 0, nullptr);
if (hThread) {
WaitForSingleObject(hThread, 5000);
CloseHandle(hThread);
}
CloseHandle(hProcess);
DWORD elapsed = 0;
while (elapsed < 3000) {
if (!IsModuleLoaded(pid, moduleName)) return true;
Sleep(50);
elapsed += 50;
}
return !IsModuleLoaded(pid, moduleName);
}
} // namespace Slinky