00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
#include <nt.h>
00014
#include <ntrtl.h>
00015
#include <nturtl.h>
00016
#include "usercli.h"
00017
#include <string.h>
00018
00019
#include "ntcsrdll.h"
00020
#include "csuser.h"
00021
00022
00023
00024
00025 typedef CSR_QLPC_API_MSG *
PCSRMSG;
00026
00027 typedef PDWORD (*
PINSTUBFUNC)(PDWORD, PDWORD, PDWORD, PDWORD);
00028 typedef void (*
POUTSTUBFUNC)(PDWORD, PDWORD);
00029
00030 PDWORD
Copy4(PDWORD psrc,PDWORD pdst,PDWORD pparam,PDWORD pmax);
00031 PDWORD
Copy5(PDWORD psrc,PDWORD pdst,PDWORD pparam,PDWORD pmax);
00032 PDWORD
CopySTR(PDWORD psrc,PDWORD pdst,PDWORD pparam,PDWORD pmax);
00033
00034
#if !defined(_MIPS_) && !defined(_PPC_)
00035 void OutCopy4(
00036 PDWORD psrc,
00037 PDWORD pdst)
00038 {
00039 pdst[0] = psrc[0];
00040 pdst[1] = psrc[1];
00041 pdst[2] = psrc[2];
00042 pdst[3] = psrc[3];
00043 }
00044
00045 PDWORD
Copy4(
00046 PDWORD psrc,
00047 PDWORD pdst,
00048 PDWORD pparam,
00049 PDWORD pmax)
00050 {
00051
if (pdst + 5 <= pmax) {
00052 pdst[0] = psrc[0];
00053 pdst[1] = psrc[1];
00054 pdst[2] = psrc[2];
00055 pdst[3] = psrc[3];
00056
return pdst + 4;
00057 }
00058
return 0;
00059 pparam;
00060 }
00061
00062 PDWORD
Copy5(
00063 PDWORD psrc,
00064 PDWORD pdst,
00065 PDWORD pparam,
00066 PDWORD pmax)
00067 {
00068
if (pdst + 5 <= pmax) {
00069 pdst[0] = psrc[0];
00070 pdst[1] = psrc[1];
00071 pdst[2] = psrc[2];
00072 pdst[3] = psrc[3];
00073 pdst[4] = psrc[4];
00074
return pdst + 5;
00075 }
00076
return 0;
00077 pparam;
00078 }
00079
00080 PDWORD
Copy6(
00081 PDWORD psrc,
00082 PDWORD pdst,
00083 PDWORD pparam,
00084 PDWORD pmax)
00085 {
00086
if (pdst + 6 <= pmax) {
00087 pdst[0] = psrc[0];
00088 pdst[1] = psrc[1];
00089 pdst[2] = psrc[2];
00090 pdst[3] = psrc[3];
00091 pdst[4] = psrc[4];
00092 pdst[5] = psrc[5];
00093
return pdst + 6;
00094 }
00095
return 0;
00096 pparam;
00097 }
00098
00099 PDWORD
CopySTR(
00100 PDWORD psrc,
00101 PDWORD pdst,
00102 PDWORD pparam,
00103 PDWORD pmax)
00104 {
00105
PBYTE length = (
PBYTE)psrc;
00106
00107
while (*length)
00108 length++;
00109
00110 length = (length - (
PBYTE)psrc + (
PBYTE)pdst);
00111 length = (
PBYTE)(((
DWORD)length +3 ) & ~3);
00112
00113
if (length <= (
PBYTE)pmax) {
00114
while ((
PBYTE)pdst != (
PBYTE)length) {
00115 *pdst = *psrc;
00116 pdst++;
00117 psrc++;
00118 }
00119
return (PDWORD)length;
00120 }
00121
return 0;
00122 pparam;
00123 }
00124
#endif
00125
00126
00127
00128
00129 PDWORD
AIDoClientInStuff(
00130 PDWORD psrc,
00131 PDWORD pbase,
00132 PDWORD ptemplate,
00133 PDWORD pmax);
00134
00135
VOID AIDoClientOutStuff(
00136 PDWORD psrc,
00137 PDWORD pbase,
00138 PDWORD ptemplate);
00139
00140 PDWORD
DoClientInStuff(
00141 PDWORD psrc,
00142 PDWORD pbase,
00143 PDWORD ptemplate,
00144 PDWORD pmax)
00145 {
00146 PDWORD pparam;
00147 PDWORD param;
00148 PDWORD pdst;
00149
00150
if (ptemplate[0]) {
00151 pdst = ((
PINSTUBFUNC)ptemplate[0])(psrc, pbase,
NULL, pmax);
00152
if (!pdst) {
00153
return 0;
00154 }
00155 ptemplate++;
00156
00157
while (ptemplate[0]) {
00158 pparam = (PDWORD)((
PBYTE)pbase + ptemplate[1]);
00159 param = (PDWORD)*pparam;
00160 *pparam = (
PBYTE)pdst - (
PBYTE)pbase;
00161 pdst = ((
PINSTUBFUNC)ptemplate[0])(param, pdst, pparam, pmax);
00162
if (!pdst) {
00163
return 0;
00164 }
00165 ptemplate += 2;
00166 }
00167 }
00168 }
00169
00170 VOID DoClientOutStuff(
00171 PDWORD psrc,
00172 PDWORD pdst,
00173 PDWORD ptemplate)
00174 {
00175 PDWORD pparam;
00176
00177
while (ptemplate[0]) {
00178 pparam = (PDWORD)((
PBYTE)psrc + ptemplate[1]);
00179 ((
POUTSTUBFUNC)ptemplate[0])(
00180 (PDWORD)((
PBYTE)psrc + *pparam),
00181 *(PDWORD *)((
PBYTE)pdst + ptemplate[1])
00182 );
00183 ptemplate += 2;
00184 }
00185 }
00186
00187
00188
00189
00190 DWORD MakeCSCall(
00191 DWORD findex,
00192 PDWORD psrc,
00193 PDWORD pInTemplate,
00194 PDWORD pOutTemplate
00195 )
00196 {
00197 PCSR_QLPC_TEB pteb = (PCSR_QLPC_TEB)NtCurrentTeb()->CsrQlpcTeb;
00198 PCSR_QLPC_STACK pstack;
00199
PCSRMSG pmsg;
00200 ULONG retval;
00201 PDWORD pbase;
00202 PDWORD pdst;
00203 PDWORD plast;
00204 PDWORD pmax;
00205
00206
00207
00208
00209
00210
if (pteb ==
NULL) {
00211 pteb = CsrClientThreadConnect();
00212
if (pteb ==
NULL) {
00213
return 0;
00214 }
00215 }
00216
00217 pstack = pteb->MessageStack;
00218
if (pstack->BatchCount) {
00219 CsrClientSendMessage();
00220 pbase = (PDWORD)((
PBYTE)pstack + pstack->Base);
00221 }
else {
00222 pbase = (PDWORD)((
PBYTE)pstack + pstack->Current);
00223 }
00224 pmax = (PDWORD)((
PBYTE)pstack + pstack->Limit);
00225 pmsg = (
PCSRMSG)(pbase+1);
00226
00227
00228
00229
00230
00231 pdst = (PDWORD)(pmsg + 1);
00232
if (pdst <= pmax) {
00233
00234
00235
00236
00237
00238
if (pInTemplate) {
00239 plast =
DoClientInStuff(psrc, pdst, pInTemplate, pmax);
00240 }
else {
00241 plast = pdst;
00242 }
00243
00244
if (plast) {
00245
00246
00247
00248
00249
00250 pmsg->Length = (
PBYTE)plast - (
PBYTE)pmsg;
00251 pmsg->ApiNumber = findex;
00252 *pbase = pstack->Base;
00253 pstack->Base = pstack->Current+4;
00254 pstack->Current = (
PBYTE)pdst - (
PBYTE)pstack;
00255 pstack->BatchCount = 1;
00256
00257 retval = CsrClientSendMessage();
00258
00259 pstack->Current = pstack->Base - 4;
00260 pstack->Base = *pbase;
00261
00262
00263
00264
00265
00266
if (pOutTemplate) {
00267
DoClientOutStuff(pdst, psrc, pOutTemplate);
00268 }
00269
00270
return retval;
00271 }
00272 }
00273
00274
00275
00276
00277
00278
return 0;
00279 }
00280
00281
00282
00283
00284
#if defined(_MIPS_) || defined(_PPC_)
00285
DWORD AIMakeCSCall(
00286 DWORD findex,
00287 PDWORD psrc,
00288 PDWORD pInTemplate,
00289 PDWORD pOutTemplate
00290 )
00291 {
00292 PCSR_QLPC_TEB pteb = (PCSR_QLPC_TEB)NtCurrentTeb()->CsrQlpcTeb;
00293 PCSR_QLPC_STACK pstack;
00294
PCSRMSG pmsg;
00295 ULONG retval;
00296 PDWORD pbase;
00297 PDWORD pdst;
00298 PDWORD plast;
00299 PDWORD pmax;
00300
00301
00302
00303
00304
00305
if (pteb ==
NULL) {
00306 pteb = CsrClientThreadConnect();
00307
if (pteb ==
NULL) {
00308
return 0;
00309 }
00310 }
00311
00312 pstack = pteb->MessageStack;
00313
if (pstack->BatchCount) {
00314 CsrClientSendMessage();
00315 pbase = (PDWORD)((
PBYTE)pstack + pstack->Base);
00316 }
else {
00317 pbase = (PDWORD)((
PBYTE)pstack + pstack->Current);
00318 }
00319 pmax = (PDWORD)((
PBYTE)pstack + pstack->Limit);
00320 pmsg = (
PCSRMSG)(pbase+1);
00321
00322
00323
00324
00325
00326
if ((PDWORD)((
PBYTE)pmsg +
sizeof(
PCSRMSG)) <= pmax) {
00327
00328
00329
00330
00331
00332 pdst = (PDWORD)(pmsg + 1);
00333
if (pInTemplate) {
00334 plast =
AIDoClientInStuff(psrc, pdst, pInTemplate, pmax);
00335 }
else {
00336 plast = pdst;
00337 }
00338
00339
if (plast) {
00340
00341
00342
00343
00344
00345 pmsg->Length = (
PBYTE)plast - (
PBYTE)pmsg;
00346 pmsg->ApiNumber = findex;
00347 *pbase = pstack->Base;
00348 pstack->Base = pstack->Current+4;
00349 pstack->Current = (
PBYTE)pdst - (
PBYTE)pstack;
00350 pstack->BatchCount = 1;
00351
00352 retval = CsrClientSendMessage();
00353
00354 pstack->Current = pstack->Base - 4;
00355 pstack->Base = *pbase;
00356
00357
00358
00359
00360
00361
if (pOutTemplate) {
00362
AIDoClientOutStuff(pdst, psrc, pOutTemplate);
00363 }
00364
00365
return retval;
00366 }
00367 }
00368
00369
00370
00371
00372
00373
return 0;
00374 }
00375
#endif
00376
00377
00378
00379
00380
#ifdef LATER
00381
typedef struct _TESTMSG {
00382
int a;
00383
int b;
00384 RECT *lprc;
00385
int c;
00386 LPSTR lpstr;
00387 RECT rc;
00388 } TESTMSG;
00389
00390 PDWORD CSInTestCall(
00391 PDWORD psrc,
00392 PDWORD pdst,
00393 PDWORD pmax)
00394 {
00395 PDWORD pvar;
00396 TESTMSG *pmsg;
00397 TESTMSG *pparam;
00398
00399
if (pmax > pdst +
sizeof(TESTMSG)) {
00400 pmsg = (TESTMSG *)pdst;
00401 pparam = (TESTMSG *)psrc;
00402 pvar = (PDWORD)(pmsg + 1);
00403
00404 pmsg->a = pparam->a;
00405 pmsg->b = pparam->b;
00406 pmsg->c = pparam->c;
00407
00408 pmsg->lprc = (RECT *)(((
PBYTE)&(pmsg->rc)) - (
PBYTE)pmsg);
00409 pmsg->rc = *(pparam->lprc);
00410
00411 pmsg->lpstr = (LPSTR)((
PBYTE)pvar - (
PBYTE)pmsg);
00412 pvar =
CopySTR((PDWORD)pparam->lpstr, pvar, NULL, pmax);
00413
00414
if (pvar) {
00415
return (PDWORD)pvar;
00416 }
00417 }
00418
return 0;
00419 }
00420
00421
typedef struct _TESTMSG {
00422 HWND hwnd;
00423
int a;
00424
int b;
00425
int c;
00426
int d;
00427
int e;
00428 } TESTMSG;
00429
00430 PDWORD CSInTestCall(
00431 PDWORD psrc,
00432 PDWORD pdst,
00433 PDWORD pmax)
00434 {
00435 TESTMSG *pmsg;
00436 TESTMSG *pparam;
00437
00438
if (pmax > pdst +
sizeof(TESTMSG)) {
00439 pmsg = (TESTMSG *)pdst;
00440 pparam = (TESTMSG *)psrc;
00441
00442 pmsg->hwnd = pparam->hwnd;
00443 pmsg->a = pparam->a;
00444 pmsg->b = pparam->b;
00445 pmsg->c = pparam->c;
00446 pmsg->d = pparam->d;
00447 pmsg->e = pparam->e;
00448
return (PDWORD)(pmsg + 1);
00449 }
00450
return 0;
00451 }
00452
#endif
00453
00454
00455
00456
00457 typedef PDWORD (*
PCSINFUNC)(PDWORD, PDWORD, PDWORD);
00458 typedef PDWORD (*
PCSOUTFUNC)(PDWORD, PDWORD);
00459
00460
00461 DWORD CSMakeCall(
00462 DWORD findex,
00463 PDWORD psrc,
00464 PCSINFUNC pInFunc,
00465 PCSOUTFUNC pOutFunc
00466 )
00467 {
00468 PCSR_QLPC_TEB pteb = (PCSR_QLPC_TEB)NtCurrentTeb()->CsrQlpcTeb;
00469 PCSR_QLPC_STACK pstack;
00470
PCSRMSG pmsg;
00471 ULONG retval;
00472 PDWORD pbase;
00473 PDWORD pdst;
00474 PDWORD plast;
00475 PDWORD pmax;
00476
00477
00478
00479
00480
00481
if (pteb ==
NULL) {
00482 pteb = CsrClientThreadConnect();
00483
if (pteb ==
NULL) {
00484
return 0;
00485 }
00486 }
00487
00488 pstack = pteb->MessageStack;
00489
if (pstack->BatchCount) {
00490 CsrClientSendMessage();
00491 pbase = (PDWORD)((
PBYTE)pstack + pstack->Base);
00492 }
else {
00493 pbase = (PDWORD)((
PBYTE)pstack + pstack->Current);
00494 }
00495 pmax = (PDWORD)((
PBYTE)pstack + pstack->Limit);
00496 pmsg = (
PCSRMSG)(pbase+1);
00497
00498
00499
00500
00501
00502 pdst = (PDWORD)(pmsg + 1);
00503
if (pdst <= pmax) {
00504
00505
00506
00507
00508
00509
if (pInFunc) {
00510 plast = pInFunc(psrc, pdst, pmax);
00511 }
else {
00512 plast = pdst;
00513 }
00514
00515
if (plast) {
00516
00517
00518
00519
00520
00521 pmsg->Length = (
PBYTE)plast - (
PBYTE)pmsg;
00522 pmsg->ApiNumber = findex;
00523 *pbase = pstack->Base;
00524 pstack->Base = pstack->Current+4;
00525 pstack->Current = (
PBYTE)pdst - (
PBYTE)pstack;
00526 pstack->BatchCount = 1;
00527
00528 retval = CsrClientSendMessage();
00529
00530 pstack->Current = pstack->Base - 4;
00531 pstack->Base = *pbase;
00532
00533
00534
00535
00536
00537
if (pOutFunc) {
00538 pOutFunc(pdst, psrc);
00539 }
00540
00541
return retval;
00542 }
00543 }
00544
00545
00546
00547
00548
00549
return 0;
00550 }
00551
00552
00553
00554
00555
00556
00557
#if 0
00558
DWORD CTestCall(HWND hwnd,
int a,
int b,
int c,
int d,
int e)
00559 {
00560
return CSMakeCall(
00561 CSR_MAKE_API_NUMBER(4,FI_CTESTCALL),
00562 (PDWORD)&hwnd,
00563 CSInTestCall,
00564 NULL);
00565 }
00566
#endif
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
#ifdef LATER
00578
DWORD InTestCall[] = {
00579 (
DWORD)
Copy5,
00580 (
DWORD)
Copy4,
00581 8,
00582 (
DWORD)
CopySTR,
00583 16,
00584 0
00585 };
00586
#endif
00587
00588 DWORD InTestCall[] = {
00589 (
DWORD)
Copy6,
00590 0
00591 };
00592
00593 DWORD ITestCall(HWND hwnd,
int a,
int b,
int c,
int d,
int e)
00594 {
00595
return MakeCSCall(
00596 CSR_MAKE_API_NUMBER(4,FI_CTESTCALL),
00597 (PDWORD)&hwnd,
00598
InTestCall,
00599
NULL
00600 );
00601 }
00602
00603 DWORD AITestCall(HWND hwnd,
int a,
int b,
int c,
int d,
int e)
00604 {
00605
#if defined(_MIPS_) || defined(_PPC_)
00606
return AIMakeCSCall(
00607 #
else
00608
return MakeCSCall(
00609 #endif
00610 CSR_MAKE_API_NUMBER(4,FI_CTESTCALL),
00611 (PDWORD)&hwnd,
00612
InTestCall,
00613
NULL
00614 );
00615 }
00616
00617
00618