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
#include "ntrtlp.h"
00032
00033
#if defined(ALLOC_PRAGMA) && defined(NTOS_KERNEL_RUNTIME)
00034
#pragma alloc_text(PAGE,RtlAnsiStringToUnicodeString)
00035
#pragma alloc_text(PAGE,RtlAnsiCharToUnicodeChar)
00036
#pragma alloc_text(PAGE,RtlOemStringToUnicodeString)
00037
#pragma alloc_text(PAGE,RtlUnicodeStringToAnsiString)
00038
#pragma alloc_text(PAGE,RtlUpcaseUnicodeStringToAnsiString)
00039
#pragma alloc_text(PAGE,RtlUnicodeStringToOemString)
00040
#pragma alloc_text(PAGE,RtlUpcaseUnicodeStringToOemString)
00041
#pragma alloc_text(PAGE,RtlOemStringToCountedUnicodeString)
00042
#pragma alloc_text(PAGE,RtlUnicodeStringToCountedOemString)
00043
#pragma alloc_text(PAGE,RtlUpcaseUnicodeStringToCountedOemString)
00044
#pragma alloc_text(PAGE,RtlUpcaseUnicodeString)
00045
#pragma alloc_text(PAGE,RtlDowncaseUnicodeString)
00046
#pragma alloc_text(PAGE,RtlUpcaseUnicodeChar)
00047
#pragma alloc_text(PAGE,RtlFreeUnicodeString)
00048
#pragma alloc_text(PAGE,RtlFreeAnsiString)
00049
#pragma alloc_text(PAGE,RtlFreeOemString)
00050
#pragma alloc_text(PAGE,RtlCreateUnicodeString)
00051
#pragma alloc_text(PAGE,RtlEqualDomainName)
00052
#pragma alloc_text(PAGE,RtlEqualComputerName)
00053
#pragma alloc_text(PAGE,RtlEqualUnicodeString)
00054
#pragma alloc_text(PAGE,RtlxUnicodeStringToOemSize)
00055
#pragma alloc_text(PAGE,RtlxAnsiStringToUnicodeSize)
00056
#pragma alloc_text(PAGE,RtlxUnicodeStringToAnsiSize)
00057
#pragma alloc_text(PAGE,RtlxOemStringToUnicodeSize)
00058
#pragma alloc_text(PAGE,RtlIsTextUnicode)
00059
#endif
00060
00061
00062
00063
00064
00065
00066
00067
00068 extern PUSHORT NlsAnsiToUnicodeData;
00069 extern PUSHORT NlsLeadByteInfo;
00070
00071
00072
00073
00074
00075
#ifndef NETBIOS_NAME_LEN
00076 #define NETBIOS_NAME_LEN 16 // NetBIOS net name (bytes)
00077
#endif // NETBIOS_NAME_LEN
00078
00079
00080
00081
NTSTATUS
00082 RtlAnsiStringToUnicodeString(
00083 OUT PUNICODE_STRING DestinationString,
00084 IN PANSI_STRING SourceString,
00085 IN BOOLEAN AllocateDestinationString
00086 )
00087
00088
00089
00090
00091
00092
00093
00094
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
00120 {
00121 ULONG UnicodeLength;
00122 ULONG
Index;
00123
NTSTATUS st;
00124
00125
RTL_PAGED_CODE();
00126
00127 UnicodeLength = RtlAnsiStringToUnicodeSize(
SourceString);
00128
if ( UnicodeLength > MAXUSHORT ) {
00129
return STATUS_INVALID_PARAMETER_2;
00130 }
00131
00132 DestinationString->Length = (
USHORT)(UnicodeLength -
sizeof(UNICODE_NULL));
00133
if ( AllocateDestinationString ) {
00134 DestinationString->MaximumLength = (
USHORT)UnicodeLength;
00135 DestinationString->Buffer = (
RtlAllocateStringRoutine)(UnicodeLength);
00136
if ( !DestinationString->Buffer ) {
00137
return STATUS_NO_MEMORY;
00138 }
00139 }
00140
else {
00141
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00142
return STATUS_BUFFER_OVERFLOW;
00143 }
00144 }
00145
00146 st =
RtlMultiByteToUnicodeN(
00147 DestinationString->Buffer,
00148 DestinationString->Length,
00149 &
Index,
00150
SourceString->Buffer,
00151
SourceString->Length
00152 );
00153
00154
if (!
NT_SUCCESS(st)) {
00155
if ( AllocateDestinationString ) {
00156 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00157 DestinationString->Buffer =
NULL;
00158 }
00159
00160
return st;
00161 }
00162
00163 DestinationString->Buffer[
Index /
sizeof(WCHAR)] = UNICODE_NULL;
00164
00165
return STATUS_SUCCESS;
00166
00167 }
00168
00169
00170 WCHAR
00171 RtlAnsiCharToUnicodeChar(
00172 IN OUT PUCHAR *SourceCharacter
00173 )
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 {
00202 WCHAR UnicodeCharacter;
00203 ULONG cbCharSize;
00204
NTSTATUS st;
00205
00206
00207
RTL_PAGED_CODE();
00208
00209
00210
#if 0
00211
UnicodeCharacter =
NlsAnsiToUnicodeData[(UCHAR)(**SourceCharacter)];
00212 (*SourceCharacter)++;
00213
return UnicodeCharacter;
00214
#endif
00215
00216
00217
00218
00219
00220 cbCharSize =
NlsLeadByteInfo[ **SourceCharacter ] ? 2 : 1;
00221 st =
RtlMultiByteToUnicodeN ( &UnicodeCharacter,
00222
sizeof ( WCHAR ),
00223
NULL,
00224 *SourceCharacter,
00225 cbCharSize );
00226
00227
00228
00229
00230
00231
if ( !
NT_SUCCESS( st ) )
00232 {
00233
00234 UnicodeCharacter = 0x0020;
00235 }
00236
00237
00238
00239
00240 (*SourceCharacter) += cbCharSize;
00241
return UnicodeCharacter;
00242 }
00243
00244
00245
NTSTATUS
00246 RtlUnicodeStringToAnsiString(
00247 OUT PANSI_STRING DestinationString,
00248 IN PUNICODE_STRING SourceString,
00249 IN BOOLEAN AllocateDestinationString
00250 )
00251
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
00280
00281
00282
00283
00284
00285 {
00286 ULONG AnsiLength;
00287 ULONG
Index;
00288
NTSTATUS st;
00289
NTSTATUS ReturnStatus = STATUS_SUCCESS;
00290
00291
RTL_PAGED_CODE();
00292
00293 AnsiLength = RtlUnicodeStringToAnsiSize(
SourceString);
00294
if ( AnsiLength > MAXUSHORT ) {
00295
return STATUS_INVALID_PARAMETER_2;
00296 }
00297
00298 DestinationString->Length = (
USHORT)(AnsiLength - 1);
00299
if ( AllocateDestinationString ) {
00300 DestinationString->MaximumLength = (
USHORT)AnsiLength;
00301 DestinationString->Buffer = (
RtlAllocateStringRoutine)(AnsiLength);
00302
if ( !DestinationString->Buffer ) {
00303
return STATUS_NO_MEMORY;
00304 }
00305 }
00306
else {
00307
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
if (!DestinationString->MaximumLength) {
00319
return STATUS_BUFFER_OVERFLOW;
00320 }
00321 ReturnStatus = STATUS_BUFFER_OVERFLOW;
00322 DestinationString->Length = DestinationString->MaximumLength - 1;
00323 }
00324 }
00325
00326 st =
RtlUnicodeToMultiByteN(
00327 DestinationString->Buffer,
00328 DestinationString->Length,
00329 &
Index,
00330
SourceString->Buffer,
00331
SourceString->Length
00332 );
00333
00334
if (!
NT_SUCCESS(st)) {
00335
if ( AllocateDestinationString ) {
00336 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00337 DestinationString->Buffer =
NULL;
00338 }
00339
00340
return st;
00341 }
00342
00343 DestinationString->Buffer[
Index] =
'\0';
00344
00345
return ReturnStatus;
00346 }
00347
00348
00349
NTSTATUS
00350 RtlUpcaseUnicodeStringToAnsiString(
00351 OUT PANSI_STRING DestinationString,
00352 IN PUNICODE_STRING SourceString,
00353 IN BOOLEAN AllocateDestinationString
00354 )
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 {
00390 ULONG AnsiLength;
00391 ULONG
Index;
00392
NTSTATUS st;
00393
00394
RTL_PAGED_CODE();
00395
00396 AnsiLength = RtlUnicodeStringToAnsiSize(
SourceString);
00397
if ( AnsiLength > MAXUSHORT ) {
00398
return STATUS_INVALID_PARAMETER_2;
00399 }
00400
00401 DestinationString->Length = (
USHORT)(AnsiLength - 1);
00402
if ( AllocateDestinationString ) {
00403 DestinationString->MaximumLength = (
USHORT)AnsiLength;
00404 DestinationString->Buffer = (
RtlAllocateStringRoutine)(AnsiLength);
00405
if ( !DestinationString->Buffer ) {
00406
return STATUS_NO_MEMORY;
00407 }
00408 }
00409
else {
00410
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00411
return STATUS_BUFFER_OVERFLOW;
00412 }
00413 }
00414
00415 st =
RtlUpcaseUnicodeToMultiByteN(
00416 DestinationString->Buffer,
00417 DestinationString->Length,
00418 &
Index,
00419
SourceString->Buffer,
00420
SourceString->Length
00421 );
00422
00423
if (!
NT_SUCCESS(st)) {
00424
if ( AllocateDestinationString ) {
00425 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00426 DestinationString->Buffer =
NULL;
00427 }
00428
00429
return st;
00430 }
00431
00432 DestinationString->Buffer[
Index] =
'\0';
00433
00434
return STATUS_SUCCESS;
00435 }
00436
00437
00438
NTSTATUS
00439 RtlOemStringToUnicodeString(
00440 OUT PUNICODE_STRING DestinationString,
00441 IN POEM_STRING SourceString,
00442 IN BOOLEAN AllocateDestinationString
00443 )
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 {
00478 ULONG UnicodeLength;
00479 ULONG
Index;
00480
NTSTATUS st;
00481
00482
RTL_PAGED_CODE();
00483
00484 UnicodeLength = RtlOemStringToUnicodeSize(
SourceString);
00485
if ( UnicodeLength > MAXUSHORT ) {
00486
return STATUS_INVALID_PARAMETER_2;
00487 }
00488
00489 DestinationString->Length = (
USHORT)(UnicodeLength -
sizeof(UNICODE_NULL));
00490
if ( AllocateDestinationString ) {
00491 DestinationString->MaximumLength = (
USHORT)UnicodeLength;
00492 DestinationString->Buffer = (
RtlAllocateStringRoutine)(UnicodeLength);
00493
if ( !DestinationString->Buffer ) {
00494
return STATUS_NO_MEMORY;
00495 }
00496 }
00497
else {
00498
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00499
return STATUS_BUFFER_OVERFLOW;
00500 }
00501 }
00502
00503 st =
RtlOemToUnicodeN(
00504 DestinationString->Buffer,
00505 DestinationString->Length,
00506 &
Index,
00507
SourceString->Buffer,
00508
SourceString->Length
00509 );
00510
00511
if (!
NT_SUCCESS(st)) {
00512
if ( AllocateDestinationString ) {
00513 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00514 DestinationString->Buffer =
NULL;
00515 }
00516
00517
return st;
00518 }
00519
00520 DestinationString->Buffer[
Index /
sizeof(WCHAR)] = UNICODE_NULL;
00521
00522
return STATUS_SUCCESS;
00523
00524 }
00525
00526
00527
NTSTATUS
00528 RtlUnicodeStringToOemString(
00529 OUT POEM_STRING DestinationString,
00530 IN PUNICODE_STRING SourceString,
00531 IN BOOLEAN AllocateDestinationString
00532 )
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567 {
00568 ULONG OemLength;
00569 ULONG
Index;
00570
NTSTATUS st;
00571
00572
RTL_PAGED_CODE();
00573
00574 OemLength = RtlUnicodeStringToOemSize(
SourceString);
00575
if ( OemLength > MAXUSHORT ) {
00576
return STATUS_INVALID_PARAMETER_2;
00577 }
00578
00579 DestinationString->Length = (
USHORT)(OemLength - 1);
00580
if ( AllocateDestinationString ) {
00581 DestinationString->MaximumLength = (
USHORT)OemLength;
00582 DestinationString->Buffer = (
RtlAllocateStringRoutine)(OemLength);
00583
if ( !DestinationString->Buffer ) {
00584
return STATUS_NO_MEMORY;
00585 }
00586 }
00587
else {
00588
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00589
return STATUS_BUFFER_OVERFLOW;
00590 }
00591 }
00592
00593 st =
RtlUnicodeToOemN(
00594 DestinationString->Buffer,
00595 DestinationString->Length,
00596 &
Index,
00597
SourceString->Buffer,
00598
SourceString->Length
00599 );
00600
00601
if (!
NT_SUCCESS(st)) {
00602
if ( AllocateDestinationString ) {
00603 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00604 DestinationString->Buffer =
NULL;
00605 }
00606
00607
return st;
00608 }
00609
00610 DestinationString->Buffer[
Index] =
'\0';
00611
00612
return STATUS_SUCCESS;
00613 }
00614
00615
00616
NTSTATUS
00617 RtlUpcaseUnicodeStringToOemString(
00618 OUT POEM_STRING DestinationString,
00619 IN PUNICODE_STRING SourceString,
00620 IN BOOLEAN AllocateDestinationString
00621 )
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655 {
00656 ULONG OemLength;
00657 ULONG
Index;
00658
NTSTATUS st;
00659
00660
RTL_PAGED_CODE();
00661
00662 OemLength = RtlUnicodeStringToOemSize(
SourceString);
00663
if ( OemLength > MAXUSHORT ) {
00664
return STATUS_INVALID_PARAMETER_2;
00665 }
00666
00667 DestinationString->Length = (
USHORT)(OemLength - 1);
00668
if ( AllocateDestinationString ) {
00669 DestinationString->MaximumLength = (
USHORT)OemLength;
00670 DestinationString->Buffer = (
RtlAllocateStringRoutine)(OemLength);
00671
if ( !DestinationString->Buffer ) {
00672
return STATUS_NO_MEMORY;
00673 }
00674 }
00675
else {
00676
if ( DestinationString->Length >= DestinationString->MaximumLength ) {
00677
return STATUS_BUFFER_OVERFLOW;
00678 }
00679 }
00680
00681 st =
RtlUpcaseUnicodeToOemN(
00682 DestinationString->Buffer,
00683 DestinationString->Length,
00684 &
Index,
00685
SourceString->Buffer,
00686
SourceString->Length
00687 );
00688
00689
00690
00691
00692
00693
00694
if (
NT_SUCCESS(st) &&
00695 !
RtlpDidUnicodeToOemWork( DestinationString,
SourceString )) {
00696
00697 st = STATUS_UNMAPPABLE_CHARACTER;
00698 }
00699
00700
if (!
NT_SUCCESS(st)) {
00701
if ( AllocateDestinationString ) {
00702 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00703 DestinationString->Buffer =
NULL;
00704 }
00705
00706
return st;
00707 }
00708
00709 DestinationString->Buffer[
Index] =
'\0';
00710
00711
return STATUS_SUCCESS;
00712 }
00713
00714
00715
NTSTATUS
00716 RtlOemStringToCountedUnicodeString(
00717 OUT PUNICODE_STRING DestinationString,
00718 IN POEM_STRING SourceString,
00719 IN BOOLEAN AllocateDestinationString
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
00752
00753
00754
00755
00756
00757 {
00758 ULONG UnicodeLength;
00759 ULONG
Index;
00760
NTSTATUS st;
00761
00762
RTL_PAGED_CODE();
00763
00764 UnicodeLength = RtlOemStringToCountedUnicodeSize(
SourceString);
00765
00766
if ( UnicodeLength == 0 ) {
00767
00768 DestinationString->Length = 0;
00769 DestinationString->MaximumLength = 0;
00770 DestinationString->Buffer =
NULL;
00771
00772
return STATUS_SUCCESS;
00773 }
00774
00775
if ( UnicodeLength > MAXUSHORT ) {
00776
return STATUS_INVALID_PARAMETER_2;
00777 }
00778
00779 DestinationString->Length = (
USHORT)(UnicodeLength);
00780
if ( AllocateDestinationString ) {
00781 DestinationString->MaximumLength = (
USHORT)UnicodeLength;
00782 DestinationString->Buffer = (
RtlAllocateStringRoutine)(UnicodeLength);
00783
if ( !DestinationString->Buffer ) {
00784
return STATUS_NO_MEMORY;
00785 }
00786 }
00787
else {
00788
if ( DestinationString->Length > DestinationString->MaximumLength ) {
00789
return STATUS_BUFFER_OVERFLOW;
00790 }
00791 }
00792
00793 st =
RtlOemToUnicodeN(
00794 DestinationString->Buffer,
00795 DestinationString->Length,
00796 &
Index,
00797
SourceString->Buffer,
00798
SourceString->Length
00799 );
00800
00801
if (!
NT_SUCCESS(st)) {
00802
if ( AllocateDestinationString ) {
00803 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00804 DestinationString->Buffer =
NULL;
00805 }
00806
00807
return st;
00808 }
00809
00810
return STATUS_SUCCESS;
00811
00812 }
00813
00814
00815
NTSTATUS
00816 RtlUnicodeStringToCountedOemString(
00817 OUT POEM_STRING DestinationString,
00818 IN PUNICODE_STRING SourceString,
00819 IN BOOLEAN AllocateDestinationString
00820 )
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858 {
00859 ULONG OemLength;
00860 ULONG
Index;
00861
NTSTATUS st;
00862
00863
RTL_PAGED_CODE();
00864
00865 OemLength = RtlUnicodeStringToCountedOemSize(
SourceString);
00866
00867
if ( OemLength == 0 ) {
00868
00869 DestinationString->Length = 0;
00870 DestinationString->MaximumLength = 0;
00871 DestinationString->Buffer =
NULL;
00872
00873
return STATUS_SUCCESS;
00874 }
00875
00876
if ( OemLength > MAXUSHORT ) {
00877
return STATUS_INVALID_PARAMETER_2;
00878 }
00879
00880 DestinationString->Length = (
USHORT)(OemLength);
00881
if ( AllocateDestinationString ) {
00882 DestinationString->MaximumLength = (
USHORT)OemLength;
00883 DestinationString->Buffer = (
RtlAllocateStringRoutine)(OemLength);
00884
if ( !DestinationString->Buffer ) {
00885
return STATUS_NO_MEMORY;
00886 }
00887 }
00888
else {
00889
if ( DestinationString->Length > DestinationString->MaximumLength ) {
00890
return STATUS_BUFFER_OVERFLOW;
00891 }
00892 }
00893
00894 st =
RtlUnicodeToOemN(
00895 DestinationString->Buffer,
00896 DestinationString->Length,
00897 &
Index,
00898
SourceString->Buffer,
00899
SourceString->Length
00900 );
00901
00902
00903
00904
00905
00906
00907
if (
NT_SUCCESS(st) &&
00908 !
RtlpDidUnicodeToOemWork( DestinationString,
SourceString )) {
00909
00910 st = STATUS_UNMAPPABLE_CHARACTER;
00911 }
00912
00913
if (!
NT_SUCCESS(st)) {
00914
if ( AllocateDestinationString ) {
00915 (
RtlFreeStringRoutine)(DestinationString->Buffer);
00916 DestinationString->Buffer =
NULL;
00917 }
00918
00919
return st;
00920 }
00921
00922
return STATUS_SUCCESS;
00923 }
00924
00925
00926
NTSTATUS
00927 RtlUpcaseUnicodeStringToCountedOemString(
00928 OUT POEM_STRING DestinationString,
00929 IN PUNICODE_STRING SourceString,
00930 IN BOOLEAN AllocateDestinationString
00931 )
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969 {
00970 ULONG OemLength;
00971 ULONG
Index;
00972
NTSTATUS st;
00973
00974
RTL_PAGED_CODE();
00975
00976 OemLength = RtlUnicodeStringToCountedOemSize(
SourceString);
00977
00978
if ( OemLength == 0 ) {
00979
00980 DestinationString->Length = 0;
00981 DestinationString->MaximumLength = 0;
00982 DestinationString->Buffer =
NULL;
00983
00984
return STATUS_SUCCESS;
00985 }
00986
00987
if ( OemLength > MAXUSHORT ) {
00988
return STATUS_INVALID_PARAMETER_2;
00989 }
00990
00991 DestinationString->Length = (
USHORT)(OemLength);
00992
if ( AllocateDestinationString ) {
00993 DestinationString->MaximumLength = (
USHORT)OemLength;
00994 DestinationString->Buffer = (
RtlAllocateStringRoutine)(OemLength);
00995
if ( !DestinationString->Buffer ) {
00996
return STATUS_NO_MEMORY;
00997 }
00998 }
00999
else {
01000
if ( DestinationString->Length > DestinationString->MaximumLength ) {
01001
return STATUS_BUFFER_OVERFLOW;
01002 }
01003 }
01004
01005 st =
RtlUpcaseUnicodeToOemN(
01006 DestinationString->Buffer,
01007 DestinationString->Length,
01008 &
Index,
01009
SourceString->Buffer,
01010
SourceString->Length
01011 );
01012
01013
01014
01015
01016
01017
01018
if (
NT_SUCCESS(st) &&
01019 !
RtlpDidUnicodeToOemWork( DestinationString,
SourceString )) {
01020
01021 st = STATUS_UNMAPPABLE_CHARACTER;
01022 }
01023
01024
if (!
NT_SUCCESS(st)) {
01025
if ( AllocateDestinationString ) {
01026 (
RtlFreeStringRoutine)(DestinationString->Buffer);
01027 DestinationString->Buffer =
NULL;
01028 }
01029
01030
return st;
01031 }
01032
01033
return STATUS_SUCCESS;
01034 }
01035
01036
01037
NTSTATUS
01038 RtlUpcaseUnicodeString(
01039 OUT PUNICODE_STRING DestinationString,
01040 IN PCUNICODE_STRING SourceString,
01041 IN BOOLEAN AllocateDestinationString
01042 )
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076 {
01077 ULONG
Index;
01078 ULONG StopIndex;
01079
01080
RTL_PAGED_CODE();
01081
01082
if ( AllocateDestinationString ) {
01083 DestinationString->MaximumLength =
SourceString->Length;
01084 DestinationString->Buffer = (
RtlAllocateStringRoutine)((ULONG)DestinationString->MaximumLength);
01085
if ( !DestinationString->Buffer ) {
01086
return STATUS_NO_MEMORY;
01087 }
01088 }
01089
else {
01090
if (
SourceString->Length > DestinationString->MaximumLength ) {
01091
return STATUS_BUFFER_OVERFLOW;
01092 }
01093 }
01094
01095 StopIndex = ((ULONG)
SourceString->Length) /
sizeof( WCHAR );
01096
01097
for (
Index = 0;
Index < StopIndex;
Index++) {
01098 DestinationString->Buffer[
Index] = (WCHAR)
NLS_UPCASE(
SourceString->Buffer[
Index]);
01099 }
01100
01101 DestinationString->Length =
SourceString->Length;
01102
01103
return STATUS_SUCCESS;
01104 }
01105
01106
01107
NTSTATUS
01108 RtlDowncaseUnicodeString(
01109 OUT PUNICODE_STRING DestinationString,
01110 IN PUNICODE_STRING SourceString,
01111 IN BOOLEAN AllocateDestinationString
01112 )
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146 {
01147 ULONG
Index;
01148 ULONG StopIndex;
01149
01150
RTL_PAGED_CODE();
01151
01152
if ( AllocateDestinationString ) {
01153 DestinationString->MaximumLength =
SourceString->Length;
01154 DestinationString->Buffer = (
RtlAllocateStringRoutine)((ULONG)DestinationString->MaximumLength);
01155
if ( !DestinationString->Buffer ) {
01156
return STATUS_NO_MEMORY;
01157 }
01158 }
01159
else {
01160
if (
SourceString->Length > DestinationString->MaximumLength ) {
01161
return STATUS_BUFFER_OVERFLOW;
01162 }
01163 }
01164
01165 StopIndex = ((ULONG)
SourceString->Length) /
sizeof( WCHAR );
01166
01167
for (
Index = 0;
Index < StopIndex;
Index++) {
01168 DestinationString->Buffer[
Index] = (WCHAR)
NLS_DOWNCASE(
SourceString->Buffer[
Index]);
01169 }
01170
01171 DestinationString->Length =
SourceString->Length;
01172
01173
return STATUS_SUCCESS;
01174 }
01175
01176
01177 WCHAR
01178 RtlUpcaseUnicodeChar(
01179 IN WCHAR SourceCharacter
01180 )
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197
01198
01199
01200
01201
01202
01203 {
01204
RTL_PAGED_CODE();
01205
01206
01207
01208
01209
01210
return (WCHAR)
NLS_UPCASE(SourceCharacter);
01211 }
01212
01213
01214
VOID
01215 RtlFreeUnicodeString(
01216 IN OUT PUNICODE_STRING UnicodeString
01217 )
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232
01233
01234
01235
01236
01237
01238 {
01239
RTL_PAGED_CODE();
01240
01241
if (UnicodeString->Buffer) {
01242 (
RtlFreeStringRoutine)(UnicodeString->Buffer);
01243 memset( UnicodeString, 0,
sizeof( *UnicodeString ) );
01244 }
01245 }
01246
01247
01248
VOID
01249 RtlFreeAnsiString(
01250 IN OUT PANSI_STRING AnsiString
01251 )
01252
01253
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272 {
01273
RTL_PAGED_CODE();
01274
01275
if (AnsiString->Buffer) {
01276 (
RtlFreeStringRoutine)(AnsiString->Buffer);
01277 memset( AnsiString, 0,
sizeof( *AnsiString ) );
01278 }
01279 }
01280
01281
01282
VOID
01283 RtlFreeOemString(
01284 IN OUT POEM_STRING OemString
01285 )
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306 {
01307
RTL_PAGED_CODE();
01308
01309
if (OemString->Buffer) {(
RtlFreeStringRoutine)(OemString->Buffer);}
01310 }
01311
01312
01313 ULONG
01314 RtlxUnicodeStringToAnsiSize(
01315 IN PUNICODE_STRING UnicodeString
01316 )
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344 {
01345 ULONG cbMultiByteString;
01346
01347
RTL_PAGED_CODE();
01348
01349
01350
01351
01352
RtlUnicodeToMultiByteSize( &cbMultiByteString,
01353 UnicodeString->Buffer,
01354 UnicodeString->Length );
01355
01356
01357
01358
01359
return (cbMultiByteString + 1);
01360 }
01361
01362
01363 ULONG
01364 RtlxUnicodeStringToOemSize(
01365 IN PUNICODE_STRING UnicodeString
01366 )
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379
01380
01381
01382
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394 {
01395 ULONG cbMultiByteString;
01396
01397
RTL_PAGED_CODE();
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
RtlUnicodeToMultiByteSize( &cbMultiByteString,
01410 UnicodeString->Buffer,
01411 UnicodeString->Length );
01412
01413
01414
01415
01416
return (cbMultiByteString + 1);
01417 }
01418
01419
01420 ULONG
01421 RtlxAnsiStringToUnicodeSize(
01422 IN PANSI_STRING AnsiString
01423 )
01424
01425
01426
01427
01428
01429
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447 {
01448 ULONG cbConverted;
01449
01450
RTL_PAGED_CODE();
01451
01452
01453
01454
01455
RtlMultiByteToUnicodeSize( &cbConverted ,
01456 AnsiString->Buffer,
01457 AnsiString->Length );
01458
01459
01460
01461
01462
return ( cbConverted +
sizeof(UNICODE_NULL) );
01463 }
01464
01465
01466 ULONG
01467 RtlxOemStringToUnicodeSize(
01468 IN POEM_STRING OemString
01469 )
01470
01471
01472
01473
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493 {
01494 ULONG cbConverted;
01495
01496
RTL_PAGED_CODE();
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
RtlMultiByteToUnicodeSize( &cbConverted,
01509 OemString->Buffer,
01510 OemString->Length );
01511
01512
01513
01514
01515
return ( cbConverted +
sizeof(UNICODE_NULL) );
01516 }
01517
01518
01519 LONG
01520 RtlCompareUnicodeString(
01521 IN PUNICODE_STRING String1,
01522 IN PUNICODE_STRING String2,
01523 IN BOOLEAN CaseInSensitive
01524 )
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543
01544
01545
01546
01547
01548
01549
01550
01551
01552
01553
01554
01555
01556
01557
01558
01559 {
01560
01561 PWCHAR s1, s2, Limit;
01562 LONG n1, n2;
01563 WCHAR c1, c2;
01564
01565 s1 =
String1->Buffer;
01566 s2 =
String2->Buffer;
01567 n1 =
String1->Length;
01568 n2 =
String2->Length;
01569
01570
ASSERT((n1 & 1) == 0);
01571
ASSERT((n2 & 1) == 0);
01572
ASSERT(!(((((ULONG_PTR)s1 & 1) != 0) || (((ULONG_PTR)s2 & 1) != 0)) && (n1 != 0) && (n2 != 0)));
01573
01574 Limit = (PWCHAR)((PCHAR)s1 + (n1 <= n2 ? n1 : n2));
01575
if (CaseInSensitive) {
01576
while (s1 < Limit) {
01577 c1 = *s1++;
01578 c2 = *s2++;
01579
if (c1 != c2) {
01580
01581
01582
01583
01584
01585 c1 =
NLS_UPCASE(c1);
01586 c2 =
NLS_UPCASE(c2);
01587
if (c1 != c2) {
01588
return (LONG)(c1) - (LONG)(c2);
01589 }
01590 }
01591 }
01592
01593 }
else {
01594
while (s1 < Limit) {
01595 c1 = *s1++;
01596 c2 = *s2++;
01597
if (c1 != c2) {
01598
return (LONG)(c1) - (LONG)(c2);
01599 }
01600 }
01601 }
01602
01603
return n1 - n2;
01604 }
01605
01606
01607 BOOLEAN
01608 RtlEqualUnicodeString(
01609 IN PCUNICODE_STRING String1,
01610 IN PCUNICODE_STRING String2,
01611 IN BOOLEAN CaseInSensitive
01612 )
01613
01614
01615
01616
01617
01618
01619
01620
01621
01622
01623
01624
01625
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639 {
01640
01641 PWCHAR s1, s2, Limit;
01642 LONG n1, n2;
01643 WCHAR c1, c2;
01644
01645
RTL_PAGED_CODE();
01646
01647 n1 =
String1->Length;
01648 n2 =
String2->Length;
01649
01650
ASSERT((n1 & 1) == 0);
01651
ASSERT((n2 & 1) == 0);
01652
01653
if (n1 == n2) {
01654 s1 =
String1->Buffer;
01655 s2 =
String2->Buffer;
01656
01657
ASSERT(!(((((ULONG_PTR)s1 & 1) != 0) || (((ULONG_PTR)s2 & 1) != 0)) && (n1 != 0) && (n2 != 0)));
01658
01659 Limit = (PWCHAR)((PCHAR)s1 + n1);
01660
if (CaseInSensitive) {
01661
while (s1 < Limit) {
01662 c1 = *s1++;
01663 c2 = *s2++;
01664
if ((c1 != c2) && (
NLS_UPCASE(c1) !=
NLS_UPCASE(c2))) {
01665
return FALSE;
01666 }
01667 }
01668
01669
return TRUE;
01670
01671 }
else {
01672
while (s1 < Limit) {
01673 c1 = *s1++;
01674 c2 = *s2++;
01675
if (c1 != c2) {
01676
return FALSE;
01677 }
01678 }
01679
01680
return TRUE;
01681 }
01682
01683 }
else {
01684
return FALSE;
01685 }
01686 }
01687
01688
01689 BOOLEAN
01690 RtlPrefixUnicodeString(
01691 IN PUNICODE_STRING String1,
01692 IN PUNICODE_STRING String2,
01693 IN BOOLEAN CaseInSensitive
01694 )
01695
01696
01697
01698
01699
01700
01701
01702
01703
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715
01716
01717
01718
01719
01720
01721
01722
01723 {
01724 PWSTR s1, s2;
01725 ULONG
n;
01726 WCHAR c1, c2;
01727
01728 s1 =
String1->Buffer;
01729 s2 =
String2->Buffer;
01730
n =
String1->Length;
01731
if (
String2->Length <
n) {
01732
return(
FALSE );
01733 }
01734
01735
n =
n /
sizeof(c1);
01736
if (CaseInSensitive) {
01737
while (
n) {
01738 c1 = *s1++;
01739 c2 = *s2++;
01740
01741
if ((c1 != c2) && (
NLS_UPCASE(c1) !=
NLS_UPCASE(c2))) {
01742
return(
FALSE );
01743 }
01744
01745
n--;
01746 }
01747 }
01748
else {
01749
while (
n) {
01750
if (*s1++ != *s2++) {
01751
return(
FALSE );
01752 }
01753
01754
n--;
01755 }
01756 }
01757
01758
return TRUE;
01759 }
01760
01761
01762
VOID
01763 RtlCopyUnicodeString(
01764 OUT PUNICODE_STRING DestinationString,
01765 IN PUNICODE_STRING SourceString OPTIONAL
01766 )
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781
01782
01783
01784
01785
01786
01787
01788
01789
01790
01791
01792
01793
01794 {
01795 UNALIGNED WCHAR *src, *dst;
01796 ULONG
n;
01797
01798
if (ARGUMENT_PRESENT(
SourceString)) {
01799 dst = DestinationString->Buffer;
01800 src =
SourceString->Buffer;
01801
n =
SourceString->Length;
01802
if ((
USHORT)
n > DestinationString->MaximumLength) {
01803
n = DestinationString->MaximumLength;
01804 }
01805
01806 DestinationString->Length = (
USHORT)
n;
01807 RtlCopyMemory(dst, src,
n);
01808
if (DestinationString->Length < DestinationString->MaximumLength) {
01809 dst[
n /
sizeof(WCHAR)] = UNICODE_NULL;
01810 }
01811
01812 }
else {
01813 DestinationString->Length = 0;
01814 }
01815
01816
return;
01817 }
01818
01819
01820
NTSTATUS
01821 RtlAppendUnicodeToString (
01822 IN PUNICODE_STRING Destination,
01823 IN PCWSTR Source OPTIONAL
01824 )
01825
01826
01827
01828
01829
01830
01831
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852
01853 {
01854
USHORT n;
01855 UNALIGNED WCHAR *dst;
01856
01857
if (ARGUMENT_PRESENT( Source )) {
01858 UNICODE_STRING UniSource;
01859
01860
RtlInitUnicodeString(&UniSource, Source);
01861
01862
n = UniSource.Length;
01863
01864
if ((
n + Destination->Length) > Destination->MaximumLength) {
01865
return( STATUS_BUFFER_TOO_SMALL );
01866 }
01867
01868 dst = &Destination->Buffer[ (Destination->Length /
sizeof( WCHAR )) ];
01869 RtlMoveMemory( dst, Source,
n );
01870
01871 Destination->Length +=
n;
01872
01873
if (Destination->Length < Destination->MaximumLength) {
01874 dst[
n /
sizeof( WCHAR ) ] = UNICODE_NULL;
01875 }
01876 }
01877
01878
return( STATUS_SUCCESS );
01879 }
01880
01881
01882
NTSTATUS
01883 RtlAppendUnicodeStringToString (
01884 IN PUNICODE_STRING Destination,
01885 IN PUNICODE_STRING Source
01886 )
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903
01904
01905
01906
01907
01908
01909
01910
01911 {
01912
USHORT n = Source->Length;
01913 UNALIGNED WCHAR *dst;
01914
01915
if (
n) {
01916
if ((
n + Destination->Length) > Destination->MaximumLength) {
01917
return( STATUS_BUFFER_TOO_SMALL );
01918 }
01919
01920 dst = &Destination->Buffer[ (Destination->Length /
sizeof( WCHAR )) ];
01921 RtlMoveMemory( dst, Source->Buffer,
n );
01922
01923 Destination->Length +=
n;
01924
01925
if (Destination->Length < Destination->MaximumLength) {
01926 dst[
n /
sizeof( WCHAR ) ] = UNICODE_NULL;
01927 }
01928 }
01929
01930
return( STATUS_SUCCESS );
01931 }
01932
01933
01934 BOOLEAN
01935 RtlCreateUnicodeString(
01936 OUT PUNICODE_STRING DestinationString,
01937 IN PCWSTR SourceString
01938 )
01939 {
01940 ULONG cb;
01941
01942
RTL_PAGED_CODE();
01943
01944 cb = (wcslen(
SourceString ) + 1) *
sizeof( WCHAR );
01945 DestinationString->Buffer = (
RtlAllocateStringRoutine)( cb );
01946
if (DestinationString->Buffer) {
01947 RtlMoveMemory( DestinationString->Buffer,
SourceString, cb );
01948 DestinationString->MaximumLength = (
USHORT)cb;
01949 DestinationString->Length = (
USHORT)(cb -
sizeof( UNICODE_NULL ));
01950
return(
TRUE );
01951 }
01952
else {
01953
return(
FALSE );
01954 }
01955 }
01956
01957
01958 BOOLEAN
01959 RtlEqualDomainName(
01960 IN PUNICODE_STRING String1,
01961 IN PUNICODE_STRING String2
01962 )
01963
01964
01965
01966
01967
01968
01969
01970
01971
01972
01973
01974
01975
01976
01977
01978
01979
01980
01981
01982
01983
01984
01985
01986
01987 {
01988
NTSTATUS Status;
01989 BOOLEAN ReturnValue =
FALSE;
01990 OEM_STRING OemString1;
01991 OEM_STRING OemString2;
01992
01993
RTL_PAGED_CODE();
01994
01995
01996
01997
01998
01999
Status =
RtlUpcaseUnicodeStringToOemString( &OemString1,
02000
String1,
02001
TRUE );
02002
02003
if (
NT_SUCCESS(
Status ) ) {
02004
02005
02006
02007
02008
02009
Status =
RtlUpcaseUnicodeStringToOemString( &OemString2,
02010
String2,
02011
TRUE );
02012
02013
if (
NT_SUCCESS(
Status ) ) {
02014
02015
02016
02017
02018
02019 ReturnValue =
RtlEqualString( &OemString1,
02020 &OemString2,
02021
FALSE );
02022
02023
RtlFreeOemString( &OemString2 );
02024 }
02025
02026
RtlFreeOemString( &OemString1 );
02027 }
02028
02029
return ReturnValue;
02030 }
02031
02032
02033
02034 BOOLEAN
02035 RtlEqualComputerName(
02036 IN PUNICODE_STRING String1,
02037 IN PUNICODE_STRING String2
02038 )
02039
02040
02041
02042
02043
02044
02045
02046
02047
02048
02049
02050
02051
02052
02053
02054
02055
02056
02057
02058
02059
02060
02061
02062
02063 {
02064
return RtlEqualDomainName(
String1,
String2 );
02065 }
02066
02072 #define UNICODE_FFFF 0xFFFF
02073 #define REVERSE_BYTE_ORDER_MARK 0xFFFE
02074 #define BYTE_ORDER_MARK 0xFEFF
02075
02076 #define PARAGRAPH_SEPARATOR 0x2029
02077 #define LINE_SEPARATOR 0x2028
02078
02079 #define UNICODE_TAB 0x0009
02080 #define UNICODE_LF 0x000A
02081 #define UNICODE_CR 0x000D
02082 #define UNICODE_SPACE 0x0020
02083 #define UNICODE_CJK_SPACE 0x3000
02084
02085 #define UNICODE_R_TAB 0x0900
02086 #define UNICODE_R_LF 0x0A00
02087 #define UNICODE_R_CR 0x0D00
02088 #define UNICODE_R_SPACE 0x2000
02089 #define UNICODE_R_CJK_SPACE 0x0030
02090
02091 #define ASCII_CRLF 0x0A0D
02092
02093 #define __max(a,b) (((a) > (b)) ? (a) : (b))
02094 #define __min(a,b) (((a) < (b)) ? (a) : (b))
02095
02096
02097 BOOLEAN
02098 RtlIsTextUnicode(
02099 IN PVOID Buffer,
02100 IN ULONG Size,
02101 IN OUT PULONG Result OPTIONAL
02102 )
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112
02113
02114
02115
02116
02117
02118
02119
02120
02121
02122
02123
02124
02125
02126
02127
02128
02129
02130
02131
02132
02133
02134
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148 {
02149 UNALIGNED WCHAR *lpBuff =
Buffer;
02150 PCHAR lpb =
Buffer;
02151 ULONG iBOM = 0;
02152 ULONG iCR = 0;
02153 ULONG iLF = 0;
02154 ULONG iTAB = 0;
02155 ULONG iSPACE = 0;
02156 ULONG iCJK_SPACE = 0;
02157 ULONG iFFFF = 0;
02158 ULONG iPS = 0;
02159 ULONG iLS = 0;
02160
02161 ULONG iRBOM = 0;
02162 ULONG iR_CR = 0;
02163 ULONG iR_LF = 0;
02164 ULONG iR_TAB = 0;
02165 ULONG iR_SPACE = 0;
02166
02167 ULONG iNull = 0;
02168 ULONG iUNULL = 0;
02169 ULONG iCRLF = 0;
02170 ULONG iTmp;
02171 ULONG LastLo = 0;
02172 ULONG LastHi = 0;
02173 ULONG iHi, iLo;
02174 ULONG HiDiff = 0;
02175 ULONG LoDiff = 0;
02176 ULONG cLeadByte = 0;
02177 ULONG cWeird = 0;
02178
02179 ULONG iResult = 0;
02180
02181 ULONG iMaxTmp =
__min(256,
Size /
sizeof(WCHAR));
02182
02183
02184
02185
02186
02187
if ((
Size < 2) ||
02188 ((
Size == 2) && (lpBuff[0] != 0) && (lpb[1] == 0)))
02189 {
02190
if (ARGUMENT_PRESENT(Result))
02191 {
02192 *Result = IS_TEXT_UNICODE_ASCII16 | IS_TEXT_UNICODE_CONTROLS;
02193 }
02194
02195
return (
FALSE);
02196 }
02197
else if ((
Size > 2) && ((
Size /
sizeof(WCHAR)) <= 256))
02198 {
02199
02200
02201
02202
02203
02204
if (((
Size %
sizeof(WCHAR)) == 0) &&
02205 ((lpBuff[iMaxTmp - 1] & 0xff00) == 0))
02206 {
02207 iMaxTmp--;
02208 }
02209 }
02210
02211
02212
02213
02214
for (iTmp = 0; iTmp < iMaxTmp; iTmp++)
02215 {
02216
switch (lpBuff[iTmp])
02217 {
02218
case BYTE_ORDER_MARK:
02219 iBOM++;
02220
break;
02221
case PARAGRAPH_SEPARATOR:
02222 iPS++;
02223
break;
02224
case LINE_SEPARATOR:
02225 iLS++;
02226
break;
02227
case UNICODE_LF:
02228 iLF++;
02229
break;
02230
case UNICODE_TAB:
02231 iTAB++;
02232
break;
02233
case UNICODE_SPACE:
02234 iSPACE++;
02235
break;
02236
case UNICODE_CJK_SPACE:
02237 iCJK_SPACE++;
02238
break;
02239
case UNICODE_CR:
02240 iCR++;
02241
break;
02242
02243
02244
02245
02246
02247
case REVERSE_BYTE_ORDER_MARK:
02248 iRBOM++;
02249
break;
02250
case UNICODE_R_LF:
02251 iR_LF++;
02252
break;
02253
case UNICODE_R_TAB:
02254 iR_TAB++;
02255
break;
02256
case UNICODE_R_CR:
02257 iR_CR++;
02258
break;
02259
case UNICODE_R_SPACE:
02260 iR_SPACE++;
02261
break;
02262
02263
02264
02265
02266
case UNICODE_FFFF:
02267 iFFFF++;
02268
break;
02269
case UNICODE_NULL:
02270 iUNULL++;
02271
break;
02272
02273
02274
02275
02276
02277
02278
case ASCII_CRLF:
02279 iCRLF++;
02280
break;
02281 }
02282
02283
02284
02285
02286
02287 iHi =
HIBYTE(lpBuff[iTmp]);
02288 iLo =
LOBYTE(lpBuff[iTmp]);
02289
02290
02291
02292
02293
if ((iLo ==
'\r' && LastHi ==
'\n') ||
02294 (iLo ==
'\n' && LastHi ==
'\r'))
02295 {
02296 cWeird++;
02297 }
02298
02299 iNull += (iHi ? 0 : 1) + (iLo ? 0 : 1);
02300
02301 HiDiff +=
__max(iHi, LastHi) -
__min(LastHi, iHi);
02302 LoDiff +=
__max(iLo, LastLo) -
__min(LastLo, iLo);
02303
02304 LastLo = iLo;
02305 LastHi = iHi;
02306 }
02307
02308
02309
02310
02311
if ((iLo ==
'\r' && LastHi ==
'\n') ||
02312 (iLo ==
'\n' && LastHi ==
'\r'))
02313 {
02314 cWeird++;
02315 }
02316
02317
if (iHi ==
'\0')
02318 iNull--;
02319
if (iHi == 26)
02320 cWeird++;
02321
02322 iMaxTmp =
__min(256 *
sizeof(WCHAR),
Size);
02323
if (
NlsMbCodePageTag)
02324 {
02325
for (iTmp = 0; iTmp < iMaxTmp; iTmp++)
02326 {
02327
if (
NlsLeadByteInfo[lpb[iTmp]])
02328 {
02329 cLeadByte++;
02330 iTmp++;
02331 }
02332 }
02333 }
02334
02335
02336
02337
02338
if (LoDiff < 127 && HiDiff == 0)
02339 {
02340 iResult |= IS_TEXT_UNICODE_ASCII16;
02341 }
02342
02343
if (HiDiff && LoDiff == 0)
02344 {
02345 iResult |= IS_TEXT_UNICODE_REVERSE_ASCII16;
02346 }
02347
02348
02349
02350
02351
if (!
NlsMbCodePageTag || cLeadByte == 0 ||
02352 !ARGUMENT_PRESENT(Result) || !(*Result & IS_TEXT_UNICODE_DBCS_LEADBYTE))
02353 {
02354 iHi = 3;
02355 }
02356
else
02357 {
02358
02359
02360
02361
02362 iHi =
__min(256,
Size /
sizeof(WCHAR)) / 2;
02363
if (cLeadByte < (iHi - 1) / 3)
02364 {
02365 iHi = 3;
02366 }
02367
else if (cLeadByte < (2 * (iHi - 1)) / 3)
02368 {
02369 iHi = 2;
02370 }
02371
else
02372 {
02373 iHi = 1;
02374 }
02375 iResult |= IS_TEXT_UNICODE_DBCS_LEADBYTE;
02376 }
02377
02378
if (iHi * HiDiff < LoDiff)
02379 {
02380 iResult |= IS_TEXT_UNICODE_STATISTICS;
02381 }
02382
02383
if (iHi * LoDiff < HiDiff)
02384 {
02385 iResult |= IS_TEXT_UNICODE_REVERSE_STATISTICS;
02386 }
02387
02388
02389
02390
02391
02392
if (iCR + iLF + iTAB + iSPACE + iCJK_SPACE )
02393 {
02394 iResult |= IS_TEXT_UNICODE_CONTROLS;
02395 }
02396
02397
if (iR_LF + iR_CR + iR_TAB + iR_SPACE)
02398 {
02399 iResult |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
02400 }
02401
02402
02403
02404
02405
if ((iRBOM + iFFFF + iUNULL + iCRLF) != 0 ||
02406 (cWeird != 0 && cWeird >= iMaxTmp/40))
02407 {
02408 iResult |= IS_TEXT_UNICODE_ILLEGAL_CHARS;
02409 }
02410
02411
02412
02413
02414
if (
Size & 1)
02415 {
02416 iResult |= IS_TEXT_UNICODE_ODD_LENGTH;
02417 }
02418
02419
02420
02421
02422
if (iNull)
02423 {
02424 iResult |= IS_TEXT_UNICODE_NULL_BYTES;
02425 }
02426
02427
02428
02429
02430
if (*lpBuff ==
BYTE_ORDER_MARK)
02431 {
02432 iResult |= IS_TEXT_UNICODE_SIGNATURE;
02433 }
02434
else if (*lpBuff ==
REVERSE_BYTE_ORDER_MARK)
02435 {
02436 iResult |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
02437 }
02438
02439
02440
02441
02442
if (ARGUMENT_PRESENT(Result))
02443 {
02444 iResult &= *Result;
02445 *Result = iResult;
02446 }
02447
02448
02449
02450
02451
02452
02453
02454
02455
02456
02457
02458
02459
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470
02471
02472
02473
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488
02489
02490
if ((iResult & IS_TEXT_UNICODE_SIGNATURE) &&
02491 !(iResult & (IS_TEXT_UNICODE_NOT_UNICODE_MASK&(~IS_TEXT_UNICODE_DBCS_LEADBYTE))))
02492 {
02493
return (
TRUE);
02494 }
02495
02496
02497
02498
02499
if (iResult & IS_TEXT_UNICODE_REVERSE_MASK)
02500 {
02501
return (
FALSE);
02502 }
02503
02504
02505
02506
02507
if (!(iResult & IS_TEXT_UNICODE_NOT_UNICODE_MASK) &&
02508 ((iResult & IS_TEXT_UNICODE_NOT_ASCII_MASK) ||
02509 (iResult & IS_TEXT_UNICODE_UNICODE_MASK)))
02510 {
02511
return (
TRUE);
02512 }
02513
02514
return (
FALSE);
02515 }
02516
02517
02518
NTSTATUS
02519 RtlDnsHostNameToComputerName(
02520 OUT PUNICODE_STRING ComputerNameString,
02521 IN PUNICODE_STRING DnsHostNameString,
02522 IN BOOLEAN AllocateComputerNameString
02523 )
02524
02525
02526
02527
02528
02529
02530
02531
02532
02533
02534
02535
02536
02537
02538
02539
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594
02595
02596 {
02597
NTSTATUS Status;
02598
02599
02600 UNICODE_STRING LocalDnsHostNameString;
02601
02602 OEM_STRING OemString;
02603 ULONG ActualOemLength;
02604
CHAR OemStringBuffer[16];
02605
02606 ULONG i;
02607
02608
RTL_PAGED_CODE();
02609
02610
02611
02612
02613
02614 LocalDnsHostNameString = *DnsHostNameString;
02615
02616
for ( i=0; i<LocalDnsHostNameString.Length/
sizeof(WCHAR); i++ ) {
02617
02618
if ( LocalDnsHostNameString.Buffer[i] ==
L'.' ) {
02619 LocalDnsHostNameString.Length = (
USHORT)(i *
sizeof(WCHAR));
02620
break;
02621 }
02622 }
02623
02624
if ( LocalDnsHostNameString.Length <
sizeof(WCHAR) ) {
02625
return STATUS_INVALID_COMPUTER_NAME;
02626 }
02627
02628
02629
02630
02631
02632
Status =
RtlUpcaseUnicodeToOemN(
02633 OemStringBuffer,
02634
NETBIOS_NAME_LEN-1,
02635 &ActualOemLength,
02636 LocalDnsHostNameString.Buffer,
02637 LocalDnsHostNameString.Length );
02638
02639
if ( !
NT_SUCCESS(
Status) &&
Status != STATUS_BUFFER_OVERFLOW ) {
02640
return Status;
02641 }
02642
02643
02644
02645
02646
02647
02648 OemString.Buffer = OemStringBuffer;
02649 OemString.MaximumLength = OemString.Length = (
USHORT) ActualOemLength;
02650
02651
if ( !
RtlpDidUnicodeToOemWork( &OemString, &LocalDnsHostNameString )) {
02652
return STATUS_INVALID_COMPUTER_NAME;
02653 }
02654
02655
02656
02657
02658
02659
02660
Status =
RtlOemStringToUnicodeString(
02661 ComputerNameString,
02662 &OemString,
02663 AllocateComputerNameString );
02664
02665
if ( !
NT_SUCCESS(
Status) ) {
02666
return Status;
02667 }
02668
02669
return STATUS_SUCCESS;
02670 }