diff --git a/Build.py b/Build.py index cb0b624..8adba93 100755 --- a/Build.py +++ b/Build.py @@ -325,7 +325,7 @@ def checkCache(fnm, strip, upx): os.system(cmd) return cachedfile -UNCOMPRESSED, COMPRESSED, SOURCEFORM = range(3) +UNCOMPRESSED, COMPRESSED = range(2) class PKG(Target): typ = 'PKG' xformdict = {'PYMODULE' : 'm', @@ -353,9 +353,10 @@ class PKG(Target): 'DATA':COMPRESSED, 'BINARY':COMPRESSED, 'EXECUTABLE':COMPRESSED, - 'PYSOURCE':SOURCEFORM } + 'PYSOURCE':COMPRESSED, + 'PYMODULE':COMPRESSED } else: - self.cdict = { 'PYSOURCE':SOURCEFORM } + self.cdict = { 'PYSOURCE':UNCOMPRESSED } self.__postinit__() def check_guts(self, last_build): outnm = os.path.basename(self.out) diff --git a/carchive.py b/carchive.py index faabf6e..f9af276 100644 --- a/carchive.py +++ b/carchive.py @@ -204,7 +204,7 @@ class CArchive(archive.Archive): entry[0] is name (under which it will be saved). entry[1] is fullpathname of the file. entry[2] is a flag for it's storage format (0==uncompressed, - 1==compressed, 2==Python source format) + 1==compressed) entry[3] is the entry's type code. Version 5: If the type code is 'o': @@ -219,7 +219,9 @@ class CArchive(archive.Archive): if typcd == 'o': s = '' flag = 0 - elif flag == 2: + elif typcd == 's': + # If it's a source code file, add \0 terminator as it will be + # executed as-is by the bootloader. s = open(pathnm, 'r').read() s = s + '\n\0' else: diff --git a/source/common/launch.c b/source/common/launch.c index e8c1813..331dd31 100644 --- a/source/common/launch.c +++ b/source/common/launch.c @@ -64,6 +64,7 @@ DECLPROC(PyList_New); DECLPROC(PyList_Append); DECLPROC(Py_BuildValue); DECLPROC(PyFile_FromString); +DECLPROC(PyString_FromStringAndSize); DECLPROC(PyObject_CallFunction); DECLPROC(PyModule_GetDict); DECLPROC(PyDict_GetItemString); @@ -112,6 +113,8 @@ static TOC *f_tocbuff = NULL; static TOC *f_tocend = NULL; static COOKIE f_cookie; +unsigned char *extract(TOC *ptoc); + /* * The functions in this file defined in reverse order so that forward * declarations are not necessary. @@ -274,6 +277,7 @@ int mapNames(HMODULE dll) GETPROC(dll, PyList_Append); GETPROC(dll, Py_BuildValue); GETPROC(dll, PyFile_FromString); + GETPROC(dll, PyString_FromStringAndSize); GETPROC(dll, PyObject_CallFunction); GETPROC(dll, PyModule_GetDict); GETPROC(dll, PyDict_GetItemString); @@ -581,19 +585,7 @@ int importModules() */ marshal = PyImport_ImportModule("marshal"); marshaldict = PyModule_GetDict(marshal); - loadfunc = PyDict_GetItemString(marshaldict, "load"); - - /* Reopen the archive as a Python file. We cannot use PyFile_FromFile - * because that would require this boot-loader and Python DLL to share - * the same libc, while they purposely don't. - */ - fclose(f_fp); - pyfile = PyFile_FromString(f_archivename, "rb"); - if (PyErr_Occurred()) - { - PyErr_Print(); - return -1; - } + loadfunc = PyDict_GetItemString(marshaldict, "loads"); /* Iterate through toc looking for module entries (type 'm') * this is normally just bootstrap stuff (archive and iu) @@ -602,14 +594,18 @@ int importModules() while (ptoc < f_tocend) { if (ptoc->typcd == 'm' || ptoc->typcd == 'M') { + unsigned char *modbuf = extract(ptoc); + + /* .pyc/.pyo files have 8 bytes header. Skip it and get a Python + * string directly pointing at the marshalled code. + */ + PyObject *mods = PyString_FromStringAndSize(modbuf + 8, + ntohl(ptoc->ulen) - 8); + VS(ptoc->name); VS("\n"); - /* Go to start of Python module (start + 8) and load the code object */ - res = PyObject_CallMethod(pyfile, "seek", "(ii)", f_pkgstart + ntohl(ptoc->pos) + 8, 0); - Py_XDECREF(res); - - co = PyObject_CallFunction(loadfunc, "O", pyfile); + co = PyObject_CallFunction(loadfunc, "O", mods); mod = PyImport_ExecCodeModule(ptoc->name, co); /* Check for errors in loading */ @@ -622,22 +618,13 @@ int importModules() PyErr_Print(); PyErr_Clear(); } + + Py_DECREF(mods); + free(modbuf); } ptoc = incrementTocPtr(ptoc); } - /* Close the file and release the object. */ - res = PyObject_CallMethod(pyfile, "close", "()"); - Py_XDECREF(res); - Py_DECREF(pyfile); - - /* After closing the python file, we can reopen it as normal file. */ - f_fp = fopen(f_archivename, "rb"); - if (f_fp == NULL) { - VS("Cannot reopen archive: "); - VS(f_archivename); - VS("\n"); - } return 0; } diff --git a/source/common/launch.h b/source/common/launch.h index 1316e91..1ad61b7 100644 --- a/source/common/launch.h +++ b/source/common/launch.h @@ -137,6 +137,7 @@ EXTDECLPROC(PyObject *, PyList_New, (int)); EXTDECLPROC(int, PyList_Append, (PyObject *, PyObject *)); EXTDECLPROC(PyObject *, Py_BuildValue, (char *, ...)); EXTDECLPROC(PyObject *, PyFile_FromString, (char *, char *)); +EXTDECLPROC(PyObject *, PyString_FromStringAndSize, (const char *, int)); EXTDECLPROC(PyObject *, PyObject_CallFunction, (PyObject *, char *, ...)); EXTDECLPROC(PyObject *, PyModule_GetDict, (PyObject *)); EXTDECLPROC(PyObject *, PyDict_GetItemString, (PyObject *, char *)); diff --git a/support/loader/inprocsrvr_6dc.dll b/support/loader/inprocsrvr_6dc.dll index 4f83c7d..8eb04d2 100644 Binary files a/support/loader/inprocsrvr_6dc.dll and b/support/loader/inprocsrvr_6dc.dll differ diff --git a/support/loader/inprocsrvr_6dw.dll b/support/loader/inprocsrvr_6dw.dll index 431b376..02aaac7 100644 Binary files a/support/loader/inprocsrvr_6dw.dll and b/support/loader/inprocsrvr_6dw.dll differ diff --git a/support/loader/inprocsrvr_6rc.dll b/support/loader/inprocsrvr_6rc.dll index 5e23644..eac0094 100644 Binary files a/support/loader/inprocsrvr_6rc.dll and b/support/loader/inprocsrvr_6rc.dll differ diff --git a/support/loader/inprocsrvr_6rw.dll b/support/loader/inprocsrvr_6rw.dll index ecff159..443c8ee 100644 Binary files a/support/loader/inprocsrvr_6rw.dll and b/support/loader/inprocsrvr_6rw.dll differ diff --git a/support/loader/inprocsrvr_7dc.dll b/support/loader/inprocsrvr_7dc.dll index 042dd88..44f18c2 100644 Binary files a/support/loader/inprocsrvr_7dc.dll and b/support/loader/inprocsrvr_7dc.dll differ diff --git a/support/loader/inprocsrvr_7dw.dll b/support/loader/inprocsrvr_7dw.dll index 2da29ea..7027d61 100644 Binary files a/support/loader/inprocsrvr_7dw.dll and b/support/loader/inprocsrvr_7dw.dll differ diff --git a/support/loader/inprocsrvr_7rc.dll b/support/loader/inprocsrvr_7rc.dll index fabe2e0..49692dd 100644 Binary files a/support/loader/inprocsrvr_7rc.dll and b/support/loader/inprocsrvr_7rc.dll differ diff --git a/support/loader/inprocsrvr_7rw.dll b/support/loader/inprocsrvr_7rw.dll index b3aee7b..28de328 100644 Binary files a/support/loader/inprocsrvr_7rw.dll and b/support/loader/inprocsrvr_7rw.dll differ diff --git a/support/loader/run_6dc.exe b/support/loader/run_6dc.exe index 5dca73f..86c3277 100644 Binary files a/support/loader/run_6dc.exe and b/support/loader/run_6dc.exe differ diff --git a/support/loader/run_6dw.exe b/support/loader/run_6dw.exe index 9135a0c..5724a26 100644 Binary files a/support/loader/run_6dw.exe and b/support/loader/run_6dw.exe differ diff --git a/support/loader/run_6rc.exe b/support/loader/run_6rc.exe index e066a07..7bda2bb 100644 Binary files a/support/loader/run_6rc.exe and b/support/loader/run_6rc.exe differ diff --git a/support/loader/run_6rw.exe b/support/loader/run_6rw.exe index 1b31a6d..f645f11 100644 Binary files a/support/loader/run_6rw.exe and b/support/loader/run_6rw.exe differ diff --git a/support/loader/run_7dc.exe b/support/loader/run_7dc.exe index 6f3e990..cf6e5a2 100644 Binary files a/support/loader/run_7dc.exe and b/support/loader/run_7dc.exe differ diff --git a/support/loader/run_7dw.exe b/support/loader/run_7dw.exe index 2155512..54b8659 100644 Binary files a/support/loader/run_7dw.exe and b/support/loader/run_7dw.exe differ diff --git a/support/loader/run_7rc.exe b/support/loader/run_7rc.exe index a22e4a5..ab190d4 100644 Binary files a/support/loader/run_7rc.exe and b/support/loader/run_7rc.exe differ diff --git a/support/loader/run_7rw.exe b/support/loader/run_7rw.exe index f4a206e..25e46c8 100644 Binary files a/support/loader/run_7rw.exe and b/support/loader/run_7rw.exe differ