Created
October 6, 2020 19:30
-
-
Save erfg12/1ef2c84f4ff286d079fea0aa133e3875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// dllmain.cpp : Defines the entry point for the DLL application. | |
#include "pch.h" | |
#include <string> | |
HMODULE globalhModule; | |
VOID PipeFunctions(std::string func) { | |
if (func.compare("remove") == 0) { | |
FreeLibraryAndExitThread(globalhModule, 0); | |
} | |
if (func.compare("gameassembly") == 0) { | |
HMODULE hmod = GetModuleHandle(L"GameAssembly.dll"); | |
char buffer[9]; // Adjust size if you're on a 64-bit system | |
sprintf_s(buffer, "%x", (size_t)GetProcAddress(hmod, NULL)); | |
MessageBoxA(NULL, buffer, "DEBUG", MB_OK | MB_ICONQUESTION); | |
} | |
} | |
void OnAttach(HMODULE hModule) { | |
HANDLE hPipe; | |
char buffer[1024]; | |
DWORD dwRead; | |
std::string myProcID = "\\\\.\\pipe\\EQTPipe" + std::to_string(GetCurrentProcessId()); | |
std::wstring To(myProcID.begin(), myProcID.end()); | |
LPCWSTR a = To.c_str(); | |
hPipe = CreateNamedPipe(a, | |
PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, | |
PIPE_WAIT, | |
1, | |
1024 * 16, | |
1024 * 16, | |
NMPWAIT_USE_DEFAULT_WAIT, | |
NULL); | |
while (hPipe != NULL) | |
{ | |
if (ConnectNamedPipe(hPipe, NULL) != FALSE) | |
{ | |
while (ReadFile(hPipe, buffer, sizeof(buffer) - 1, &dwRead, NULL) != FALSE) | |
{ | |
buffer[dwRead] = '\0'; | |
std::string b = buffer; | |
std::string::size_type pos = 0; | |
while ((pos = b.find("\r\n", pos)) != std::string::npos) | |
{ | |
b.erase(pos, 2); | |
} | |
PipeFunctions(b); | |
} | |
} | |
DisconnectNamedPipe(hPipe); | |
} | |
globalhModule = hModule; | |
} | |
BOOL APIENTRY DllMain( HMODULE hModule, | |
DWORD ul_reason_for_call, | |
LPVOID lpReserved | |
) | |
{ | |
switch (ul_reason_for_call) | |
{ | |
case DLL_PROCESS_ATTACH: | |
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)OnAttach, hModule, 0, NULL); | |
case DLL_THREAD_ATTACH: | |
case DLL_THREAD_DETACH: | |
case DLL_PROCESS_DETACH: | |
break; | |
} | |
return TRUE; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment