mirror of https://github.com/n1nj4sec/pupy.git
Exit early with some different exit codes
This commit is contained in:
parent
860d21c7f8
commit
2d9fc79f5a
|
@ -5,6 +5,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "pupy_load.h"
|
#include "pupy_load.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
void on_exit_session(void);
|
void on_exit_session(void);
|
||||||
|
|
||||||
|
@ -12,21 +13,21 @@ static BOOL on_exit_session_called = FALSE;
|
||||||
|
|
||||||
LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK WinProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_QUERYENDSESSION:
|
case WM_QUERYENDSESSION:
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
case WM_QUIT:
|
case WM_QUIT:
|
||||||
if (on_exit_session && !on_exit_session_called) {
|
if (on_exit_session && !on_exit_session_called) {
|
||||||
on_exit_session_called = TRUE;
|
on_exit_session_called = TRUE;
|
||||||
on_exit_session();
|
on_exit_session();
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return DefWindowProc (hwnd, msg, wParam, lParam);
|
return DefWindowProc (hwnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
|
@ -35,43 +36,56 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
MSG msg;
|
MSG msg;
|
||||||
BOOL bRet;
|
BOOL bRet;
|
||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
HWND hwndMain;
|
HWND hwndMain;
|
||||||
HINSTANCE hinst;
|
HINSTANCE hinst;
|
||||||
HANDLE hThread;
|
HANDLE hThread;
|
||||||
DWORD threadId;
|
DWORD threadId;
|
||||||
DWORD dwWake;
|
DWORD dwWake;
|
||||||
WNDCLASSEX wx;
|
WNDCLASSEX wx;
|
||||||
static const char class_name[] = "DUMMY";
|
static const char class_name[] = "DUMMY";
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
AttachConsole(-1);
|
AttachConsole(-1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ZeroMemory(&wx, sizeof(WNDCLASSEX));
|
ZeroMemory(&wx, sizeof(WNDCLASSEX));
|
||||||
|
|
||||||
wx.cbSize = sizeof(WNDCLASSEX);
|
wx.cbSize = sizeof(WNDCLASSEX);
|
||||||
wx.lpfnWndProc = WinProc;
|
wx.lpfnWndProc = WinProc;
|
||||||
wx.hInstance = hInstance;
|
wx.hInstance = hInstance;
|
||||||
wx.lpszClassName = class_name;
|
wx.lpszClassName = class_name;
|
||||||
if ( ! RegisterClassEx(&wx) )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
hwndMain = CreateWindowEx(
|
if ( ! RegisterClassEx(&wx) ) {
|
||||||
0,
|
dprint("RegisterClassEx failed: %d\n", GetLastError());
|
||||||
class_name,
|
return -1;
|
||||||
NULL,
|
}
|
||||||
0, 0, 0, 0, 0,
|
|
||||||
NULL, NULL, NULL, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
hThread = CreateThread(
|
hwndMain = CreateWindowEx(
|
||||||
NULL,
|
0,
|
||||||
0,
|
class_name,
|
||||||
mainThread,
|
NULL,
|
||||||
NULL,
|
0, 0, 0, 0, 0,
|
||||||
0,
|
NULL, NULL, NULL, NULL
|
||||||
&threadId
|
);
|
||||||
);
|
|
||||||
|
if (!hwndMain) {
|
||||||
|
dprint("CreateWindowEx failed: %d\n", GetLastError());
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
hThread = CreateThread(
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
mainThread,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&threadId
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!hThread) {
|
||||||
|
dprint("CreateThread failed: %d\n", GetLastError());
|
||||||
|
return -GetLastError();
|
||||||
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
dwWake = MsgWaitForMultipleObjects(
|
dwWake = MsgWaitForMultipleObjects(
|
||||||
|
@ -80,11 +94,11 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
FALSE,
|
FALSE,
|
||||||
INFINITE,
|
INFINITE,
|
||||||
QS_ALLINPUT
|
QS_ALLINPUT
|
||||||
);
|
);
|
||||||
|
|
||||||
switch (dwWake) {
|
switch (dwWake) {
|
||||||
case WAIT_FAILED:
|
case WAIT_FAILED:
|
||||||
return -1;
|
return -3;
|
||||||
|
|
||||||
case WAIT_TIMEOUT:
|
case WAIT_TIMEOUT:
|
||||||
continue;
|
continue;
|
||||||
|
@ -99,7 +113,7 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue