// Test.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#pragma comment(linker, "/entry:main")
typedef void (WINAPI *APITEST)(unsigned int, unsigned int, unsigned int, unsigned int);
//get kernel base image address
unsigned int GetBaseImage()
{
__asm {
mov eax,fs:[30h]
mov eax,[eax+0ch]
mov esi,[eax+1ch]
lodsd
mov eax,[eax+08h] //return
}
}
unsigned int GetAPIFuncAdress(unsigned int nImageBase,const char *pFuncName, int iLen)
{
__asm {
mov eax,nImageBase
mov eax,[eax+0x3c]
add eax,nImageBase //PE header
mov eax,[eax+0x78]
add eax,nImageBase //Data_Directory
mov esi,eax //IMAGE_EXPORT_DIRECTORY
mov ecx,[eax+0x18] //NumberOfName
mov eax,[eax+0x20] //AddressOfName
add eax,nImageBase
mov ebx,eax
xor edx,edx
FindLoop:
push ecx
push esi
mov eax,[eax]
add eax,nImageBase
mov esi,pFuncName
mov edi,eax
mov ecx,iLen
cld
rep cmpsb //compare function
pop esi //pop esi => IMAGE_EXPORT_DIRECTORY
je Found
inc edx
add ebx,4
mov eax,ebx
pop ecx
loop FindLoop
Found:
add esp,4
mov eax,esi
mov eax,[eax+0x1c] //AddressOfFunction
add eax,nImageBase
shl edx,2
add eax,edx
mov eax,[eax]
add eax,nImageBase //eax return
}
}
int main()
{
#if 1
char *szTitle = "title";
char *szMsg = "message";
char *szUserDLL = "User32.dll";
char *szMessagebox = "MessageBoxA";
unsigned int nBaseImage = 0;
unsigned int nLoadLibraryAdress = 0;
unsigned int nGetProcAddress = 0;
nBaseImage = GetBaseImage();
nLoadLibraryAdress = GetAPIFuncAdress(nBaseImage, "LoadLibraryA", 12);
nGetProcAddress = GetAPIFuncAdress(nBaseImage, "GetProcAddress", 14);
__asm {
lea eax,szUserDLL
push eax
call dword ptr nLoadLibraryAdress//eax 0??//每次到这里执行完就为0
lea ebx,szMessagebox
push ebx
push eax
call dword ptr nGetProcAddress
push MB_OK
push szTitle
push szMsg
push NULL
call eax
}
#else//test
char *szUserDLL = "User32.dll";
char *szMessagebox = "MessageBoxA";
char *szTitle = "title";
char *szMsg = "message";
APITEST apitest;
apitest = (APITEST)GetProcAddress(LoadLibraryA(szUserDLL), szMessagebox);
apitest((unsigned int)NULL, (unsigned int)szMsg, (unsigned int)szTitle, (unsigned int)MB_OK);
#endif
ExitProcess(0);
return 0;
}
麻烦高手来看一下执行完call dword ptr nLoadLibraryAdress//eax 0??//每次到这里执行完就为0
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!