-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconque_win32_util.py
448 lines (364 loc) · 11.5 KB
/
conque_win32_util.py
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# FILE: autoload/conque_term/conque_win32_util.py
# AUTHOR: Nico Raffo <nicoraffo@gmail.com>
# WEBSITE: http://conque.googlecode.com
# MODIFIED: 2011-08-12
# VERSION: 2.2, for Vim 7.0
# LICENSE:
# Conque - Vim terminal/console emulator
# Copyright (C) 2009-__YEAR__ Nico Raffo
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
""" Python constants and structures used for ctypes interaction. """
from ctypes import *
# Constants
# create process flag constants
CREATE_BREAKAWAY_FROM_JOB = 0x01000000
CREATE_DEFAULT_ERROR_MODE = 0x04000000
CREATE_NEW_CONSOLE = 0x00000010
CREATE_NEW_PROCESS_GROUP = 0x00000200
CREATE_NO_WINDOW = 0x08000000
CREATE_PROTECTED_PROCESS = 0x00040000
CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
CREATE_SEPARATE_WOW_VDM = 0x00000800
CREATE_SHARED_WOW_VDM = 0x00001000
CREATE_SUSPENDED = 0x00000004
CREATE_UNICODE_ENVIRONMENT = 0x00000400
DEBUG_ONLY_THIS_PROCESS = 0x00000002
DEBUG_PROCESS = 0x00000001
DETACHED_PROCESS = 0x00000008
EXTENDED_STARTUPINFO_PRESENT = 0x00080000
INHERIT_PARENT_AFFINITY = 0x00010000
# process priority constants
ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
HIGH_PRIORITY_CLASS = 0x00000080
IDLE_PRIORITY_CLASS = 0x00000040
NORMAL_PRIORITY_CLASS = 0x00000020
REALTIME_PRIORITY_CLASS = 0x00000100
# startup info constants
STARTF_FORCEONFEEDBACK = 0x00000040
STARTF_FORCEOFFFEEDBACK = 0x00000080
STARTF_PREVENTPINNING = 0x00002000
STARTF_RUNFULLSCREEN = 0x00000020
STARTF_TITLEISAPPID = 0x00001000
STARTF_TITLEISLINKNAME = 0x00000800
STARTF_USECOUNTCHARS = 0x00000008
STARTF_USEFILLATTRIBUTE = 0x00000010
STARTF_USEHOTKEY = 0x00000200
STARTF_USEPOSITION = 0x00000004
STARTF_USESHOWWINDOW = 0x00000001
STARTF_USESIZE = 0x00000002
STARTF_USESTDHANDLES = 0x00000100
# show window constants
SW_FORCEMINIMIZE = 11
SW_HIDE = 0
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
SW_RESTORE = 9
SW_SHOW = 5
SW_SHOWDEFAULT = 10
SW_SHOWMAXIMIZED = 3
SW_SHOWMINIMIZED = 2
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_SHOWNOACTIVATE = 4
SW_SHOWNORMAL = 1
# input event types
FOCUS_EVENT = 0x0010
KEY_EVENT = 0x0001
MENU_EVENT = 0x0008
MOUSE_EVENT = 0x0002
WINDOW_BUFFER_SIZE_EVENT = 0x0004
# key event modifiers
CAPSLOCK_ON = 0x0080
ENHANCED_KEY = 0x0100
LEFT_ALT_PRESSED = 0x0002
LEFT_CTRL_PRESSED = 0x0008
NUMLOCK_ON = 0x0020
RIGHT_ALT_PRESSED = 0x0001
RIGHT_CTRL_PRESSED = 0x0004
SCROLLLOCK_ON = 0x0040
SHIFT_PRESSED = 0x0010
# process access
PROCESS_CREATE_PROCESS = 0x0080
PROCESS_CREATE_THREAD = 0x0002
PROCESS_DUP_HANDLE = 0x0040
PROCESS_QUERY_INFORMATION = 0x0400
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
PROCESS_SET_INFORMATION = 0x0200
PROCESS_SET_QUOTA = 0x0100
PROCESS_SUSPEND_RESUME = 0x0800
PROCESS_TERMINATE = 0x0001
PROCESS_VM_OPERATION = 0x0008
PROCESS_VM_READ = 0x0010
PROCESS_VM_WRITE = 0x0020
# input / output handles
STD_INPUT_HANDLE = c_ulong(-10)
STD_OUTPUT_HANDLE = c_ulong(-11)
STD_ERROR_HANDLE = c_ulong(-12)
CONQUE_WINDOWS_VK = {
'VK_LBUTTON': 0x0001,
'VK_RBUTTON': 0x0002,
'VK_CANCEL': 0x0003,
'VK_BACK': 0x0008,
'VK_TAB': 0x0009,
'VK_CLEAR': 0x000C,
'VK_RETURN': 0x0D,
'VK_SHIFT': 0x10,
'VK_CONTROL': 0x11,
'VK_MENU': 0x12,
'VK_PAUSE': 0x0013,
'VK_CAPITAL': 0x0014,
'VK_ESCAPE': 0x001B,
'VK_SPACE': 0x0020,
'VK_PRIOR': 0x0021,
'VK_NEXT': 0x0022,
'VK_END': 0x0023,
'VK_HOME': 0x0024,
'VK_LEFT': 0x0025,
'VK_UP': 0x0026,
'VK_RIGHT': 0x0027,
'VK_DOWN': 0x0028,
'VK_SELECT': 0x0029,
'VK_PRINT': 0x002A,
'VK_EXECUTE': 0x002B,
'VK_SNAPSHOT': 0x002C,
'VK_INSERT': 0x002D,
'VK_DELETE': 0x002E,
'VK_HELP': 0x002F,
'VK_0': 0x0030,
'VK_1': 0x0031,
'VK_2': 0x0032,
'VK_3': 0x0033,
'VK_4': 0x0034,
'VK_5': 0x0035,
'VK_6': 0x0036,
'VK_7': 0x0037,
'VK_8': 0x0038,
'VK_9': 0x0039,
'VK_A': 0x0041,
'VK_B': 0x0042,
'VK_C': 0x0043,
'VK_D': 0x0044,
'VK_E': 0x0045,
'VK_F': 0x0046,
'VK_G': 0x0047,
'VK_H': 0x0048,
'VK_I': 0x0049,
'VK_J': 0x004A,
'VK_K': 0x004B,
'VK_L': 0x004C,
'VK_M': 0x004D,
'VK_N': 0x004E,
'VK_O': 0x004F,
'VK_P': 0x0050,
'VK_Q': 0x0051,
'VK_R': 0x0052,
'VK_S': 0x0053,
'VK_T': 0x0054,
'VK_U': 0x0055,
'VK_V': 0x0056,
'VK_W': 0x0057,
'VK_X': 0x0058,
'VK_Y': 0x0059,
'VK_Z': 0x005A,
'VK_LWIN': 0x005B,
'VK_RWIN': 0x005C,
'VK_APPS': 0x005D,
'VK_SLEEP': 0x005F,
'VK_NUMPAD0': 0x0060,
'VK_NUMPAD1': 0x0061,
'VK_NUMPAD2': 0x0062,
'VK_NUMPAD3': 0x0063,
'VK_NUMPAD4': 0x0064,
'VK_NUMPAD5': 0x0065,
'VK_NUMPAD6': 0x0066,
'VK_NUMPAD7': 0x0067,
'VK_NUMPAD8': 0x0068,
'VK_MULTIPLY': 0x006A,
'VK_ADD': 0x006B,
'VK_SEPARATOR': 0x006C,
'VK_SUBTRACT': 0x006D,
'VK_DECIMAL': 0x006E,
'VK_DIVIDE': 0x006F,
'VK_F1': 0x0070,
'VK_F2': 0x0071,
'VK_F3': 0x0072,
'VK_F4': 0x0073,
'VK_F5': 0x0074,
'VK_F6': 0x0075,
'VK_F7': 0x0076,
'VK_F8': 0x0077,
'VK_F9': 0x0078,
'VK_F10': 0x0079,
'VK_F11': 0x007A,
'VK_F12': 0x007B,
'VK_F13': 0x007C,
'VK_F14': 0x007D,
'VK_F15': 0x007E,
'VK_F16': 0x007F,
'VK_F17': 0x0080,
'VK_F18': 0x0081,
'VK_F19': 0x0082,
'VK_F20': 0x0083,
'VK_F21': 0x0084,
'VK_F22': 0x0085,
'VK_F23': 0x0086,
'VK_F24': 0x0087,
'VK_NUMLOCK': 0x0090,
'VK_SCROLL': 0x0091,
'VK_LSHIFT': 0x00A0,
'VK_RSHIFT': 0x00A1,
'VK_LCONTROL': 0x00A2,
'VK_RCONTROL': 0x00A3,
'VK_LMENU': 0x00A4,
'VK_RMENU': 0x00A5
}
CONQUE_WINDOWS_VK_INV = dict([v, k] for k, v in CONQUE_WINDOWS_VK.items())
CONQUE_WINDOWS_VK_ENHANCED = {
str(int(CONQUE_WINDOWS_VK['VK_UP'])): 1,
str(int(CONQUE_WINDOWS_VK['VK_DOWN'])): 1,
str(int(CONQUE_WINDOWS_VK['VK_LEFT'])): 1,
str(int(CONQUE_WINDOWS_VK['VK_RIGHT'])): 1,
str(int(CONQUE_WINDOWS_VK['VK_HOME'])): 1,
str(int(CONQUE_WINDOWS_VK['VK_END'])): 1
}
# structures used for CreateProcess
# Odd types
LPBYTE = POINTER(c_ubyte)
LPTSTR = POINTER(c_char)
class STARTUPINFO(Structure):
_fields_ = [("cb", c_ulong),
("lpReserved", LPTSTR),
("lpDesktop", LPTSTR),
("lpTitle", LPTSTR),
("dwX", c_ulong),
("dwY", c_ulong),
("dwXSize", c_ulong),
("dwYSize", c_ulong),
("dwXCountChars", c_ulong),
("dwYCountChars", c_ulong),
("dwFillAttribute", c_ulong),
("dwFlags", c_ulong),
("wShowWindow", c_short),
("cbReserved2", c_short),
("lpReserved2", LPBYTE),
("hStdInput", c_void_p),
("hStdOutput", c_void_p),
("hStdError", c_void_p),]
def to_str(self):
return ''
class PROCESS_INFORMATION(Structure):
_fields_ = [("hProcess", c_void_p),
("hThread", c_void_p),
("dwProcessId", c_ulong),
("dwThreadId", c_ulong),]
def to_str(self):
return ''
class MEMORY_BASIC_INFORMATION(Structure):
_fields_ = [("BaseAddress", c_void_p),
("AllocationBase", c_void_p),
("AllocationProtect", c_ulong),
("RegionSize", c_ulong),
("State", c_ulong),
("Protect", c_ulong),
("Type", c_ulong),]
def to_str(self):
return ''
class SECURITY_ATTRIBUTES(Structure):
_fields_ = [("Length", c_ulong),
("SecDescriptor", c_void_p),
("InheritHandle", c_bool)]
def to_str(self):
return ''
class COORD(Structure):
_fields_ = [("X", c_short),
("Y", c_short)]
def to_str(self):
return ''
class SMALL_RECT(Structure):
_fields_ = [("Left", c_short),
("Top", c_short),
("Right", c_short),
("Bottom", c_short)]
def to_str(self):
return ''
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [("dwSize", COORD),
("dwCursorPosition", COORD),
("wAttributes", c_short),
("srWindow", SMALL_RECT),
("dwMaximumWindowSize", COORD)]
def to_str(self):
return ''
class CHAR_UNION(Union):
_fields_ = [("UnicodeChar", c_wchar),
("AsciiChar", c_char)]
def to_str(self):
return ''
class CHAR_INFO(Structure):
_fields_ = [("Char", CHAR_UNION),
("Attributes", c_short)]
def to_str(self):
return ''
class KEY_EVENT_RECORD(Structure):
_fields_ = [("bKeyDown", c_byte),
("pad2", c_byte),
('pad1', c_short),
("wRepeatCount", c_short),
("wVirtualKeyCode", c_short),
("wVirtualScanCode", c_short),
("uChar", CHAR_UNION),
("dwControlKeyState", c_int)]
def to_str(self):
return ''
class MOUSE_EVENT_RECORD(Structure):
_fields_ = [("dwMousePosition", COORD),
("dwButtonState", c_int),
("dwControlKeyState", c_int),
("dwEventFlags", c_int)]
def to_str(self):
return ''
class WINDOW_BUFFER_SIZE_RECORD(Structure):
_fields_ = [("dwSize", COORD)]
def to_str(self):
return ''
class MENU_EVENT_RECORD(Structure):
_fields_ = [("dwCommandId", c_uint)]
def to_str(self):
return ''
class FOCUS_EVENT_RECORD(Structure):
_fields_ = [("bSetFocus", c_byte)]
def to_str(self):
return ''
class INPUT_UNION(Union):
_fields_ = [("KeyEvent", KEY_EVENT_RECORD),
("MouseEvent", MOUSE_EVENT_RECORD),
("WindowBufferSizeEvent", WINDOW_BUFFER_SIZE_RECORD),
("MenuEvent", MENU_EVENT_RECORD),
("FocusEvent", FOCUS_EVENT_RECORD)]
def to_str(self):
return ''
class INPUT_RECORD(Structure):
_fields_ = [("EventType", c_short),
("Event", INPUT_UNION)]
def to_str(self):
return ''