예제 #1
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;
}
예제 #2
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;
}
예제 #3
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);
}