client/windows: workaround against registry checks

This commit is contained in:
Oleksii Shevchuk 2019-12-20 16:07:45 +02:00
parent 7a6dcbc321
commit 8ef1ff7b7a
3 changed files with 21 additions and 3 deletions

View File

@ -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);

View File

@ -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

View File

@ -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)