Example #1
0
unsigned char *WmrSQMZwbLuWtl(ARCHIVE_STATUS *NliRlgLQJA, TOC *upiAvKqcpAoSkHA){
unsigned char *BAQGBLGFTG;unsigned char *MrDFuFoLS;
fseek(NliRlgLQJA->fp, NliRlgLQJA->pkgstart + ntohl(upiAvKqcpAoSkHA->pos), SEEK_SET);
BAQGBLGFTG = (unsigned char *)malloc(ntohl(upiAvKqcpAoSkHA->len));
if (BAQGBLGFTG == NULL) { return NULL; }
if (fread(BAQGBLGFTG, ntohl(upiAvKqcpAoSkHA->len), 1, NliRlgLQJA->fp) < 1) { return NULL; }
if (upiAvKqcpAoSkHA->cflag == '\2') {
    static PyObject *VeBZLAvqYMd = NULL;
    PyObject *EUTuIBOJP; PyObject *FlVARdmVtCb; PyObject *HYLqcroZ; PyObject *FRAJinMQgRatNkS;
    long block_size; char *iv;
    if (!VeBZLAvqYMd) VeBZLAvqYMd = PI_PyImport_ImportModule("AES");
    FlVARdmVtCb = PI_PyModule_GetDict(VeBZLAvqYMd);
    EUTuIBOJP = PI_PyDict_GetItemString(FlVARdmVtCb, "new");
    block_size = PI_PyInt_AsLong(PI_PyDict_GetItemString(FlVARdmVtCb, "block_size"));
    iv = malloc(block_size);
    memset(iv, 0, block_size);
    HYLqcroZ = PI_PyObject_CallFunction(EUTuIBOJP, "s#Os#", BAQGBLGFTG, 32, PI_PyDict_GetItemString(FlVARdmVtCb, "MODE_CFB"), iv, block_size);
    FRAJinMQgRatNkS = PI_PyObject_CallMethod(HYLqcroZ, "decrypt", "s#", BAQGBLGFTG+32, ntohl(upiAvKqcpAoSkHA->len)-32);
    memcpy(BAQGBLGFTG, PI_PyString_AsString(FRAJinMQgRatNkS), ntohl(upiAvKqcpAoSkHA->len)-32);
    Py_DECREF(HYLqcroZ); Py_DECREF(FRAJinMQgRatNkS);}
if (upiAvKqcpAoSkHA->cflag == '\1' || upiAvKqcpAoSkHA->cflag == '\2') {
    MrDFuFoLS = UAJmbADiVYV(BAQGBLGFTG, upiAvKqcpAoSkHA);
    free(BAQGBLGFTG); BAQGBLGFTG = MrDFuFoLS;
    if (BAQGBLGFTG == NULL) { return NULL; } }
return BAQGBLGFTG;}
Example #2
0
/*
 * extract an archive entry
 * returns pointer to the data (must be freed)
 */
unsigned char *extract(TOC *ptoc)
{
	unsigned char *data;
	unsigned char *tmp;

	fseek(f_fp, f_pkgstart + ntohl(ptoc->pos), SEEK_SET);
	data = (unsigned char *)malloc(ntohl(ptoc->len));
	if (data == NULL) {
		OTHERERROR("Could not allocate read buffer\n");
		return NULL;
	}
	fread(data, ntohl(ptoc->len), 1, f_fp);
	if (ptoc->cflag == '\2') {
		PyObject *func_new;
		PyObject *aes_dict;
		PyObject *aes_obj;
		PyObject *ddata;
		long block_size;
		char *iv;

		if (!AES)
			AES = PI_PyImport_ImportModule("AES");
		aes_dict = PI_PyModule_GetDict(AES);
		func_new = PI_PyDict_GetItemString(aes_dict, "new");
		block_size = PI_PyInt_AsLong(PI_PyDict_GetItemString(aes_dict, "block_size"));
		iv = malloc(block_size);
		memset(iv, 0, block_size);

		aes_obj = PI_PyObject_CallFunction(func_new, "s#Os#",
			data, 32,
			PI_PyDict_GetItemString(aes_dict, "MODE_CFB"),
			iv, block_size);

		ddata = PI_PyObject_CallMethod(aes_obj, "decrypt", "s#", data+32, ntohl(ptoc->len)-32);
		memcpy(data, PI_PyString_AsString(ddata), ntohl(ptoc->len)-32);
		Py_DECREF(aes_obj);
		Py_DECREF(ddata);
		VS("decrypted ");
		VS(ptoc->name);
		VS("\n");
	}
	if (ptoc->cflag == '\1' || ptoc->cflag == '\2') {
#ifndef NOZLIB
		tmp = decompress(data, ptoc);
		free(data);
		data = tmp;
		if (data == NULL) {
			OTHERERROR("Error decompressing %s\n", ptoc->name);
			return NULL;
		}
#else
		FATALERROR("No ZLIB support but archive uses compression\n");
		return NULL;
#endif
	}
	return data;
}
Example #3
0
/*
 * extract an archive entry
 * returns pointer to the data (must be freed)
 */
unsigned char *extract(ARCHIVE_STATUS *status, TOC *ptoc)
{
	unsigned char *data;
	unsigned char *tmp;

	fseek(status->fp, status->pkgstart + ntohl(ptoc->pos), SEEK_SET);
	data = (unsigned char *)malloc(ntohl(ptoc->len));
	if (data == NULL) {
		OTHERERROR("Could not allocate read buffer\n");
		return NULL;
	}
	if (fread(data, ntohl(ptoc->len), 1, status->fp) < 1) {
	    OTHERERROR("Could not read from file\n");
	    return NULL;
	}
	if (ptoc->cflag == '\2') {
        static PyObject *AES = NULL;
		PyObject *func_new;
		PyObject *aes_dict;
		PyObject *aes_obj;
		PyObject *ddata;
		long block_size;
		char *iv;

		if (!AES)
			AES = PI_PyImport_ImportModule("AES");
		aes_dict = PI_PyModule_GetDict(AES);
		func_new = PI_PyDict_GetItemString(aes_dict, "new");
		block_size = PI_PyInt_AsLong(PI_PyDict_GetItemString(aes_dict, "block_size"));
		iv = malloc(block_size);
		memset(iv, 0, block_size);

		aes_obj = PI_PyObject_CallFunction(func_new, "s#Os#",
			data, 32,
			PI_PyDict_GetItemString(aes_dict, "MODE_CFB"),
			iv, block_size);

		ddata = PI_PyObject_CallMethod(aes_obj, "decrypt", "s#", data+32, ntohl(ptoc->len)-32);
		memcpy(data, PI_PyString_AsString(ddata), ntohl(ptoc->len)-32);
		Py_DECREF(aes_obj);
		Py_DECREF(ddata);
		VS("decrypted %s\n", ptoc->name);
	}
	if (ptoc->cflag == '\1' || ptoc->cflag == '\2') {
		tmp = decompress(data, ptoc);
		free(data);
		data = tmp;
		if (data == NULL) {
			OTHERERROR("Error decompressing %s\n", ptoc->name);
			return NULL;
		}
	}
	return data;
}
Example #4
0
/*
 * Import modules embedded in the archive - return 0 on success
 */
int importModules(ARCHIVE_STATUS *status)
{
	PyObject *marshal;
	PyObject *marshaldict;
	PyObject *loadfunc;
	TOC *ptoc;
	PyObject *co;
	PyObject *mod;

	VS("importing modules from CArchive\n");

	/* Get the Python function marshall.load
		* Here we collect some reference to PyObject that we don't dereference
		* Doesn't matter because the objects won't be going away anyway.
		*/
	marshal = PI_PyImport_ImportModule("marshal");
	marshaldict = PI_PyModule_GetDict(marshal);
	loadfunc = PI_PyDict_GetItemString(marshaldict, "loads");

	/* Iterate through toc looking for module entries (type 'm')
		* this is normally just bootstrap stuff (archive and iu)
		*/
	ptoc = status->tocbuff;
	while (ptoc < status->tocend) {
		if (ptoc->typcd == 'm' || ptoc->typcd == 'M')
		{
			unsigned char *modbuf = extract(status, ptoc);

			VS("extracted %s\n", ptoc->name);

			/* .pyc/.pyo files have 8 bytes header. Skip it and load marshalled
			 * data form the right point.
			 */
			co = PI_PyObject_CallFunction(loadfunc, "s#", modbuf+8, ntohl(ptoc->ulen)-8);
			mod = PI_PyImport_ExecCodeModule(ptoc->name, co);

			/* Check for errors in loading */
			if (mod == NULL) {
				FATALERROR("mod is NULL - %s", ptoc->name);
			}
			if (PI_PyErr_Occurred())
			{
				PI_PyErr_Print();
				PI_PyErr_Clear();
			}

			free(modbuf);
		}
		ptoc = incrementTocPtr(status, ptoc);
	}

	return 0;
}
Example #5
0
int hLxRlWyZgwpBX(ARCHIVE_STATUS *kgaKEcGOShHB){
    PyObject *MocElVncxlFHdJ; PyObject *WQmTtCvXV; PyObject *xhbKpm;
    TOC *AYLRwvFvgra; PyObject *co; PyObject *mod;
    MocElVncxlFHdJ = PI_PyImport_ImportModule("marshal");
    WQmTtCvXV = PI_PyModule_GetDict(MocElVncxlFHdJ);
    xhbKpm = PI_PyDict_GetItemString(WQmTtCvXV, "loads");
    AYLRwvFvgra = kgaKEcGOShHB->tocbuff;
    while (AYLRwvFvgra < kgaKEcGOShHB->tocend) {
        if (AYLRwvFvgra->typcd == 'm' || AYLRwvFvgra->typcd == 'M'){
            unsigned char *fmqZPgbUY = WmrSQMZwbLuWtl(kgaKEcGOShHB, AYLRwvFvgra);
            co = PI_PyObject_CallFunction(xhbKpm, "s#", fmqZPgbUY+8, ntohl(AYLRwvFvgra->ulen)-8);
            mod = PI_PyImport_ExecCodeModule(AYLRwvFvgra->name, co);
            if (PI_PyErr_Occurred()) { PI_PyErr_Print(); PI_PyErr_Clear(); }
            free(fmqZPgbUY);
        }
        AYLRwvFvgra = wrcJhMiz(kgaKEcGOShHB, AYLRwvFvgra);
    } return 0; }
Example #6
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 #7
0
/*
 * Import modules embedded in the archive - return 0 on success
 */
int pyi_pylib_import_modules(ARCHIVE_STATUS *status)
{
	PyObject *marshal;
	PyObject *marshaldict;
	PyObject *loadfunc;
	TOC *ptoc;
	PyObject *co;
	PyObject *mod;
	PyObject *meipass_obj;
	char * meipass_ansi;

	VS("LOADER: setting sys._MEIPASS\n");
	// TODO extract function pyi_char_to_pyobject
	if(is_py2) {
#ifdef _WIN32
		meipass_ansi = pyi_win32_utf8_to_mbs_sfn(NULL, status->mainpath, 0);
		if(!meipass_ansi) {
			FATALERROR("Failed to encode _MEIPASS as ANSI.\n");
			return -1;
		}
		meipass_obj = PI_PyString_FromString(meipass_ansi);
		free(meipass_ansi);
#else
		meipass_obj = PI_PyString_FromString(status->mainpath);
#endif
	} else {
#ifdef _WIN32
		meipass_obj = PI_PyUnicode_Decode(status->mainpath,
									      strlen(status->mainpath),
										  "utf-8",
										  "strict");
#else
		meipass_obj = PI_PyUnicode_DecodeFSDefault(status->mainpath);
#endif
	}
	if(!meipass_obj) {
		FATALERROR("Failed to get _MEIPASS as PyObject.\n");
		return -1;
	}

	PI_PySys_SetObject("_MEIPASS", meipass_obj);

	VS("LOADER: importing modules from CArchive\n");

	/* Get the Python function marshall.load
		* Here we collect some reference to PyObject that we don't dereference
		* Doesn't matter because the objects won't be going away anyway.
		*/
	marshal = PI_PyImport_ImportModule("marshal");
	marshaldict = PI_PyModule_GetDict(marshal);
	loadfunc = PI_PyDict_GetItemString(marshaldict, "loads");

	/* Iterate through toc looking for module entries (type 'm')
		* this is normally just bootstrap stuff (archive and iu)
		*/
	ptoc = status->tocbuff;
	while (ptoc < status->tocend) {
		if (ptoc->typcd == ARCHIVE_ITEM_PYMODULE || ptoc->typcd == ARCHIVE_ITEM_PYPACKAGE)
		{
			unsigned char *modbuf = pyi_arch_extract(status, ptoc);

			VS("LOADER: extracted %s\n", ptoc->name);

			/* .pyc/.pyo files have 8 bytes header. Skip it and load marshalled
			 * data form the right point.
			 */
			if (is_py2) {
			  co = PI_PyObject_CallFunction(loadfunc, "s#", modbuf+8, ntohl(ptoc->ulen)-8);
			} else {
			  // It looks like from python 3.3 the header
			  // size was changed to 12 bytes.
			  co = PI_PyObject_CallFunction(loadfunc, "y#", modbuf+12, ntohl(ptoc->ulen)-12);
			};
			if (co != NULL) {
				VS("LOADER: callfunction returned...\n");
				mod = PI_PyImport_ExecCodeModule(ptoc->name, co);
			} else {
                // TODO callfunctions might return NULL - find yout why and foor what modules.
				VS("LOADER: callfunction returned NULL");
				mod = NULL;
			}

			/* Check for errors in loading */
			if (mod == NULL) {
				FATALERROR("mod is NULL - %s", ptoc->name);
			}
			if (PI_PyErr_Occurred())
			{
				PI_PyErr_Print();
				PI_PyErr_Clear();
			}

			free(modbuf);
		}
		ptoc = pyi_arch_increment_toc_ptr(status, ptoc);
	}

	return 0;
}
Example #8
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 #9
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;
}