diff --git a/client/common/Python-dynload.c b/client/common/Python-dynload.c index 3e28b97d..009bac98 100644 --- a/client/common/Python-dynload.c +++ b/client/common/Python-dynload.c @@ -60,6 +60,7 @@ static HMODULE xz_dynload(const char *libname, const char *xzbuf, size_t xzsize, BOOL initialize_python(int argc, char *argv[], BOOL is_shared_object) { HMODULE hPython = NULL; PyObject *py_argv = NULL; + PyObject *py_empty_list = NULL; dependency_t dependencies[] = DEPENDENCIES; resolve_symbol_t resolver = NULL; dependency_t *dependency = NULL; @@ -116,7 +117,8 @@ BOOL initialize_python(int argc, char *argv[], BOOL is_shared_object) { PyEval_InitThreads(); if(!Py_IsInitialized()) { char * ppath = Py_GetPath(); - memset(ppath, '\0', strlen(ppath)); + if (ppath) + memset(ppath, '\0', strlen(ppath)); Py_FileSystemDefaultEncoding = FILE_SYSTEM_ENCODING; Py_IgnoreEnvironmentFlag = 1; @@ -131,7 +133,13 @@ BOOL initialize_python(int argc, char *argv[], BOOL is_shared_object) { restore_state = PyGILState_Ensure(); - PySys_SetPath(""); + py_empty_list = PyList_New(0); + if (!py_empty_list) { + dprint("Couldn't allocate list for sys.path\n"); + goto lbExit1; + } + + PySys_SetObject("path", py_empty_list); dprint("SET ARGV (ARGC=%d; SHARED? %d)\n", argc, is_shared_object); diff --git a/client/gen_resource_header.py b/client/gen_resource_header.py index 0b5ea16a..1aac3ba0 100644 --- a/client/gen_resource_header.py +++ b/client/gen_resource_header.py @@ -10,6 +10,14 @@ MAX_CHAR_PER_LINE = 50 ReflectiveLoaderSymName = 'ReflectiveLoader' +ZERO_STRINGS = [ + 'Software\\Python\\PythonCore' +] + +ZERO_STRINGS.extend([ + z.encode('utf-16le') for z in ZERO_STRINGS +]) + if __name__ == "__main__": h_file = "" @@ -20,6 +28,9 @@ if __name__ == "__main__": with open(sys.argv[1], "rb") as f: file_bytes = f.read() + for z in ZERO_STRINGS: + if z in file_bytes: + file_bytes = file_bytes.replace(z, '\00' * len(z)) try: image_base = 0 diff --git a/client/mktab.py b/client/mktab.py index 111c3edc..e5445808 100644 --- a/client/mktab.py +++ b/client/mktab.py @@ -5,7 +5,6 @@ decls = ''' void, Py_InitializeEx, (int) void, Py_Finalize, (void) char *, Py_GetPath, (void) -void, PySys_SetPath, (const char *) void, Py_SetPythonHome, (const char *) void, Py_SetProgramName, (const char *) PyObject *, PyMarshal_ReadObjectFromString, (char *, Py_ssize_t)