-
Notifications
You must be signed in to change notification settings - Fork 25
/
sys_launcher.cpp
141 lines (117 loc) · 3.31 KB
/
sys_launcher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <windows.h>
typedef LONG NTSTATUS;
typedef NTSTATUS *PNTSTATUS;
#define STATUS_SUCCESS ((NTSTATUS)0x00000000)
#define MEM_EXECUTE_OPTION_DISABLE 0x1
#define MEM_EXECUTE_OPTION_ENABLE 0x2
#define MEM_EXECUTE_OPTION_DISABLE_THUNK_EMULATION 0x4
#define MEM_EXECUTE_OPTION_PERMANENT 0x8
#define MEM_EXECUTE_OPTION_EXECUTE_DISPATCH_ENABLE 0x10
#define MEM_EXECUTE_OPTION_IMAGE_DISPATCH_ENABLE 0x20
#define MEM_EXECUTE_OPTION_VALID_FLAGS 0x3f
typedef enum _PROCESSINFOCLASS
{
ProcessBasicInformation,
ProcessQuotaLimits,
ProcessIoCounters,
ProcessVmCounters,
ProcessTimes,
ProcessBasePriority,
ProcessRaisePriority,
ProcessDebugPort,
ProcessExceptionPort,
ProcessAccessToken,
ProcessLdtInformation,
ProcessLdtSize,
ProcessDefaultHardErrorMode,
ProcessIoPortHandlers,
ProcessPooledUsageAndLimits,
ProcessWorkingSetWatch,
ProcessUserModeIOPL,
ProcessEnableAlignmentFaultFixup,
ProcessPriorityClass,
ProcessWx86Information,
ProcessHandleCount,
ProcessAffinityMask,
ProcessPriorityBoost,
ProcessDeviceMap,
ProcessSessionInformation,
ProcessForegroundInformation,
ProcessWow64Information,
ProcessImageFileName,
ProcessLUIDDeviceMapsEnabled,
ProcessBreakOnTermination,
ProcessDebugObjectHandle,
ProcessDebugFlags,
ProcessHandleTracing,
ProcessIoPriority,
ProcessExecuteFlags,
ProcessResourceManagement,
ProcessCookie,
ProcessImageInformation,
MaxProcessInfoClass
}
PROCESSINFOCLASS;
BOOL Sys_CloseDEP(void)
{
static NTSTATUS (WINAPI *pfnNtSetInformationProcess)(HANDLE ProcessHandle, PROCESSINFOCLASS ProcessInformationClass, PVOID ProcessInformation, ULONG ProcessInformationLength) = (NTSTATUS (WINAPI *)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG))GetProcAddress(GetModuleHandle("ntdll.dll"), "NtSetInformationProcess");
ULONG ExecuteFlags = MEM_EXECUTE_OPTION_ENABLE;
return (pfnNtSetInformationProcess(GetCurrentProcess(), ProcessExecuteFlags, &ExecuteFlags, sizeof(ExecuteFlags)) == 0);
}
BOOL Sys_GetExecutableName(char *pszName, int nSize)
{
return GetModuleFileName(GetModuleHandle(NULL), pszName, nSize) != 0;
}
char *Sys_GetLongPathName(void)
{
char szShortPath[MAX_PATH];
static char szLongPath[MAX_PATH];
char *pszPath;
szShortPath[0] = 0;
szLongPath[0] = 0;
if (GetModuleFileName(NULL, szShortPath, sizeof(szShortPath)))
{
GetLongPathName(szShortPath, szLongPath, sizeof(szLongPath));
pszPath = strrchr(szLongPath, '\\');
if (pszPath[0])
pszPath[1] = 0;
int len = strlen(szLongPath);
if (len > 0)
{
if (szLongPath[len - 1] == '\\' || szLongPath[len - 1] == '/')
szLongPath[len - 1] = 0;
}
}
return szLongPath;
}
char* Sys_GetLongPathNameWithoutBin(void)
{
char szShortPath[MAX_PATH];
static char szLongPath[MAX_PATH];
char* pszPath;
szShortPath[0] = 0;
szLongPath[0] = 0;
if (GetModuleFileName(NULL, szShortPath, sizeof(szShortPath)))
{
GetLongPathName(szShortPath, szLongPath, sizeof(szLongPath));
pszPath = strrchr(szLongPath, '\\');
if (pszPath[0])
pszPath[1] = 0;
int len = strlen(szLongPath);
if (len > 0)
{
if (szLongPath[len - 1] == '\\' || szLongPath[len - 1] == '/')
szLongPath[len - 1] = 0;
}
pszPath = strrchr(szLongPath, '\\');
if (pszPath[0])
pszPath[1] = 0;
len = strlen(szLongPath);
if (len > 0)
{
if (szLongPath[len - 1] == '\\' || szLongPath[len - 1] == '/')
szLongPath[len - 1] = 0;
}
}
return szLongPath;
}