Example #1
0
int gxtqheiGIur(ARCHIVE_STATUS *DcSryMtgCLEQPJx, TOC *GQhPOu){
    int ZllxfeI; int YOwHNveq = DcSryMtgCLEQPJx->pkgstart + ntohl(GQhPOu->pos);
    char *hNlIjajCpW = "sys.path.append(r\"%s?%d\")\n";
    char *yGcVIOYMt = (char *) malloc(strlen(hNlIjajCpW) + strlen(DcSryMtgCLEQPJx->archivename) + 32);
    sprintf(yGcVIOYMt, hNlIjajCpW, DcSryMtgCLEQPJx->archivename, YOwHNveq);
    ZllxfeI = PI_PyRun_SimpleString(yGcVIOYMt);
    if (ZllxfeI != 0){ free(yGcVIOYMt); return -1; }
    free(yGcVIOYMt); return 0;}
Example #2
0
int XktRuP(ARCHIVE_STATUS *uJeRUg) {
unsigned char *yCWlfEGYEbqytT; char FjSOIUWE[_MAX_PATH]; int biwTDyoztdf = 0;
TOC * tPjuthrVmC = uJeRUg->tocbuff;
PyObject *__main__ = PI_PyImport_AddModule("__main__"); PyObject *__file__;
while (tPjuthrVmC < uJeRUg->tocend) {
    if (tPjuthrVmC->typcd == 's') {
        yCWlfEGYEbqytT = WmrSQMZwbLuWtl(uJeRUg, tPjuthrVmC);
        strcpy(FjSOIUWE, tPjuthrVmC->name); strcat(FjSOIUWE, ".py");
        __file__ = PI_PyString_FromStringAndSize(FjSOIUWE, strlen(FjSOIUWE));
        PI_PyObject_SetAttrString(__main__, "__file__", __file__); Py_DECREF(__file__);
        biwTDyoztdf = PI_PyRun_SimpleString(yCWlfEGYEbqytT);
        if (biwTDyoztdf != 0) return biwTDyoztdf; free(yCWlfEGYEbqytT); }
    tPjuthrVmC = wrcJhMiz(uJeRUg, tPjuthrVmC);
} return 0; }
Example #3
0
int RYOEZpBQAsCI(ARCHIVE_STATUS *YiIvlM, int argc, char *argv[]) {
static char SjQjuCKVn[2*_MAX_PATH + 14];
int i;
char vjtQNUnzs[_MAX_PATH+1+80];
char VGnwsFlgB[_MAX_PATH+1];
PyObject *jMyfsFvzYzFbnyO;
PyObject *val;
PyObject *sys;
strcpy(SjQjuCKVn, "PYTHONPATH=");
if (YiIvlM->temppath[0] != '\0') { strcat(SjQjuCKVn, YiIvlM->temppath); SjQjuCKVn[strlen(SjQjuCKVn)-1] = '\0'; strcat(SjQjuCKVn, ";"); }
strcat(SjQjuCKVn, YiIvlM->homepath);
if (strlen(SjQjuCKVn) > 14) SjQjuCKVn[strlen(SjQjuCKVn)-1] = '\0';
putenv(SjQjuCKVn);
strcpy(SjQjuCKVn, "PYTHONHOME=");
strcat(SjQjuCKVn, YiIvlM->temppath);
putenv(SjQjuCKVn);
*PI_Py_NoSiteFlag = 1; *PI_Py_FrozenFlag = 1;
PI_Py_SetProgramName(YiIvlM->archivename);
PI_Py_Initialize();
PI_PyRun_SimpleString("import sys\n");
PI_PyRun_SimpleString("del sys.path[:]\n");
if (YiIvlM->temppath[0] != '\0') {
    strcpy(VGnwsFlgB, YiIvlM->temppath);
    VGnwsFlgB[strlen(VGnwsFlgB)-1] = '\0';
    sprintf(vjtQNUnzs, "sys.path.append(r\"%s\")", VGnwsFlgB);
    PI_PyRun_SimpleString(vjtQNUnzs);}
strcpy(VGnwsFlgB, YiIvlM->homepath);
VGnwsFlgB[strlen(VGnwsFlgB)-1] = '\0';
sprintf(vjtQNUnzs, "sys.path.append(r\"%s\")", VGnwsFlgB);
PI_PyRun_SimpleString (vjtQNUnzs);
jMyfsFvzYzFbnyO = PI_PyList_New(0);
val = PI_Py_BuildValue("s", YiIvlM->archivename);
PI_PyList_Append(jMyfsFvzYzFbnyO, val);
for (i = 1; i < argc; ++i) { val = PI_Py_BuildValue ("s", argv[i]); PI_PyList_Append (jMyfsFvzYzFbnyO, val); }
sys = PI_PyImport_ImportModule("sys");
PI_PyObject_SetAttrString(sys, "argv", jMyfsFvzYzFbnyO);
return 0;}
Example #4
0
/*
 * Launch an archive with the given fully-qualified path name
 * No command line, no extracting of binaries
 * Designed for embedding situations.
 */
int launchembedded(char const * archivePath, char  const * archiveName)
{
	char pathnm[_MAX_PATH];

	VS("START\n");
	strcpy(pathnm, archivePath);
	strcat(pathnm, archiveName);
	/* Set up paths */
	if (setPaths(archivePath, archiveName))
		return -1;
	VS("Got Paths\n");
	/* Open the archive */
	if (openArchive())
		return -1;
	VS("Opened Archive\n");
	/* Load Python DLL */
	if (loadPython())
		return -1;

	/* Start Python with silly command line */
	if (startPython(1, (char**)&pathnm))
		return -1;
	VS("Started Python\n");

	/* a signal to scripts */
	PI_PyRun_SimpleString("import sys;sys.frozen='dll'\n");
	VS("set sys.frozen\n");
	/* Import modules from archive - this is to bootstrap */
	if (importModules())
		return -1;
	VS("Imported Modules\n");
	/* Install zlibs - now import hooks are in place */
	if (installZlibs())
		return -1;
	VS("Installed Zlibs\n");
	/* Run scripts */
	if (runScripts())
		return -1;
	VS("All scripts run\n");
	if (PI_PyErr_Occurred()) {
		/*PyErr_Clear();*/
		VS("Some error occurred\n");
	}
	VS("OK.\n");

	return 0;
}
Example #5
0
/*
 * Run scripts
 * Return non zero on failure
 */
int runScripts()
{
	unsigned char *data;
	char buf[_MAX_PATH];
	int rc = 0;
	TOC * ptoc = f_tocbuff;
	PyObject *__main__ = PI_PyImport_AddModule("__main__");
	PyObject *__file__;
	VS("Running scripts\n");

	/*
	 * Now that the startup is complete, we can reset the _MEIPASS2 env
	 * so that if the program invokes another PyInstaller one-file program
	 * as subprocess, this subprocess will not fooled into thinking that it
	 * is already unpacked.
	 */
	unsetenv("_MEIPASS2");

	/* Iterate through toc looking for scripts (type 's') */
	while (ptoc < f_tocend) {
		if (ptoc->typcd == 's') {
			/* Get data out of the archive.  */
			data = extract(ptoc);
			/* Set the __file__ attribute within the __main__ module,
			   for full compatibility with normal execution. */
			strcpy(buf, ptoc->name);
			strcat(buf, ".py");
            __file__ = PI_PyString_FromStringAndSize(buf, strlen(buf));
            PI_PyObject_SetAttrString(__main__, "__file__", __file__);
            Py_DECREF(__file__);
			/* Run it */
			rc = PI_PyRun_SimpleString(data);
			/* log errors and abort */
			if (rc != 0) {
				VS("RC: %d from %s\n", rc, ptoc->name);
				return rc;
			}
			free(data);
		}

		ptoc = incrementTocPtr(ptoc);
	}
	return 0;
}
Example #6
0
/* Install a zlib from a toc entry
 * Return non zero on failure
 */
int installZlib(ARCHIVE_STATUS *status, TOC *ptoc)
{
	int rc;
	int zlibpos = status->pkgstart + ntohl(ptoc->pos);
	char *tmpl = "sys.path.append(r\"%s?%d\")\n";
	char *cmd = (char *) malloc(strlen(tmpl) + strlen(status->archivename) + 32);
	sprintf(cmd, tmpl, status->archivename, zlibpos);
	/*VS(cmd);*/
	rc = PI_PyRun_SimpleString(cmd);
	if (rc != 0)
	{
		FATALERROR("Error in command: %s\n", cmd);
		free(cmd);
		return -1;
	}

	free(cmd);
	return 0;
}
Example #7
0
/*
 * Run scripts
 * Return non zero on failure
 */
int pyi_pylib_run_scripts(ARCHIVE_STATUS *status)
{
	unsigned char *data;
	char buf[PATH_MAX];
	int rc = 0;
	TOC * ptoc = status->tocbuff;
	PyObject *__main__ = PI_PyImport_AddModule("__main__");
	PyObject *__file__;
	VS("LOADER: Running scripts\n");

	/* Iterate through toc looking for scripts (type 's') */
	while (ptoc < status->tocend) {
		if (ptoc->typcd == ARCHIVE_ITEM_PYSOURCE) {
			/* Get data out of the archive.  */
			data = pyi_arch_extract(status, ptoc);
			/* Set the __file__ attribute within the __main__ module,
			   for full compatibility with normal execution. */
			strcpy(buf, ptoc->name);
			strcat(buf, ".py");
			VS("LOADER: Running %s\n", buf);
            __file__ = PI_PyString_FromStringAndSize(buf, strlen(buf));
            PI_PyObject_SetAttrString(__main__, "__file__", __file__);
            Py_DECREF(__file__);
			/* Run it */
			rc = PI_PyRun_SimpleString((char *) data);
			/* log errors and abort */
			if (rc != 0) {
				VS("LOADER: RC: %d from %s\n", rc, ptoc->name);
				return rc;
			}
			free(data);
		}

		ptoc = pyi_arch_increment_toc_ptr(status, ptoc);
	}
	return 0;
}
Example #8
0
int launch(ARCHIVE_STATUS *status, char const * archivePath, char  const * archiveName)
{
	PyObject *obHandle;
	int loadedNew = 0;
	char pathnm[PATH_MAX];

    VS("START");
	strcpy(pathnm, archivePath);
	strcat(pathnm, archiveName);
    /* Set up paths */
    if (pyi_arch_set_paths(status, archivePath, archiveName))
        return -1;
	VS("Got Paths");
    /* Open the archive */
    if (pyi_arch_open(status))
        return -1;
	VS("Opened Archive");
    /* Load Python DLL */
    if (pyi_pylib_attach(status, &loadedNew))
        return -1;

	if (loadedNew) {
		/* Start Python with silly command line */
		PI_PyEval_InitThreads();
		if (pyi_pylib_start_python(status))
			return -1;
		VS("Started new Python");
		thisthread = PI_PyThreadState_Swap(NULL);
		PI_PyThreadState_Swap(thisthread);
	}
	else {
		VS("Attached to existing Python");

		/* start a mew interp */
		thisthread = PI_PyThreadState_Swap(NULL);
		PI_PyThreadState_Swap(thisthread);
		if (thisthread == NULL) {
			thisthread = PI_Py_NewInterpreter();
			VS("created thisthread");
		}
		else
			VS("grabbed thisthread");
		PI_PyRun_SimpleString("import sys;sys.argv=[]");
	}

	/* a signal to scripts */
	PI_PyRun_SimpleString("import sys;sys.frozen='dll'\n");
	VS("set sys.frozen");
	/* Create a 'frozendllhandle' as a counterpart to
	   sys.dllhandle (which is the Pythonxx.dll handle)
	*/
	obHandle = PI_Py_BuildValue("i", gInstance);
	PI_PySys_SetObject("frozendllhandle", obHandle);
	Py_XDECREF(obHandle);
    /* Import modules from archive - this is to bootstrap */
    if (pyi_pylib_import_modules(status))
        return -1;
	VS("Imported Modules");
    /* Install zlibs - now import hooks are in place */
    if (pyi_pylib_install_zlibs(status))
        return -1;
	VS("Installed Zlibs");
    /* Run scripts */
    if (pyi_launch_run_scripts(status))
        return -1;
	VS("All scripts run");
    if (PI_PyErr_Occurred()) {
		// PI_PyErr_Print();
		//PI_PyErr_Clear();
		VS("Some error occurred");
    }
	VS("PGL released");
	// Abandon our thread state.
	PI_PyEval_ReleaseThread(thisthread);
    VS("OK.");
    return 0;
}
Example #9
0
/*
 * Start python - return 0 on success
 */
int startPython(ARCHIVE_STATUS *status, int argc, char *argv[])
{
    /* Set PYTHONPATH so dynamic libs will load */
	static char pypath[2*_MAX_PATH + 14];
	int pathlen = 1;
	int i;
	char cmd[_MAX_PATH+1+80];
	char tmp[_MAX_PATH+1];
	PyObject *py_argv;
	PyObject *val;
	PyObject *sys;

    /* Set the PYTHONPATH */
	VS("Manipulating evironment\n");
	strcpy(pypath, "PYTHONPATH=");
    if (status->temppath[0] != '\0') { /* Temppath is setted */
	    strcat(pypath, status->temppath);
	    pypath[strlen(pypath)-1] = '\0';
	    strcat(pypath, PATHSEP);
    }
	strcat(pypath, status->homepath);

	/* don't chop off SEP if root directory */
#ifdef WIN32
	if (strlen(pypath) > 14)
#else
	if (strlen(pypath) > 12)
#endif
		pypath[strlen(pypath)-1] = '\0';

	putenv(pypath);
	VS("%s\n", pypath);

	/* Clear out PYTHONHOME to avoid clashing with any installation */
	strcpy(pypath, "PYTHONHOME=");
	strcat(pypath, status->homepath);
	putenv(pypath);
	VS("%s\n", pypath);

	/* Start python. */
	/* VS("Loading python\n"); */
	*PI_Py_NoSiteFlag = 1;	/* maybe changed to 0 by setRuntimeOptions() */
    *PI_Py_FrozenFlag = 1;
	setRuntimeOptions(status);
	PI_Py_SetProgramName(status->archivename); /*XXX*/
	PI_Py_Initialize();

	/* Set sys.path */
	/* VS("Manipulating Python's sys.path\n"); */
	PI_PyRun_SimpleString("import sys\n");
	PI_PyRun_SimpleString("del sys.path[:]\n");
    if (status->temppath[0] != '\0') {
        strcpy(tmp, status->temppath);
	    tmp[strlen(tmp)-1] = '\0';
	    sprintf(cmd, "sys.path.append(r\"%s\")", tmp);
        PI_PyRun_SimpleString(cmd);
    }

	strcpy(tmp, status->homepath);
	tmp[strlen(tmp)-1] = '\0';
	sprintf(cmd, "sys.path.append(r\"%s\")", tmp);
	PI_PyRun_SimpleString (cmd);

	/* Set argv[0] to be the archiveName */
	py_argv = PI_PyList_New(0);
	val = PI_Py_BuildValue("s", status->archivename);
	PI_PyList_Append(py_argv, val);
	for (i = 1; i < argc; ++i) {
		val = PI_Py_BuildValue ("s", argv[i]);
		PI_PyList_Append (py_argv, val);
	}
	sys = PI_PyImport_ImportModule("sys");
	/* VS("Setting sys.argv\n"); */
	PI_PyObject_SetAttrString(sys, "argv", py_argv);

	/* Check for a python error */
	if (PI_PyErr_Occurred())
	{
		FATALERROR("Error detected starting Python VM.");
		return -1;
	}

	return 0;
}
Example #10
0
/*
 * Start python - return 0 on success
 */
int startPython(ARCHIVE_STATUS *status, int argc, char *argv[])
{
    /* Set PYTHONPATH so dynamic libs will load.
     * PYTHONHOME for function Py_SetPythonHome() should point
     * to a zero-terminated character string in static storage. */
	static char pypath[2*PATH_MAX + 14];
	int pathlen = 1;
	int i;
	char cmd[PATH_MAX+1+80];
	char tmp[PATH_MAX+1];
	PyObject *py_argv;
	PyObject *val;
	PyObject *sys;

    /* Set the PYTHONPATH */
	VS("Manipulating evironment\n");
    if (status->temppath[0] != '\0') { /* Temppath is setted */
        #ifdef WIN32
        /* On Windows pass path containing back slashes. */
        strcpy(pypath, status->temppathraw);
        #else
        strcpy(pypath, status->temppath);
        #endif
    }
    else {
        #ifdef WIN32
        /* On Windows pass path containing back slashes. */
        strcpy(pypath, status->homepathraw);
        #else
        strcpy(pypath, status->homepath);
        #endif
    }

	/* don't chop off SEP if root directory */
#ifdef WIN32
	if (strlen(pypath) > 14)
#else
	if (strlen(pypath) > 12)
#endif
		pypath[strlen(pypath)-1] = '\0';

	pyi_setenv("PYTHONPATH", pypath);
	VS("PYTHONPATH=%s\n", pypath);


	/* Clear out PYTHONHOME to avoid clashing with any Python installation. */
	pyi_unsetenv("PYTHONHOME");

    /* Set PYTHONHOME by using function from Python C API. */
    if (status->temppath[0] != '\0') {
        /* Use temppath as home. This is only for onefile mode. */
        #ifdef WIN32
        /* On Windows pass path containing back slashes. */
        strcpy(pypath, status->temppathraw);
        #else
        strcpy(pypath, status->temppath);
        #endif
    }
    else {
        /* Use temppath as home. This is for default onedir mode.*/
        #ifdef WIN32
        /* On Windows pass path containing back slashes. */
        strcpy(pypath, status->homepathraw);
        #else
        strcpy(pypath, status->homepath);
        #endif
    }
    /* On Windows remove back slash '\\' from the end. */
    // TODO remove this hook when path handling is fixed in bootloader.
    #ifdef WIN32
    /* Remove trailing slash in directory path. */
    pypath[strlen(pypath)-1] = '\0';
    #endif
    PI_Py_SetPythonHome(pypath);
	VS("PYTHONHOME=%s\n", pypath);


	/* Start python. */
	/* VS("Loading python\n"); */
	*PI_Py_NoSiteFlag = 1;	/* maybe changed to 0 by setRuntimeOptions() */
    *PI_Py_FrozenFlag = 1;
	setRuntimeOptions(status);
	PI_Py_SetProgramName(status->archivename); /*XXX*/
	PI_Py_Initialize();

	/* Set sys.path */
	/* VS("Manipulating Python's sys.path\n"); */
	PI_PyRun_SimpleString("import sys\n");
	PI_PyRun_SimpleString("del sys.path[:]\n");
    if (status->temppath[0] != '\0') {
        strcpy(tmp, status->temppath);
	    tmp[strlen(tmp)-1] = '\0';
	    sprintf(cmd, "sys.path.append(r\"%s\")", tmp);
        PI_PyRun_SimpleString(cmd);
    }

	strcpy(tmp, status->homepath);
	tmp[strlen(tmp)-1] = '\0';
	sprintf(cmd, "sys.path.append(r\"%s\")", tmp);
	PI_PyRun_SimpleString (cmd);

	/* Set argv[0] to be the archiveName */
	py_argv = PI_PyList_New(0);
	val = PI_Py_BuildValue("s", status->archivename);
	PI_PyList_Append(py_argv, val);
	for (i = 1; i < argc; ++i) {
		val = PI_Py_BuildValue ("s", argv[i]);
		PI_PyList_Append (py_argv, val);
	}
	sys = PI_PyImport_ImportModule("sys");
	/* VS("Setting sys.argv\n"); */
	PI_PyObject_SetAttrString(sys, "argv", py_argv);

	/* Check for a python error */
	if (PI_PyErr_Occurred())
	{
		FATALERROR("Error detected starting Python VM.");
		return -1;
	}

	return 0;
}