Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // == Windows API GetProcAddress
- void *PeGetProcAddressA(void *Base, LPCSTR Name)
- {
- DWORD Tmp;
- IMAGE_NT_HEADERS *NT=ImageNtHeader(Base);
- IMAGE_EXPORT_DIRECTORY *Exp=(IMAGE_EXPORT_DIRECTORY*)ImageDirectoryEntryToDataEx(Base,TRUE,IMAGE_DIRECTORY_ENTRY_EXPORT,&Tmp,0);
- if(Exp==0 || Exp->NumberOfFunctions==0)
- {
- SetLastError(ERROR_NOT_FOUND);
- return 0;
- }
- DWORD *Names=(DWORD*)(Exp->AddressOfNames+(DWORD_PTR)Base);
- WORD *Ordinals=(WORD*)(Exp->AddressOfNameOrdinals+(DWORD_PTR)Base);
- DWORD *Functions=(DWORD*)(Exp->AddressOfFunctions+(DWORD_PTR)Base);
- FARPROC Ret=0;
- if((DWORD_PTR)Name<65536)
- {
- if((DWORD_PTR)Name-Exp->Base<Exp->NumberOfFunctions)
- Ret=(FARPROC)(Functions[(DWORD_PTR)Name-Exp->Base]+(DWORD_PTR)Base);
- } else
- {
- for(DWORD i=0; i<Exp->NumberOfNames && Ret==0; i++)
- {
- char *Func=(char*)(Names[i]+(DWORD_PTR)Base);
- if(Func && strcmp(Func,Name)==0)
- Ret=(FARPROC)(Functions[Ordinals[i]]+(DWORD_PTR)Base);
- }
- }
- if(Ret)
- {
- DWORD ExpStart=NT->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress+(DWORD)Base;
- DWORD ExpSize=NT->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size;
- if((DWORD)Ret>=ExpStart && (DWORD)Ret<=ExpStart+ExpSize)
- {
- // Forwarder
- return 0;
- }
- return Ret;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement