00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
#include "string.h"
00033
#include "nt.h"
00034
#include "ntrtlp.h"
00035
00036
00037
#if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
00038
#pragma alloc_text(PAGE,RtlUpperChar)
00039
#pragma alloc_text(PAGE,RtlUpperString)
00040
#endif
00041
00042
00043
00044
00045 extern PUSHORT NlsAnsiToUnicodeData;
00046 extern PCH
NlsUnicodeToAnsiData;
00047 extern PUSHORT NlsLeadByteInfo;
00048 extern PUSHORT NlsUnicodeToMbAnsiData;
00049 extern BOOLEAN
NlsMbCodePageTag;
00050
00051
00052
00053
#if !defined(_M_IX86)
00054
00055
VOID
00056 RtlInitString(
00057 OUT PSTRING DestinationString,
00058 IN PCSZ SourceString OPTIONAL
00059 )
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 {
00086 ULONG Length;
00087
00088 DestinationString->Buffer = (PCHAR)
SourceString;
00089
if (ARGUMENT_PRESENT(
SourceString )) {
00090 Length =
strlen(
SourceString);
00091 DestinationString->Length = (
USHORT)Length;
00092 DestinationString->MaximumLength = (
USHORT)(Length+1);
00093 }
00094
else {
00095 DestinationString->Length = 0;
00096 DestinationString->MaximumLength = 0;
00097 }
00098 }
00099
00100
00101
VOID
00102 RtlInitAnsiString(
00103 OUT PANSI_STRING DestinationString,
00104 IN PCSZ SourceString OPTIONAL
00105 )
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 {
00132 ULONG Length;
00133
00134 DestinationString->Buffer = (PCHAR)
SourceString;
00135
if (ARGUMENT_PRESENT(
SourceString )) {
00136 Length =
strlen(
SourceString);
00137 DestinationString->Length = (
USHORT)Length;
00138 DestinationString->MaximumLength = (
USHORT)(Length+1);
00139 }
00140
else {
00141 DestinationString->Length = 0;
00142 DestinationString->MaximumLength = 0;
00143 }
00144 }
00145
00146
00147
VOID
00148 RtlInitUnicodeString(
00149 OUT PUNICODE_STRING DestinationString,
00150 IN PCWSTR SourceString OPTIONAL
00151 )
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 {
00178 ULONG Length;
00179
00180 DestinationString->Buffer = (PWSTR)
SourceString;
00181
if (ARGUMENT_PRESENT(
SourceString )) {
00182 Length = wcslen(
SourceString ) *
sizeof( WCHAR );
00183 DestinationString->Length = (
USHORT)Length;
00184 DestinationString->MaximumLength = (
USHORT)(Length +
sizeof(UNICODE_NULL));
00185 }
00186
else {
00187 DestinationString->MaximumLength = 0;
00188 DestinationString->Length = 0;
00189 }
00190 }
00191
00192
#endif // !defined(_M_IX86)
00193
00194
00195
VOID
00196 RtlCopyString(
00197 OUT PSTRING DestinationString,
00198 IN PSTRING SourceString OPTIONAL
00199 )
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 {
00228 PSZ src, dst;
00229 ULONG
n;
00230
00231
if (ARGUMENT_PRESENT(
SourceString )) {
00232 dst = DestinationString->Buffer;
00233 src =
SourceString->Buffer;
00234
n =
SourceString->Length;
00235
if ((
USHORT)
n > DestinationString->MaximumLength) {
00236
n = DestinationString->MaximumLength;
00237 }
00238 DestinationString->Length = (
USHORT)
n;
00239
while (
n) {
00240 *dst++ = *src++;
00241
n--;
00242 }
00243 }
00244
else {
00245 DestinationString->Length = 0;
00246 }
00247 }
00248
00249
CHAR
00250 RtlUpperChar (
00251
register IN CHAR Character
00252 )
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 {
00271
00272
00273
00274
00275
00276
00277
00278
00279
if (Character <=
'z') {
00280
if (Character >=
'a') {
00281
return Character ^ 0x20;
00282 }
00283
else {
00284
return Character;
00285 }
00286 }
00287
else {
00288 WCHAR wCh;
00289
00290
00291
00292
00293
if (!
NlsMbCodePageTag) {
00294
00295
00296
00297 wCh =
NlsAnsiToUnicodeData[(UCHAR)Character];
00298 wCh =
NLS_UPCASE(wCh);
00299
return NlsUnicodeToAnsiData[(
USHORT)wCh];
00300 }
00301
else {
00302
00303
00304
00305
00306
00307
if (!
NlsLeadByteInfo[Character]) {
00308 wCh =
NlsAnsiToUnicodeData[(UCHAR)Character];
00309 wCh =
NLS_UPCASE(wCh);
00310 wCh =
NlsUnicodeToMbAnsiData[(
USHORT)wCh];
00311
if (!
HIBYTE(wCh)) {
00312
return LOBYTE(wCh);
00313 }
00314 }
00315 }
00316 }
00317
00318
return Character;
00319 }
00320
00321 LONG
00322 RtlCompareString(
00323 IN PSTRING String1,
00324 IN PSTRING String2,
00325 IN BOOLEAN CaseInSensitive
00326 )
00327
00328
00329
00330
00331
00332
00333
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
00361 {
00362
00363 PUCHAR s1, s2, Limit;
00364 LONG n1, n2;
00365 UCHAR c1, c2;
00366
00367 s1 =
String1->Buffer;
00368 s2 =
String2->Buffer;
00369 n1 =
String1->Length;
00370 n2 =
String2->Length;
00371 Limit = s1 + (n1 <= n2 ? n1 : n2);
00372
if (CaseInSensitive) {
00373
while (s1 < Limit) {
00374 c1 = *s1++;
00375 c2 = *s2++;
00376
if (c1 !=c2) {
00377 c1 =
RtlUpperChar(c1);
00378 c2 =
RtlUpperChar(c2);
00379
if (c1 != c2) {
00380
return (LONG)c1 - (LONG)c2;
00381 }
00382 }
00383 }
00384
00385 }
else {
00386
while (s1 < Limit) {
00387 c1 = *s1++;
00388 c2 = *s2++;
00389
if (c1 != c2) {
00390
return (LONG)c1 - (LONG)c2;
00391 }
00392 }
00393 }
00394
00395
return n1 - n2;
00396 }
00397
00398 BOOLEAN
00399 RtlEqualString(
00400 IN PSTRING String1,
00401 IN PSTRING String2,
00402 IN BOOLEAN CaseInSensitive
00403 )
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429 {
00430
00431 PUCHAR s1, s2, Limit;
00432 LONG n1, n2;
00433 UCHAR c1, c2;
00434
00435 n1 =
String1->Length;
00436 n2 =
String2->Length;
00437
if (n1 == n2) {
00438 s1 =
String1->Buffer;
00439 s2 =
String2->Buffer;
00440 Limit = s1 + n1;
00441
if (CaseInSensitive) {
00442
while (s1 < Limit) {
00443 c1 = *s1++;
00444 c2 = *s2++;
00445
if (c1 != c2) {
00446 c1 =
RtlUpperChar(c1);
00447 c2 =
RtlUpperChar(c2);
00448
if (c1 != c2) {
00449
return FALSE;
00450 }
00451 }
00452 }
00453
00454
return TRUE;
00455
00456 }
else {
00457
while (s1 < Limit) {
00458 c1 = *s1++;
00459 c2 = *s2++;
00460
if (c1 != c2) {
00461
return FALSE;
00462 }
00463 }
00464
00465
return TRUE;
00466 }
00467
00468 }
else {
00469
return FALSE;
00470 }
00471 }
00472
00473 BOOLEAN
00474 RtlPrefixString(
00475 IN PSTRING String1,
00476 IN PSTRING String2,
00477 IN BOOLEAN CaseInSensitive
00478 )
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506 {
00507 PSZ s1, s2;
00508
USHORT n;
00509 UCHAR c1, c2;
00510
00511 s1 =
String1->Buffer;
00512 s2 =
String2->Buffer;
00513
n =
String1->Length;
00514
if (
String2->Length <
n) {
00515
return(
FALSE );
00516 }
00517
00518
if (CaseInSensitive) {
00519
while (
n) {
00520 c1 = *s1++;
00521 c2 = *s2++;
00522
00523
if (c1 != c2 &&
RtlUpperChar(c1) !=
RtlUpperChar(c2)) {
00524
return(
FALSE );
00525 }
00526
00527
n--;
00528 }
00529 }
00530
else {
00531
while (
n) {
00532
if (*s1++ != *s2++) {
00533
return(
FALSE );
00534 }
00535
00536
n--;
00537 }
00538 }
00539
00540
return TRUE;
00541 }
00542
00543 BOOLEAN
00544 RtlCreateUnicodeStringFromAsciiz(
00545 OUT PUNICODE_STRING DestinationString,
00546 IN PCSZ SourceString
00547 )
00548 {
00549 ANSI_STRING AnsiString;
00550
NTSTATUS Status;
00551
00552
RtlInitAnsiString( &AnsiString,
SourceString );
00553
Status =
RtlAnsiStringToUnicodeString( DestinationString, &AnsiString,
TRUE );
00554
if (
NT_SUCCESS(
Status )) {
00555
return(
TRUE );
00556 }
00557
else {
00558
return(
FALSE );
00559 }
00560 }
00561
00562
00563
VOID
00564 RtlUpperString(
00565 IN PSTRING DestinationString,
00566 IN PSTRING SourceString
00567 )
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594 {
00595 PSZ src, dst;
00596 ULONG
n;
00597
00598 dst = DestinationString->Buffer;
00599 src =
SourceString->Buffer;
00600
n =
SourceString->Length;
00601
if ((
USHORT)
n > DestinationString->MaximumLength) {
00602
n = DestinationString->MaximumLength;
00603 }
00604 DestinationString->Length = (
USHORT)
n;
00605
while (
n) {
00606 *dst++ =
RtlUpperChar(*src++);
00607
n--;
00608 }
00609 }
00610
00611
00612
NTSTATUS
00613 RtlAppendAsciizToString (
00614 IN PSTRING Destination,
00615 IN PCSZ Source OPTIONAL
00616 )
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643 {
00644
USHORT n;
00645
00646
if (ARGUMENT_PRESENT( Source )) {
00647
n = (
USHORT)
strlen( Source );
00648
00649
if ((
n + Destination->Length) > Destination->MaximumLength) {
00650
return( STATUS_BUFFER_TOO_SMALL );
00651 }
00652
00653 RtlMoveMemory( &Destination->Buffer[ Destination->Length ], Source,
n );
00654 Destination->Length +=
n;
00655 }
00656
00657
return( STATUS_SUCCESS );
00658 }
00659
00660
00661
00662
NTSTATUS
00663 RtlAppendStringToString (
00664 IN PSTRING Destination,
00665 IN PSTRING Source
00666 )
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691 {
00692
USHORT n = Source->Length;
00693
00694
if (
n) {
00695
if ((
n + Destination->Length) > Destination->MaximumLength) {
00696
return( STATUS_BUFFER_TOO_SMALL );
00697 }
00698
00699 RtlMoveMemory( &Destination->Buffer[ Destination->Length ],
00700 Source->Buffer,
00701
n
00702 );
00703 Destination->Length +=
n;
00704 }
00705
00706
return( STATUS_SUCCESS );
00707 }
00708
00709
00710
#ifndef i386
00711
00712 SIZE_T
00713 NTAPI
00714 RtlCompareMemoryUlong(
00715 PVOID Source,
00716 SIZE_T Length,
00717 ULONG Pattern
00718 )
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750 {
00751 SIZE_T CountLongs;
00752 PULONG p = (PULONG)Source;
00753 PCHAR p1, p2;
00754
00755
if (((ULONG_PTR)p & (
sizeof( ULONG )-1)) ||
00756 (Length & (
sizeof( ULONG )-1))
00757 ) {
00758
return( 0 );
00759 }
00760
00761 CountLongs = Length /
sizeof( ULONG );
00762
while (CountLongs--) {
00763
if (*p++ !=
Pattern) {
00764 p1 = (PCHAR)(p - 1);
00765 p2 = (PCHAR)&
Pattern;
00766 Length = p1 - (PCHAR)Source;
00767
while (*p1++ == *p2++) {
00768
if (p1 > (PCHAR)p) {
00769
break;
00770 }
00771
00772 Length++;
00773 }
00774 }
00775 }
00776
00777
return( Length );
00778 }
00779
00780
#endif // ndef i386