#include <iostream>
#include <windows.h>
using std::cout;
using std::cin;
using std::endl;
void auth()
{
cout << "CALLED FUNCTION auth()" << endl;
}
int main()
{
void (*funcPtr)() = &auth;
cout << "Address of auth: " << (void*)funcPtr << endl;
while (true)
{
if (GetAsyncKeyState(VK_F8) & 1)
{
auth();
}
}
return 0;
}
void (*funcPtr)() = &auth;
cout << "Address of auth: " << (void*)funcPtr << endl;
// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include <Windows.h>
#include <string>
#include <iostream>
using namespace std;
typedef void()__stdcall* _auth)();
_auth auth = nullptr;
DWORD WINAPI MainThread(LPVOID param)
{
uintptr_t modBase = (uintptr_t)GetModuleHandle(NULL);
auth = (_auth)(modBase + 0x1040);
cout << "[+] MOD BASE: 0x" << std::hex << modBase << endl;
cout << "[+] FUNCTION ADDRESS: 0x" << std::hex << (uintptr_t)auth << endl;
MEMORY_BASIC_INFORMATION mbi;
if (VirtualQuery((LPCVOID)auth, &mbi, sizeof(mbi)))
{
if (mbi.Protect & (PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE))
{
cout << "[+] CAN BE EXECUTED" << endl;
}
else
{
cout << "[-] CANNOT BE EXECUTED" << endl;
}
}
else
{
cout << "[-] ERROR VirtualQuery for auth function address" << endl;
}
while (!GetAsyncKeyState(VK_END))
{
if (GetAsyncKeyState(VK_F9) & 1)
{
__try
{
//cout << "0x" << std::hex << modBase << endl;
auth();
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DWORD errorCode = GetExceptionCode();
cout << "[-] EXCEPTION auth() CALL, CODE ERROR: 0x" << std::hex << errorCode << endl;
}
}
}
FreeLibraryAndExitThread((HMODULE)param, 0);
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateThread(0, 0, MainThread, hModule, 0, 0);
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
original_auth = (auth_type)GetProcAddress(NULL, "auth");. original_auth равняется nullptr, хотя должно равняться адресу функции auth()