Nytro Posted June 11, 2011 Report Posted June 11, 2011 [C] CallAPIByNameLPVOID GetProcAddressEx(HMODULE hModule, LPCSTR lpProcName){ DWORD dwModule = (DWORD)hModule; IMAGE_DOS_HEADER *Image_Dos_Header = (IMAGE_DOS_HEADER *)(dwModule); IMAGE_NT_HEADERS *Image_Nt_Headers = (IMAGE_NT_HEADERS *)(dwModule + Image_Dos_Header->e_lfanew); IMAGE_EXPORT_DIRECTORY *Image_Export_Directory = (IMAGE_EXPORT_DIRECTORY *)(dwModule + Image_Nt_Headers->OptionalHeader.DataDirectory->VirtualAddress); unsigned int nNumber; for (nNumber = 0; Image_Export_Directory->NumberOfNames; ++nNumber) { LPSTR lpAddressOfNames = ((*(LPSTR *)(Image_Export_Directory->AddressOfNames + dwModule + nNumber * sizeof(DWORD))) + dwModule); if (!lstrcmpA(lpProcName, lpAddressOfNames)) { USHORT Ordinal = (*(USHORT *)(Image_Export_Directory->AddressOfNameOrdinals + dwModule + nNumber * sizeof(USHORT))); return (LPINT)((DWORD)*(LPVOID *)(Image_Export_Directory->AddressOfFunctions + dwModule + Ordinal * sizeof(LPVOID)) + dwModule); } } return NULL;}LPVOID WINAPI Invoke(LPCWSTR lpModuleName, LPCSTR lpProcName, int count, ...){ HMODULE hModule; LPVOID lpProcAddress, lpResult = NULL; va_list list; void **args = (void **) HeapAlloc(GetProcessHeap(), 0, count); int x; if ((hModule = LoadLibrary(lpModuleName)) != 0) { if ((lpProcAddress = GetProcAddressEx(hModule,lpProcName)) != 0) { va_start(list,count); for (x = 0; x < count; x++) args[x] = va_arg(list, void *); for (x = count -1; x >= 0; x--) { int temp = x * 4; __asm { mov eax, dword ptr args add eax, temp push [eax] } } __asm { call lpProcAddress mov lpResult,eax } } } va_end(list); HeapFree(GetProcessHeap(), 0, args); FreeLibrary(hModule); return lpResult;}Example:Invoke(L"USER32.DLL", "MessageBoxW", 4, 0, L"Hello World", L"Info!", 0);Sursa: CallAPIByName [C] Quote