Skip to content

Commit

Permalink
Corrected function to find dll module base
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoigorr committed Aug 26, 2022
1 parent d1bd6ee commit 190a0f6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
10 changes: 3 additions & 7 deletions Option.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
class Option
{
public:
bool exit;
bool exit = false;

int SCREEN_WIDTH;
int SCREEN_HEIGHT;
void GetDesktopResolution(int& horizontal, int& vertical);

bool bMenu;
bool bGodMode;
bool bMenu = true;
bool bGodMode = false;

// Constructor
Option() {
this->exit = false;
this->bMenu = true;
this->bGodMode = false;

GetDesktopResolution(this->SCREEN_WIDTH, this->SCREEN_HEIGHT);
}
};
Expand Down
10 changes: 4 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// Get Handle to target Process
hProcess = OpenProcess(PROCESS_ALL_ACCESS, NULL, procId);

// Module base address
addr->moduleBase = proc->GetModuleBaseAddress64(procId);
// Proc base address
addr->moduleBase = (uintptr_t)proc->GetModuleBaseAddress64(procId);

addr->unityPlayer = proc->getDllModule((LPSTR)"UnityPlayer.dll");
addr->unityPlayer = (uintptr_t)proc->GetDllModule(L"UnityPlayer.dll", procId);
}
else
{
Expand Down Expand Up @@ -112,10 +112,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
MSG msg;

// Main loop
while (!(GetAsyncKeyState(VK_END)))
while ((!(GetAsyncKeyState(VK_END))) && !option->exit)
{
//if (exit) break;

// Check to see if any messages are waiting in the queue
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
Expand Down
27 changes: 25 additions & 2 deletions proc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,32 @@ DWORD_PTR Proc::GetModuleBaseAddress64(DWORD processID)
return baseAddress;
}

DWORD Proc::getDllModule(LPSTR lpDllName)
DWORD Proc::GetDllModule(const wchar_t* module, DWORD procId)
{
// to do with msdn process32first
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, procId);

if (hSnap == INVALID_HANDLE_VALUE)
{
return 0;
}

MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(MODULEENTRY32);

if (!Module32First(hSnap, &modEntry))
{
return 0;
}

if (!_wcsicmp(modEntry.szModule, module))
return (DWORD)modEntry.modBaseAddr;

while (Module32Next(hSnap, &modEntry))
{
if (!_wcsicmp(modEntry.szModule, module))
return (DWORD)modEntry.modBaseAddr;
}

}

Proc* proc = new Proc();
2 changes: 1 addition & 1 deletion proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Proc

DWORD GetProcId(const wchar_t* procName);
DWORD_PTR GetModuleBaseAddress64(DWORD processID);
DWORD getDllModule(LPSTR lpDllName);
DWORD GetDllModule(const wchar_t* module, DWORD procId);

Proc() {
this->hProcess = 0;
Expand Down

0 comments on commit 190a0f6

Please sign in to comment.