#include <Windows.h>
DWORD getKernel32();
FARPROC _GetProcAddress(HMODULE hModule);
int EntryMain() {
HMODULE hAddr = (HMODULE)getKernel32();
typedef FARPROC(WINAPI* FN_GetProcAddress)(
_In_ HMODULE hModule,
_In_ LPCSTR lpProcName
);
FN_GetProcAddress fn_GetProcAddress;
fn_GetProcAddress = (FN_GetProcAddress)_GetProcAddress(hAddr);
typedef HMODULE(WINAPI* FN_LoadLibraryA)(
_In_ LPCSTR lpLibFileName);
char szLoadLibraryA[] = { 'L','o','a','d','L','i','b','r','a','r','y','A',0 };
FN_LoadLibraryA fn_LoadLibraryA = (FN_LoadLibraryA)fn_GetProcAddress(hAddr, szLoadLibraryA);
char szMessageBoxA[] = { 'M', 'e', 's', 's', 'a', 'g', 'e', 'B', 'o', 'x', 'A', 0 };
typedef int(WINAPI* FN_MessageBoxA)(
_In_opt_ HWND hWnd,
_In_opt_ LPCSTR lpText,
_In_opt_ LPCSTR lpCaption,
_In_ UINT uType);
char szUser32[] = { 'U','s','e','r','3','2','.','d','l','l',0 };
FN_MessageBoxA fn_MessageBoxA = (FN_MessageBoxA)fn_GetProcAddress(fn_LoadLibraryA(szUser32), szMessageBoxA);
char szHello[] = { 'b','1','a','c','k','i','e','!',0 };
char szTitle[] = { 't','e','s','t',0 };
fn_MessageBoxA(NULL, szHello, szTitle, NULL);
return 0;
}
_declspec(naked) DWORD getKernel32() {
__asm {
mov eax, fs: [30h]
mov eax, [eax + 0Ch]
mov eax, [eax + 14h]
mov eax, [eax]
mov eax, [eax]
mov eax, [eax + 10h]
ret
}
}
FARPROC _GetProcAddress(HMODULE hModule) {
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hModule;
PIMAGE_NT_HEADERS pNtHeader = (PIMAGE_NT_HEADERS)((DWORD)pDosHeader + pDosHeader->e_lfanew);
PIMAGE_EXPORT_DIRECTORY lpExport = (PIMAGE_EXPORT_DIRECTORY)((DWORD)pDosHeader +
(DWORD)pNtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
PDWORD lpAddressOfNamesArray = (PDWORD)((DWORD)pDosHeader + lpExport->AddressOfNames);
PWORD lpAddressOfNameOrdinalArray = (PWORD)((DWORD)pDosHeader + lpExport->AddressOfNameOrdinals);
PDWORD lpAddressOfFuncArray = (PDWORD)((DWORD)pDosHeader + lpExport->AddressOfFunctions);
DWORD dwNumber = lpExport->NumberOfNames;
DWORD wHint = 0;
FARPROC lpFunc;
for (DWORD i = 0; i < dwNumber; i++) {
char* lpFuncName = (char*)((DWORD)pDosHeader + lpAddressOfNamesArray[i]);
if (lpFuncName[0] == 'G' &&
lpFuncName[1] == 'e' &&
lpFuncName[2] == 't' &&
lpFuncName[3] == 'P' &&
lpFuncName[4] == 'r' &&
lpFuncName[5] == 'o' &&
lpFuncName[6] == 'c' &&
lpFuncName[7] == 'A' &&
lpFuncName[8] == 'd' &&
lpFuncName[9] == 'd' &&
lpFuncName[10] == 'r' &&
lpFuncName[11] == 'e' &&
lpFuncName[12] == 's' &&
lpFuncName[13] == 's') {
wHint = lpAddressOfNameOrdinalArray[i];
lpFunc = (FARPROC)((DWORD)pDosHeader + lpAddressOfFuncArray[wHint]);
break;
}
}
return lpFunc;
}