Beispiel #1
0
static T *get_interface( const char *mod_name, const char *interface_name, bool exact = false ) {
	T *iface = nullptr;
	InterfaceReg *register_list;
	int part_match_len = strlen( interface_name );

	DWORD interface_fn = reinterpret_cast<DWORD>( GetProcAddress( GetModuleHandleA( mod_name ), "CreateInterface" ) );

	if ( !interface_fn ) {
		return nullptr;
	}

	unsigned int jump_start = ( unsigned int )( interface_fn )+4;
	unsigned int jump_target = jump_start + *( unsigned int* )( jump_start + 1 ) + 5;

	register_list = **reinterpret_cast<InterfaceReg***>( jump_target + 6 );

	for ( InterfaceReg *cur = register_list; cur; cur = cur->m_pNext ) {
		if ( exact == true ) {
			if ( strcmp( cur->m_pName, interface_name ) == 0 )
				iface = reinterpret_cast<T*>( cur->m_CreateFn( ) );
		} else {
			if ( !strncmp( cur->m_pName, interface_name, part_match_len ) && std::atoi( cur->m_pName + part_match_len ) > 0 )
				iface = reinterpret_cast<T*>( cur->m_CreateFn( ) );
		}
	}
	return iface;
}
Beispiel #2
0
// ------------------------------------------------------------------------------------ //
// CreateInterface.
// ------------------------------------------------------------------------------------ //
EXPORT_FUNCTION IBaseInterface *CreateInterface( const char *pName, int *pReturnCode )
{
	InterfaceReg *pCur;
	
	for(pCur=InterfaceReg::s_pInterfaceRegs; pCur; pCur=pCur->m_pNext)
	{
		if(strcmp(pCur->m_pName, pName) == 0)
		{
			if ( pReturnCode )
			{
				*pReturnCode = IFACE_OK;
			}
			return pCur->m_CreateFn();
		}
	}
	
	if ( pReturnCode )
	{
		*pReturnCode = IFACE_FAILED;
	}
	return NULL;	
}