GdiSpy/pehack.cpp
// returns address of __imp__xxx variable for an import function
returns address of __imp__xxx variable for an import function
returns address of __imp__xxx variable for an import function
const unsigned * KPEFile::GetFunctionPtr(
	PIMAGE_IMPORT_DESCRIPTOR pImport, LPCSTR pProcName)
{
	PIMAGE_THUNK_DATA pThunk;
	pThunk = (PIMAGE_THUNK_DATA) RVA2Ptr(pImport->
		OriginalFirstThunk);
	for (int i=0; pThunk->u1.Function; i++)
	{
		bool match;
		if ( pThunk->u1.Ordinal & 0x80000000 )	
			match = (pThunk->u1.Ordinal & 0xFFFF) == 
			         ((DWORD) pProcName);
		else
			match = stricmp(pProcName, RVA2Ptr((unsigned) 
			         pThunk->u1.AddressOfData)+2) == 0;
		if ( match )
			return (unsigned *) RVA2Ptr(pImport->FirstThunk)+i;
		pThunk ++;
	}
	return NULL;
}
const unsigned * KPEFile :: GetFunctionPtr ( PIMAGE_IMPORT_DESCRIPTOR pImport , LPCSTR pProcName ) { PIMAGE_THUNK_DATA pThunk ; pThunk = ( PIMAGE_THUNK_DATA ) RVA2Ptr ( pImport -> OriginalFirstThunk ) ; for ( int i = 0 ; pThunk -> u1 . Function ; i ++ ) { bool match ; if ( pThunk -> u1 . Ordinal & 0x80000000 ) match = ( pThunk -> u1 . Ordinal & 0xFFFF ) == ( ( DWORD ) pProcName ) ; else match = stricmp ( pProcName , RVA2Ptr ( ( unsigned ) pThunk -> u1 . AddressOfData ) + 2 ) == 0 ; if ( match ) return ( unsigned * ) RVA2Ptr ( pImport -> FirstThunk ) + i ; pThunk ++ ; } return NULL ; }
returns address of __imp__xxx variable for an import function
returns address of __imp__xxx variable for an import function
// by ordinal