Fix ticket #69: import [220], [223] and [224] from the crypt branch,

which allow to compress the bootstrap modules so that they not appear
in plaintext in the executable.


git-svn-id: http://svn.pyinstaller.org/trunk@288 8dd32b29-ccff-0310-8a9a-9233e24343b1
This commit is contained in:
giovannibajo
2006-09-05 12:44:44 +00:00
parent fe6e72b258
commit 5fb220ef2b
20 changed files with 26 additions and 35 deletions
+4 -3
View File
@@ -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)
+4 -2
View File
@@ -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:
+17 -30
View File
@@ -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;
}
+1
View File
@@ -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 *));
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.