static void LoadConstants(LoadState* S, Proto* f) { int i,n; n=LoadInt(S); f->k=luaM_newvector(S->L,n,TValue); f->sizek=n; for (i=0; i<n; i++) setnilvalue(&f->k[i]); for (i=0; i<n; i++) { TValue* o=&f->k[i]; int t=LoadChar(S); switch (t) { case LUA_TNIL: setnilvalue(o); break; case LUA_TBOOLEAN: setbvalue(o,LoadChar(S)); break; case LUA_TNUMBER: setnvalue(o,LoadNumber(S)); break; case LUA_TSTRING: setsvalue2n(S->L,o,LoadString(S)); break; default: error(S,"bad constant"); break; } } n=LoadInt(S); f->p=luaM_newvector(S->L,n,Proto*); f->sizep=n; for (i=0; i<n; i++) f->p[i]=NULL; for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source); }
bool CPlugin::Load(const char * FileName) { // Already loaded, so unload first. if (m_LibHandle != NULL) { UnloadPlugin(); } // Try to load the plugin DLL //Try to load the DLL library m_LibHandle = pjutil::DynLibOpen(FileName, bHaveDebugger()); if (m_LibHandle == NULL) { return false; } // Get DLL information void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo); LoadFunction(GetDllInfo); if (GetDllInfo == NULL) { return false; } GetDllInfo(&m_PluginInfo); if (!ValidPluginVersion(m_PluginInfo)) { return false; } if (m_PluginInfo.Type != type()) { return false; } LoadFunction(CloseDLL); LoadFunction(RomOpen); LoadFunction(RomClosed); _LoadFunction("PluginLoaded", PluginOpened); LoadFunction(DllConfig); LoadFunction(DllAbout); LoadFunction(SetSettingInfo3); if (SetSettingInfo3) { PLUGIN_SETTINGS3 info; info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings; SetSettingInfo3(&info); } LoadFunction(SetSettingInfo2); if (SetSettingInfo2) { PLUGIN_SETTINGS2 info; info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting; SetSettingInfo2(&info); } LoadFunction(SetSettingInfo); if (SetSettingInfo) { PLUGIN_SETTINGS info; info.dwSize = sizeof(PLUGIN_SETTINGS); info.DefaultStartRange = GetDefaultSettingStartRange(); info.SettingStartRange = GetSettingStartRange(); info.MaximumSettings = MaxPluginSetting; info.NoDefault = Default_None; info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile; info.handle = g_Settings; info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting; info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting; info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz; info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting; info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz; info.UseUnregisteredSetting = NULL; SetSettingInfo(&info); } if (RomClosed == NULL) { return false; } if (!LoadFunctions()) { return false; } WriteTrace(PluginTraceType(), TraceDebug, "Functions loaded"); if (PluginOpened) { WriteTrace(PluginTraceType(), TraceDebug, "Before Plugin Opened"); PluginOpened(); WriteTrace(PluginTraceType(), TraceDebug, "After Plugin Opened"); } return true; }
static Proto* LoadChunk (LoadState* S) { LoadHeader(S); return LoadFunction(S,NULL); }
static Proto* LoadChunk (lua_State* L, ZIO* Z) { return LoadFunction(L,Z,LoadHeader(L,Z)); }
bool CPlugin::Load(const char * FileName) { // Already loaded, so unload first. if (m_hDll != NULL) { UnloadPlugin(); } // Try to load the plugin DLL //Try to load the DLL library if (bHaveDebugger()) { m_hDll = LoadLibrary(FileName); } else { UINT LastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); m_hDll = LoadLibrary(FileName); SetErrorMode(LastErrorMode); } if (m_hDll == NULL) { return false; } // Get DLL information void(__cdecl *GetDllInfo) (PLUGIN_INFO * PluginInfo); LoadFunction(GetDllInfo); if (GetDllInfo == NULL) { return false; } GetDllInfo(&m_PluginInfo); if (!ValidPluginVersion(m_PluginInfo)) { return false; } if (m_PluginInfo.Type != type()) { return false; } CloseDLL = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "CloseDLL"); RomOpen = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomOpen"); RomClosed = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "RomClosed"); PluginOpened = (void(__cdecl *)(void)) GetProcAddress((HMODULE)m_hDll, "PluginLoaded"); DllConfig = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllConfig"); DllAbout = (void(__cdecl *)(void *)) GetProcAddress((HMODULE)m_hDll, "DllAbout"); SetSettingInfo3 = (void(__cdecl *)(PLUGIN_SETTINGS3 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo3"); if (SetSettingInfo3) { PLUGIN_SETTINGS3 info; info.FlushSettings = (void(*)(void * handle))CSettings::FlushSettings; SetSettingInfo3(&info); } SetSettingInfo2 = (void(__cdecl *)(PLUGIN_SETTINGS2 *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo2"); if (SetSettingInfo2) { PLUGIN_SETTINGS2 info; info.FindSystemSettingId = (uint32_t(*)(void * handle, const char *))CSettings::FindSetting; SetSettingInfo2(&info); } SetSettingInfo = (void(__cdecl *)(PLUGIN_SETTINGS *))GetProcAddress((HMODULE)m_hDll, "SetSettingInfo"); if (SetSettingInfo) { PLUGIN_SETTINGS info; info.dwSize = sizeof(PLUGIN_SETTINGS); info.DefaultStartRange = GetDefaultSettingStartRange(); info.SettingStartRange = GetSettingStartRange(); info.MaximumSettings = MaxPluginSetting; info.NoDefault = Default_None; info.DefaultLocation = g_Settings->LoadDword(Setting_UseFromRegistry) ? SettingType_Registry : SettingType_CfgFile; info.handle = g_Settings; info.RegisterSetting = (void(*)(void *, int, int, SettingDataType, SettingType, const char *, const char *, uint32_t))&CSettings::RegisterSetting; info.GetSetting = (uint32_t(*)(void *, int))&CSettings::GetSetting; info.GetSettingSz = (const char * (*)(void *, int, char *, int))&CSettings::GetSettingSz; info.SetSetting = (void(*)(void *, int, uint32_t))&CSettings::SetSetting; info.SetSettingSz = (void(*)(void *, int, const char *))&CSettings::SetSettingSz; info.UseUnregisteredSetting = NULL; SetSettingInfo(&info); } if (RomClosed == NULL) return false; if (!LoadFunctions()) { return false; } WriteTrace(PluginTraceType(), TraceDebug, "Functions loaded"); if (PluginOpened) { WriteTrace(PluginTraceType(), TraceDebug, "Before Plugin Opened"); PluginOpened(); WriteTrace(PluginTraceType(), TraceDebug, "After Plugin Opened"); } return true; }
int LoadPlugin(struct PluginList* q, HWND hSlit, char** errorMsg) { struct NativePluginInfo* pInfo = c_new(struct NativePluginInfo); int error = 0; bool useslit; int r; char plugin_path[MAX_PATH]; for (;;) { //--------------------------------------- // load the dll if (0 == FindRCFile(plugin_path, q->path, NULL)) { error = error_plugin_dll_not_found; break; } r = SetErrorMode(0); // enable 'missing xxx.dll' system message pInfo->module = LoadLibrary(plugin_path); SetErrorMode(r); if (NULL == pInfo->module) { r = GetLastError(); // char buff[200]; win_error(buff, sizeof buff); // dbg_printf("LoadLibrary::GetLastError %d: %s", r, buff); if (ERROR_MOD_NOT_FOUND == r) error = error_plugin_dll_needs_module; else error = error_plugin_does_not_load; break; } //--------------------------------------- // grab interface functions LoadFunction(pInfo, beginPlugin); LoadFunction(pInfo, beginPluginEx); LoadFunction(pInfo, beginSlitPlugin); LoadFunction(pInfo, endPlugin); LoadFunction(pInfo, pluginInfo); //--------------------------------------- // check interfaces if(!pInfo->endPlugin) BreakWithCode(error, error_plugin_missing_entry); // check whether plugin supports the slit q->canUseSlit = !!pInfo->beginPluginEx || !!pInfo->beginSlitPlugin; if(!q->canUseSlit) q->useSlit = false; useslit = hSlit && q->useSlit; if (!useslit && !pInfo->beginPluginEx && !pInfo->beginPlugin) BreakWithCode(error, error_plugin_missing_entry); //--------------------------------------- // inititalize plugin TRY { if (useslit) { if (pInfo->beginPluginEx) r = pInfo->beginPluginEx(pInfo->module, hSlit); else r = pInfo->beginSlitPlugin(pInfo->module, hSlit); } else { if (pInfo->beginPlugin) r = pInfo->beginPlugin(pInfo->module); else r = pInfo->beginPluginEx(pInfo->module, NULL); } if (BEGINPLUGIN_OK == r) { q->loaderInfo = pInfo; q->inSlit = useslit; } else if (BEGINPLUGIN_FAILED_QUIET != r) { error = error_plugin_fail_to_load; } } EXCEPT(EXCEPTION_EXECUTE_HANDLER) { error = error_plugin_crash_on_load; } break; } // clean up after error if(error) { if (pInfo->module) FreeLibrary(pInfo->module); q->loaderInfo = NULL; c_del(pInfo); } return error; }
static void CPROC DoStart2( void ) # endif { #ifdef WIN32 //lprintf( WIDE("Begin impersonation...") ); ImpersonateInteractiveUser(); #endif //lprintf( WIDE("Begin impersonation2...") ); # ifndef LOAD_LIBNAME if( my_argc > 1 ) { hModule = LoadFunction( libname = my_argv[1], NULL ); if( hModule ) arg_offset++; } # endif if( !hModule ) { # ifdef LOAD_LIBNAME SetCurrentPath( GetProgramPath() ); hModule = LoadFunction( libname = _WIDE(LOAD_LIBNAME), NULL ); if( !hModule ) { # ifndef UNDER_CE lprintf( WIDE("error: (%")_32fs WIDE(")%s") , GetLastError() , strerror(GetLastError()) ); # endif # ifdef BUILD_SERVICE_THREAD return 0; # else return; # endif } else arg_offset = 0; # else lprintf( WIDE("strerror(This is NOT right... what's the GetStrError?): (%ld)%s") , GetLastError() , strerror(GetLastError()) ); # ifdef BUILD_SERVICE_THREAD return 0; # else return; # endif # endif } { Main = (MainFunction)LoadFunction( libname, WIDE( "_Main" ) ); if( !Main ) Main = (MainFunction)LoadFunction( libname, WIDE( "Main" ) ); if( !Main ) Main = (MainFunction)LoadFunction( libname, WIDE( "Main_" ) ); if( Main ) { // main should be considered windowd.... (no console for output either) Main( my_argc-arg_offset, my_argv+arg_offset, FALSE ); } else { Begin = (BeginFunction)LoadFunction( libname, WIDE( "_Begin" ) ); if( !Begin ) Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin" ) ); if( !Begin ) Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin_" ) ); if( Begin ) { int xlen, ofs, arg; for( arg = arg_offset, xlen = 0; arg < my_argc; arg++, xlen += snprintf( NULL, 0, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), my_argv[arg] ) ); x = (TEXTCHAR*)malloc( ++xlen ); for( arg = arg_offset, ofs = 0; arg < my_argc; arg++, ofs += snprintf( x + ofs, xlen - ofs, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), my_argv[arg] ) ); Begin( x, MODE ); // pass console defined in Makefile free( x ); } else { Start = (StartFunction)LoadFunction( libname, WIDE( "_Start" ) ); if( !Start ) Start = (StartFunction)LoadFunction( libname, WIDE( "Start" ) ); if( !Start ) Start = (StartFunction)LoadFunction( libname, WIDE( "Start_" ) ); if( Start ) { Start( ); } } } } # ifdef BUILD_SERVICE_THREAD return 0; # endif }
SaneWinMain( argc, argv ) { { #ifndef BUILD_SERVICE #ifndef LOAD_LIBNAME if( argc > 1 ) { hModule = LoadFunction( libname = argv[1], NULL ); if( hModule ) arg_offset++; } #endif if( !hModule ) { #ifdef LOAD_LIBNAME hModule = LoadFunction( libname = _WIDE(LOAD_LIBNAME), NULL ); if( !hModule ) { #ifndef UNDER_CE lprintf( WIDE("error: (%")_32fs WIDE(")%s") , GetLastError() , strerror(GetLastError()) ); #endif return 0; } else arg_offset = 0; #else lprintf( WIDE("strerror(This is NOT right... what's the GetStrError?): (%ld)%s") , GetLastError() , strerror(GetLastError()) ); return 0; #endif } #endif my_argc = argc; my_argv = argv; #ifdef BUILD_SERVICE { // look through command line, and while -L options exist, use thsoe to load more libraries // then pass the final remainer to the proc (if used) #ifdef _WIN32 for( ; arg_offset < argc; arg_offset++ ) { if( StrCaseCmp( argv[arg_offset], WIDE("install") ) == 0 ) { ServiceInstall( GetProgramName() ); return 0; } if( StrCaseCmp( argv[arg_offset], WIDE("uninstall") ) == 0 ) { ServiceUninstall( GetProgramName() ); return 0; } } // need to do this before windows are created? #ifdef BUILD_SERVICE_THREAD xlprintf(2400)( WIDE("Go To Service. %s"), GetProgramName() ); SetupServiceThread( (TEXTSTR)GetProgramName(), DoStart2, 0 ); #else xlprintf(2400)( WIDE("Go To Service. %s"), GetProgramName() ); SetupService( (TEXTSTR)GetProgramName(), DoStart2 ); #endif #endif } #endif #ifndef BUILD_SERVICE { Main = (MainFunction)LoadFunction( libname, WIDE( "_Main" ) ); if( !Main ) Main = (MainFunction)LoadFunction( libname, WIDE( "Main" ) ); if( !Main ) Main = (MainFunction)LoadFunction( libname, WIDE( "Main_" ) ); if( Main ) { Main( argc-arg_offset, argv+arg_offset, MODE ); } else { Begin = (BeginFunction)LoadFunction( libname, WIDE( "_Begin" ) ); if( !Begin ) Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin" ) ); if( !Begin ) Begin = (BeginFunction)LoadFunction( libname, WIDE( "Begin_" ) ); if( Begin ) { int xlen, ofs, arg; for( arg = arg_offset, xlen = 0; arg < argc; arg++, xlen += snprintf( NULL, 0, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), argv[arg] ) ); x = (TEXTCHAR*)malloc( ++xlen ); for( arg = arg_offset, ofs = 0; arg < argc; arg++, ofs += snprintf( (TEXTCHAR*)x + ofs, xlen - ofs, WIDE( "%s%s" ), arg?WIDE( " " ):WIDE( "" ), argv[arg] ) ); Begin( x, MODE ); // pass console defined in Makefile free( x ); } else { Start = (StartFunction)LoadFunction( libname, WIDE( "_Start" ) ); if( !Start ) Start = (StartFunction)LoadFunction( libname, WIDE( "Start" ) ); if( !Start ) Start = (StartFunction)LoadFunction( libname, WIDE( "Start_" ) ); if( Start ) { Start( ); } } } } #endif } return 0; }
int __stdcall LoadMexDLL(int index, const TCHAR* szPrimarySearchPath, const TCHAR* szCallingModul, BOOL bContinueSearch) { int i=0; int wl=0; int wwl=0; int l=0; int loadedfunctions=0; int check=0; int count=0; HINSTANCE hInst=NULL; WCHAR * wszPrimarySearchPath=NULL; WCHAR * wszCallingModul=NULL; WCHAR * p = NULL; WCHAR wszSearchPath[_MAX_PATH]; memset(wszSearchPath,0,sizeof(wszSearchPath)); // conversion of calling parameter to UNICODE if(szPrimarySearchPath) { #ifdef UNICODE l=wcslen(szPrimarySearchPath)+1;// terminating zero inclusive wszPrimarySearchPath=(WCHAR*)malloc(l*sizeof(WCHAR));//new WCHAR[l]; if(wszPrimarySearchPath) { wcscpy(wszPrimarySearchPath,szPrimarySearchPath); } #else l=strlen(szPrimarySearchPath)+1;// terminating zero inclusive wl=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,szPrimarySearchPath,-1,wszPrimarySearchPath,0); if(wl>0) { wszPrimarySearchPath=(WCHAR*)malloc(wl*sizeof(WCHAR));//new WCHAR[wl]; wwl=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,szPrimarySearchPath,-1,wszPrimarySearchPath,wl); } #endif } if(szCallingModul) { #ifdef UNICODE l=wcslen(szCallingModul)+1;// terminating zero inclusive wszCallingModul=(WCHAR*)malloc(l*sizeof(WCHAR));//new WCHAR[l]; if(wszCallingModul) { wcscpy(wszCallingModul,szCallingModul); } #else l=strlen(szCallingModul)+1;// terminating zero inclusive wl=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,szCallingModul,-1,wszCallingModul,0); if(wl>0) { wszCallingModul=(WCHAR*)malloc(wl*sizeof(WCHAR));//new WCHAR[wl]; wwl=MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,szCallingModul,-1,wszCallingModul,wl); } #endif } if(0<= index && index <2) { if(NULL==hInstDLL) { if(wszPrimarySearchPath!=NULL) { wcscpy(wszSearchPath,wszPrimarySearchPath); l=wcslen(wszSearchPath); } else if(szCallingModul!=NULL) { hInst=GetModuleHandleW(wszCallingModul); l=GetModuleFileNameW(hInst,wszSearchPath,_MAX_PATH); if(l>0) { p=wcsrchr(wszSearchPath,'\\'); if(p && p!=&wszSearchPath[l-1]) { *(p+1)=L'\0'; wcscat(wszSearchPath,szMexDLL[index]); l=wcslen(wszSearchPath); } } } else { l=GetModuleFileNameW(NULL,wszSearchPath,_MAX_PATH); p=wcsrchr(wszSearchPath,'\\'); if(p) { *p=L'\0'; --l; } } if(l>0) // SearchPath to use { p=wcsrchr(wszSearchPath,'\\'); if(p==NULL) { if(_wcsicmp(wszSearchPath,szMexDLL[index])) wcscat(wszSearchPath,L"\\"); wcscat(wszSearchPath,szMexDLL[index]); } else { if(wszSearchPath[l-1]!=L'\\') { if(_wcsicmp(p+1,szMexDLL[index])) { wcscat(wszSearchPath,L"\\"); wcscat(wszSearchPath,szMexDLL[index]); } } else { wcscat(wszSearchPath,szMexDLL[index]); } } hInstDLL=LoadLibraryExW(wszSearchPath,NULL,LOAD_WITH_ALTERED_SEARCH_PATH); if(hInstDLL==NULL && bContinueSearch) { hInstDLL=LoadLibraryExW(szMexDLL[index],NULL,0); } } else // no SearchPath to use { hInstDLL=LoadLibraryExW(szMexDLL[index],NULL,0); } // free local allocated string memory if(wszPrimarySearchPath) { free(wszPrimarySearchPath); wszPrimarySearchPath=NULL; } if(wszCallingModul) { free(wszCallingModul); wszCallingModul=NULL; } if(hInstDLL!=NULL) { count=FUNCOUNT[index]; for(i=0; i<=count; i++) { LoadFunction(i); if((check=CheckMexFunction(i,NULL,0))==2) loadedfunctions++; } globalindex=index; } } else { loadedfunctions=0; if(0<=globalindex && globalindex < 2) { count=FUNCOUNT[globalindex]; for(i=0; i<=count; i++) { if((check=CheckMexFunction(i,NULL,0))==2) loadedfunctions++; } } } } return loadedfunctions; }
void Init() { self = dlopen(NULL, RTLD_LAZY); LoadFunction("glBeginQuery", (void**)&glBeginQuery); LoadFunction("glEndQuery", (void**)&glEndQuery); LoadFunction("glGetQueryObjectuiv", (void**)&glGetQueryObjectuiv); LoadFunction("glDeleteQueries", (void**)&glDeleteQueries); LoadFunction("glGenQueries", (void**)&glGenQueries); { LoadFunction("glUnmapBuffer", (void**)&glUnmapBuffer); LoadFunction("glMapBufferRange", (void**)&glMapBufferRange); LoadFunction("glBindBufferRange", (void**)&glBindBufferRange); LoadFunction("glBlitFramebuffer", (void**)&glBlitFramebuffer); LoadFunction("glGenVertexArrays", (void**)&glGenVertexArrays); LoadFunction("glDeleteVertexArrays", (void**)&glDeleteVertexArrays); LoadFunction("glBindVertexArray", (void**)&glBindVertexArray); LoadFunction("glClientWaitSync", (void**)&glClientWaitSync); LoadFunction("glDeleteSync", (void**)&glDeleteSync); LoadFunction("glFenceSync", (void**)&glFenceSync); LoadFunction("glSamplerParameterf", (void**)&glSamplerParameterf); LoadFunction("glSamplerParameteri", (void**)&glSamplerParameteri); LoadFunction("glSamplerParameterfv", (void**)&glSamplerParameterfv); LoadFunction("glBindSampler", (void**)&glBindSampler); LoadFunction("glDeleteSamplers", (void**)&glDeleteSamplers); LoadFunction("glGenSamplers", (void**)&glGenSamplers); } LoadFunction("glGetProgramBinary", (void**)&glGetProgramBinary); LoadFunction("glProgramBinary", (void**)&glProgramBinary); LoadFunction("glProgramParameteri", (void**)&glProgramParameteri); LoadFunction("glDrawRangeElements", (void**)&glDrawRangeElements); LoadFunction("glGetUniformBlockIndex", (void**)&glGetUniformBlockIndex); LoadFunction("glUniformBlockBinding", (void**)&glUniformBlockBinding); dlclose(self); }