00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "precomp.h"
00024
#pragma hdrstop
00025
#pragma hdrstop
00026
00027
#if !defined(BUILD_WOW64)
00028
00029 typedef HANDLE (*
PCONVPALFUNC)(HANDLE);
00030 PCONVPALFUNC pfnGdiConvertPalette;
00031
00032
#endif
00033
00034
#if !defined(BUILD_WOW6432)
00035
00036
BOOL
00037 WINAPI
00038 SetConsoleCursor(
00039 IN HANDLE hConsoleOutput,
00040 IN HCURSOR hCursor
00041 )
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 {
00066
00067
CONSOLE_API_MSG m;
00068
PCONSOLE_SETCURSOR_MSG a = &m.
u.SetConsoleCursor;
00069
00070 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00071 a->
OutputHandle = hConsoleOutput;
00072 a->
CursorHandle = hCursor;
00073
CsrClientCallServer( (PCSR_API_MSG)&m,
00074
NULL,
00075 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00076
ConsolepSetCursor
00077 ),
00078
sizeof( *a )
00079 );
00080
if (!
NT_SUCCESS( m.ReturnValue)) {
00081
SET_LAST_NT_ERROR(m.ReturnValue);
00082
return FALSE;
00083 }
00084
else {
00085
return TRUE;
00086 }
00087
00088 }
00089
00090
int
00091 WINAPI
00092 ShowConsoleCursor(
00093 IN HANDLE hConsoleOutput,
00094 IN BOOL bShow
00095 )
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 {
00118
00119
CONSOLE_API_MSG m;
00120
PCONSOLE_SHOWCURSOR_MSG a = &m.
u.ShowConsoleCursor;
00121
00122 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00123 a->
OutputHandle = hConsoleOutput;
00124 a->
bShow = bShow;
00125
CsrClientCallServer( (PCSR_API_MSG)&m,
00126
NULL,
00127 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00128
ConsolepShowCursor
00129 ),
00130
sizeof( *a )
00131 );
00132
return a->DisplayCount;
00133
00134 }
00135
00136 HMENU
00137
APIENTRY
00138 ConsoleMenuControl(
00139 IN HANDLE hConsoleOutput,
00140 IN UINT dwCommandIdLow,
00141 IN UINT dwCommandIdHigh
00142 )
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 {
00170
00171
CONSOLE_API_MSG m;
00172
PCONSOLE_MENUCONTROL_MSG a = &m.
u.ConsoleMenuControl;
00173
00174 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00175 a->
OutputHandle = hConsoleOutput;
00176 a->
CommandIdLow =dwCommandIdLow;
00177 a->
CommandIdHigh = dwCommandIdHigh;
00178
CsrClientCallServer( (PCSR_API_MSG)&m,
00179
NULL,
00180 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00181
ConsolepMenuControl
00182 ),
00183
sizeof( *a )
00184 );
00185
return a->hMenu;
00186
00187 }
00188
00189
BOOL
00190
APIENTRY
00191 SetConsolePaletteInternal(
00192 IN HANDLE hConsoleOutput,
00193 IN HPALETTE hPalette,
00194 IN UINT dwUsage
00195 )
00196 {
00197
00198
CONSOLE_API_MSG m;
00199
PCONSOLE_SETPALETTE_MSG a = &m.
u.SetConsolePalette;
00200
NTSTATUS Status;
00201
00202 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00203 a->
OutputHandle = hConsoleOutput;
00204 a->
hPalette = hPalette;
00205 a->
dwUsage = dwUsage;
00206
CsrClientCallServer( (PCSR_API_MSG)&m,
00207
NULL,
00208 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00209
ConsolepSetPalette
00210 ),
00211
sizeof( *a )
00212 );
00213
if (!
NT_SUCCESS( m.ReturnValue)) {
00214
SET_LAST_NT_ERROR(m.ReturnValue);
00215
return FALSE;
00216 }
00217
else {
00218
return TRUE;
00219 }
00220
00221 }
00222
00223
BOOL
00224
APIENTRY
00225 SetConsoleDisplayMode(
00226 IN HANDLE hConsoleOutput,
00227 IN DWORD dwFlags,
00228 OUT PCOORD lpNewScreenBufferDimensions
00229 )
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 {
00262
00263
CONSOLE_API_MSG m;
00264
PCONSOLE_SETDISPLAYMODE_MSG a = &m.
u.SetConsoleDisplayMode;
00265
NTSTATUS Status;
00266
00267
#if !defined(_X86_)
00268
return FALSE;
00269
#else
00270
00271
Status =
NtCreateEvent(&(a->
hEvent),
00272 EVENT_ALL_ACCESS,
00273
NULL,
00274 SynchronizationEvent,
00275 (BOOLEAN)
FALSE
00276 );
00277
if (!
NT_SUCCESS(
Status)) {
00278
SET_LAST_NT_ERROR(
Status);
00279
return FALSE;
00280 }
00281
00282 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00283 a->
OutputHandle = hConsoleOutput;
00284 a->
dwFlags =
dwFlags;
00285
00286
CsrClientCallServer( (PCSR_API_MSG)&m,
00287
NULL,
00288 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00289
ConsolepSetDisplayMode
00290 ),
00291
sizeof( *a )
00292 );
00293
if (!
NT_SUCCESS( m.ReturnValue)) {
00294
SET_LAST_NT_ERROR(m.ReturnValue);
00295
NtClose(a->hEvent);
00296
return FALSE;
00297
00298 }
00299
else {
00300
Status =
NtWaitForSingleObject(a->hEvent,
FALSE,
NULL);
00301
NtClose(a->hEvent);
00302
00303
if (
Status != 0) {
00304
SET_LAST_NT_ERROR(
Status);
00305
return FALSE;
00306 }
00307
try {
00308 *lpNewScreenBufferDimensions = a->ScreenBufferDimensions;
00309 } except(
EXCEPTION_EXECUTE_HANDLER ) {
00310
SET_LAST_ERROR(ERROR_INVALID_ACCESS);
00311
return FALSE;
00312 }
00313
return TRUE;
00314 }
00315
00316
#endif
00317
00318 }
00319
00320
BOOL
00321
APIENTRY
00322 RegisterConsoleVDM(
00323 IN DWORD dwRegisterFlags,
00324 IN HANDLE hStartHardwareEvent,
00325 IN HANDLE hEndHardwareEvent,
00326 IN LPWSTR lpStateSectionName,
00327 IN DWORD dwStateSectionNameLength,
00328 OUT LPDWORD lpStateLength,
00329 OUT PVOID *lpState,
00330 IN LPWSTR lpVDMBufferSectionName,
00331 IN DWORD dwVDMBufferSectionNameLength,
00332 IN COORD VDMBufferSize OPTIONAL,
00333 OUT PVOID *lpVDMBuffer
00334 )
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 {
00360
CONSOLE_API_MSG m;
00361
PCONSOLE_REGISTERVDM_MSG a = &m.
u.RegisterConsoleVDM;
00362 PCSR_CAPTURE_HEADER CaptureBuffer;
00363
00364 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00365 a->
RegisterFlags = dwRegisterFlags;
00366
if (dwRegisterFlags) {
00367 a->
StartEvent = hStartHardwareEvent;
00368 a->
EndEvent = hEndHardwareEvent;
00369 a->
VDMBufferSectionNameLength = dwVDMBufferSectionNameLength;
00370 a->
VDMBufferSize = VDMBufferSize;
00371 a->
StateSectionNameLength = dwStateSectionNameLength;
00372 CaptureBuffer =
CsrAllocateCaptureBuffer( 2,
00373 dwStateSectionNameLength+dwVDMBufferSectionNameLength
00374 );
00375
if (CaptureBuffer ==
NULL) {
00376
SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
00377
return FALSE;
00378 }
00379
00380
CsrCaptureMessageBuffer( CaptureBuffer,
00381 lpStateSectionName,
00382 dwStateSectionNameLength,
00383 (PVOID *) &a->
StateSectionName
00384 );
00385
00386
CsrCaptureMessageBuffer( CaptureBuffer,
00387 lpVDMBufferSectionName,
00388 dwVDMBufferSectionNameLength,
00389 (PVOID *) &a->
VDMBufferSectionName
00390 );
00391 }
else {
00392 CaptureBuffer =
NULL;
00393 }
00394
CsrClientCallServer( (PCSR_API_MSG)&m,
00395 CaptureBuffer,
00396 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00397
ConsolepRegisterVDM
00398 ),
00399
sizeof( *a )
00400 );
00401
if (CaptureBuffer !=
NULL) {
00402
CsrFreeCaptureBuffer( CaptureBuffer );
00403 }
00404
if (!
NT_SUCCESS( m.ReturnValue)) {
00405
SET_LAST_NT_ERROR(m.ReturnValue);
00406
return FALSE;
00407 }
00408
else {
00409
if (dwRegisterFlags) {
00410
try {
00411 *lpStateLength = a->StateLength;
00412 *lpState = a->StateBuffer;
00413 *lpVDMBuffer = a->VDMBuffer;
00414 } except (
EXCEPTION_EXECUTE_HANDLER) {
00415
SET_LAST_ERROR(ERROR_INVALID_ACCESS);
00416
return FALSE;
00417 }
00418 }
00419
return TRUE;
00420 }
00421 }
00422
00423
BOOL
00424
APIENTRY
00425 GetConsoleHardwareState(
00426 IN HANDLE hConsoleOutput,
00427 OUT PCOORD lpResolution,
00428 OUT PCOORD lpFontSize
00429 )
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456 {
00457
00458
CONSOLE_API_MSG m;
00459
PCONSOLE_GETHARDWARESTATE_MSG a = &m.
u.GetConsoleHardwareState;
00460
00461 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00462 a->
OutputHandle = hConsoleOutput;
00463
CsrClientCallServer( (PCSR_API_MSG)&m,
00464
NULL,
00465 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00466
ConsolepGetHardwareState
00467 ),
00468
sizeof( *a )
00469 );
00470
if (!
NT_SUCCESS( m.ReturnValue)) {
00471
SET_LAST_NT_ERROR(m.ReturnValue);
00472
return FALSE;
00473 }
00474
else {
00475
try {
00476 *lpResolution = a->Resolution;
00477 *lpFontSize = a->FontSize;
00478 } except(
EXCEPTION_EXECUTE_HANDLER ) {
00479
SET_LAST_ERROR(ERROR_INVALID_ACCESS);
00480
return FALSE;
00481 }
00482
return TRUE;
00483 }
00484
00485 }
00486
00487
BOOL
00488
APIENTRY
00489 SetConsoleHardwareState(
00490 IN HANDLE hConsoleOutput,
00491 IN COORD dwResolution,
00492 IN COORD dwFontSize
00493 )
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520 {
00521
00522
CONSOLE_API_MSG m;
00523
PCONSOLE_SETHARDWARESTATE_MSG a = &m.
u.SetConsoleHardwareState;
00524
00525 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00526 a->
OutputHandle = hConsoleOutput;
00527 a->
Resolution = dwResolution;
00528 a->
FontSize = dwFontSize;
00529
CsrClientCallServer( (PCSR_API_MSG)&m,
00530
NULL,
00531 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00532
ConsolepSetHardwareState
00533 ),
00534
sizeof( *a )
00535 );
00536
if (!
NT_SUCCESS( m.ReturnValue)) {
00537
SET_LAST_NT_ERROR(m.ReturnValue);
00538
return FALSE;
00539 }
00540
else {
00541
return TRUE;
00542 }
00543
00544 }
00545
00546
BOOL
00547
APIENTRY
00548 GetConsoleDisplayMode(
00549 OUT LPDWORD lpModeFlags
00550 )
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 {
00572
00573
CONSOLE_API_MSG m;
00574
PCONSOLE_GETDISPLAYMODE_MSG a = &m.
u.GetConsoleDisplayMode;
00575
00576 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00577
CsrClientCallServer( (PCSR_API_MSG)&m,
00578
NULL,
00579 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00580
ConsolepGetDisplayMode
00581 ),
00582
sizeof( *a )
00583 );
00584
if (!
NT_SUCCESS( m.ReturnValue)) {
00585
SET_LAST_NT_ERROR(m.ReturnValue);
00586
return FALSE;
00587 }
00588
else {
00589
try {
00590 *lpModeFlags = a->ModeFlags;
00591 } except(
EXCEPTION_EXECUTE_HANDLER ) {
00592
SET_LAST_ERROR(ERROR_INVALID_ACCESS);
00593
return FALSE;
00594 }
00595
return TRUE;
00596 }
00597
00598 }
00599
00600
BOOL
00601
APIENTRY
00602 SetConsoleKeyShortcuts(
00603 IN BOOL bSet,
00604 IN BYTE bReserveKeys,
00605 IN LPAPPKEY lpAppKeys,
00606 IN DWORD dwNumAppKeys
00607 )
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 {
00637
00638
CONSOLE_API_MSG m;
00639
PCONSOLE_SETKEYSHORTCUTS_MSG a = &m.
u.SetConsoleKeyShortcuts;
00640 PCSR_CAPTURE_HEADER CaptureBuffer;
00641
00642 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00643 a->
Set = bSet;
00644 a->
ReserveKeys = bReserveKeys;
00645
if (lpAppKeys ==
NULL) {
00646 a->
NumAppKeys = 0;
00647 CaptureBuffer =
NULL;
00648 }
else {
00649 a->
NumAppKeys = dwNumAppKeys;
00650 CaptureBuffer =
CsrAllocateCaptureBuffer( 1,
00651 dwNumAppKeys *
sizeof(APPKEY)
00652 );
00653
if (CaptureBuffer ==
NULL) {
00654
SET_LAST_ERROR(ERROR_NOT_ENOUGH_MEMORY);
00655
return FALSE;
00656 }
00657
CsrCaptureMessageBuffer( CaptureBuffer,
00658 lpAppKeys,
00659 dwNumAppKeys *
sizeof(APPKEY),
00660 (PVOID *) &a->
AppKeys
00661 );
00662 }
00663
00664
CsrClientCallServer( (PCSR_API_MSG)&m,
00665 CaptureBuffer,
00666 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00667
ConsolepSetKeyShortcuts
00668 ),
00669
sizeof( *a )
00670 );
00671
if (CaptureBuffer)
00672
CsrFreeCaptureBuffer( CaptureBuffer );
00673
if (!
NT_SUCCESS( m.ReturnValue)) {
00674
SET_LAST_NT_ERROR(m.ReturnValue);
00675
return FALSE;
00676 }
00677
else {
00678
return TRUE;
00679 }
00680
00681 }
00682
00683
BOOL
00684
APIENTRY
00685 SetConsoleMenuClose(
00686 IN BOOL bEnable
00687 )
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708 {
00709
00710
CONSOLE_API_MSG m;
00711
PCONSOLE_SETMENUCLOSE_MSG a = &m.
u.SetConsoleMenuClose;
00712
00713 a->
ConsoleHandle =
GET_CONSOLE_HANDLE;
00714 a->
Enable = bEnable;
00715
CsrClientCallServer( (PCSR_API_MSG)&m,
00716
NULL,
00717 CSR_MAKE_API_NUMBER( CONSRV_SERVERDLL_INDEX,
00718
ConsolepSetMenuClose
00719 ),
00720
sizeof( *a )
00721 );
00722
if (!
NT_SUCCESS( m.ReturnValue)) {
00723
SET_LAST_NT_ERROR(m.ReturnValue);
00724
return FALSE;
00725 }
00726
else {
00727
return TRUE;
00728 }
00729
00730 }
00731
00732
#endif
00733
00734
#if !defined(BUILD_WOW64)
00735
00736
BOOL
00737 SetConsolePalette(
00738 IN HANDLE hConsoleOutput,
00739 IN HPALETTE hPalette,
00740 IN UINT dwUsage
00741 )
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769
00770
00771
00772
00773 {
00774
00775 HANDLE hmodGdi;
00776 UNICODE_STRING ModuleNameString;
00777
NTSTATUS Status;
00778
00779
if ( !
pfnGdiConvertPalette ) {
00780
RtlInitUnicodeString( &ModuleNameString,
L"gdi32" );
00781
Status =
LdrLoadDll( UNICODE_NULL,
NULL, &ModuleNameString, &hmodGdi );
00782
if ( !
NT_SUCCESS(
Status) ) {
00783
SET_LAST_NT_ERROR(
Status);
00784
return FALSE;
00785 }
00786
pfnGdiConvertPalette = (
PCONVPALFUNC)GetProcAddress(hmodGdi,
"GdiConvertPalette");
00787
if (
pfnGdiConvertPalette ==
NULL) {
00788
SET_LAST_NT_ERROR(STATUS_PROCEDURE_NOT_FOUND);
00789
return FALSE;
00790 }
00791
00792 }
00793
00794 hPalette = (*pfnGdiConvertPalette)(hPalette);
00795
00796
return SetConsolePaletteInternal(hConsoleOutput,
00797 hPalette,
00798 dwUsage);
00799 }
00800
00801
BOOL
00802
APIENTRY
00803 WriteConsoleInputVDMA(
00804 HANDLE hConsoleInput,
00805 PINPUT_RECORD lpBuffer,
00806 DWORD nLength,
00807 LPDWORD lpNumberOfEventsWritten
00808 )
00809 {
00810
return WriteConsoleInputInternal(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten,
FALSE,
FALSE);
00811 }
00812
00813
BOOL
00814
APIENTRY
00815 WriteConsoleInputVDMW(
00816 HANDLE hConsoleInput,
00817 PINPUT_RECORD lpBuffer,
00818 DWORD nLength,
00819 LPDWORD lpNumberOfEventsWritten
00820 )
00821 {
00822
return WriteConsoleInputInternal(hConsoleInput,lpBuffer,nLength,lpNumberOfEventsWritten,
TRUE,
FALSE);
00823 }
00824
00825
#endif