00573 {
00574
00575
NTSTATUS status;
00576 UNICODE_STRING registryPathName = PathName;
00577 UNICODE_STRING controllerBackupRegistryPathName;
00578 UNICODE_STRING peripheralBackupRegistryPathName;
00579 HANDLE controllerHandle =
NULL;
00580 HANDLE peripheralHandle =
NULL;
00581 PKEY_FULL_INFORMATION controllerTypeInfo =
NULL;
00582 PKEY_FULL_INFORMATION peripheralTypeInfo =
NULL;
00583 ULONG maxControllerNum;
00584 ULONG maxPeripheralNum;
00585 ULONG controllerNum;
00586 ULONG peripheralNum;
00587 WCHAR numBuffer[
UNICODE_NUM_LENGTH];
00588 UNICODE_STRING bufferUnicodeString;
00589 PKEY_VALUE_FULL_INFORMATION controllerValueInfo[
IoQueryDeviceMaxData];
00590 PKEY_VALUE_FULL_INFORMATION peripheralValueInfo[
IoQueryDeviceMaxData];
00591
00592
00593
00594
00595
00596
00597 bufferUnicodeString.MaximumLength =
UNICODE_NUM_LENGTH *
sizeof(WCHAR);
00598 bufferUnicodeString.Buffer = &numBuffer[0];
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 status =
RtlAppendUnicodeToString( ®istryPathName,
00613 L
"\\" );
00614
00615
if (
NT_SUCCESS( status )) {
00616
00617 status =
RtlAppendUnicodeToString( ®istryPathName,
00618 CmTypeString[*(QueryDescription->
ControllerType)] );
00619
00620 }
00621
00622
if (!
NT_SUCCESS( status )) {
00623
return status;
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
if (ARGUMENT_PRESENT( QueryDescription->
ControllerNumber )) {
00633
00634 controllerNum = *(QueryDescription->
ControllerNumber);
00635 maxControllerNum = controllerNum + 1;
00636
00637 }
else {
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647 status =
IopOpenRegistryKey( &controllerHandle,
00648 (HANDLE) NULL,
00649 ®istryPathName,
00650 KEY_READ,
00651 FALSE );
00652
00653
if (
NT_SUCCESS( status )) {
00654
00655 status =
IopGetRegistryKeyInformation( controllerHandle,
00656 &controllerTypeInfo );
00657
00658 ZwClose( controllerHandle );
00659 controllerHandle =
NULL;
00660 }
00661
00662
00663
00664
00665
00666
00667
00668
if (!
NT_SUCCESS( status )) {
00669
00670
return status;
00671
00672 }
00673
00674
00675
00676
00677
00678
00679 maxControllerNum = controllerTypeInfo->SubKeys;
00680 controllerNum = 0;
00681
00682
ExFreePool( controllerTypeInfo );
00683 controllerTypeInfo =
NULL;
00684 }
00685
00686
00687
00688
00689
00690
00691 controllerBackupRegistryPathName = registryPathName;
00692
00693
00694
00695
00696
00697
00698
00699
00700
for ( ; controllerNum < maxControllerNum; controllerNum++) {
00701
00702
00703
00704
00705
00706 registryPathName = controllerBackupRegistryPathName;
00707
00708
00709
00710
00711
00712
00713 bufferUnicodeString.Length = (
UNICODE_NUM_LENGTH-1) *
sizeof(WCHAR);
00714 status =
RtlIntegerToUnicodeString( controllerNum,
00715 10,
00716 &bufferUnicodeString );
00717
00718
if (
NT_SUCCESS( status )) {
00719
00720 status =
RtlAppendUnicodeToString( ®istryPathName,
00721 L
"\\" );
00722
00723
if (
NT_SUCCESS( status )) {
00724
00725 status =
RtlAppendUnicodeStringToString(
00726 ®istryPathName,
00727 &bufferUnicodeString );
00728
00729 }
00730 }
00731
00732
if (!
NT_SUCCESS( status )) {
00733
break;
00734 }
00735
00736
00737
00738
00739
00740
00741
00742 status =
IopOpenRegistryKey( &controllerHandle,
00743 (HANDLE) NULL,
00744 ®istryPathName,
00745 KEY_READ,
00746 FALSE );
00747
00748
if (
NT_SUCCESS( status )) {
00749
00750 status =
IopGetRegistryValues( controllerHandle,
00751 &controllerValueInfo[0] );
00752
00753 ZwClose( controllerHandle );
00754 controllerHandle =
NULL;
00755 }
00756
00757
00758
00759
00760
00761
00762
00763
if (!
NT_SUCCESS( status )) {
00764
continue;
00765 }
00766
00767
00768
00769
00770
00771
00772
00773
if (!ARGUMENT_PRESENT( (QueryDescription->
PeripheralType) )) {
00774
00775 status = QueryDescription->
CalloutRoutine(
00776 QueryDescription->
Context,
00777 ®istryPathName,
00778 *(QueryDescription->
BusType),
00779 BusNum,
00780 BusValueInfo,
00781 *(QueryDescription->
ControllerType),
00782 controllerNum,
00783 (PKEY_VALUE_FULL_INFORMATION *) controllerValueInfo,
00784 0,
00785 0,
00786 NULL );
00787
00788
goto IoQueryDeviceControllerLoop;
00789 }
00790
00791
00792
00793
00794
00795 status =
RtlAppendUnicodeToString( ®istryPathName,
00796 L
"\\" );
00797
00798
if (
NT_SUCCESS( status )) {
00799
00800 status =
RtlAppendUnicodeToString(
00801 ®istryPathName,
00802 CmTypeString[*(QueryDescription->
PeripheralType)] );
00803
00804 }
00805
00806
if (!
NT_SUCCESS( status )) {
00807
goto IoQueryDeviceControllerLoop;
00808 }
00809
00810
00811
00812
00813
00814
00815
00816
if (ARGUMENT_PRESENT( (QueryDescription->
PeripheralNumber) )) {
00817
00818 peripheralNum = *(QueryDescription->
PeripheralNumber);
00819 maxPeripheralNum = peripheralNum + 1;
00820
00821 }
else {
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831 status =
IopOpenRegistryKey( &peripheralHandle,
00832 (HANDLE) NULL,
00833 ®istryPathName,
00834 KEY_READ,
00835 FALSE );
00836
00837
if (
NT_SUCCESS( status )) {
00838
00839 status =
IopGetRegistryKeyInformation( peripheralHandle,
00840 &peripheralTypeInfo );
00841
00842 ZwClose( peripheralHandle );
00843 peripheralHandle =
NULL;
00844 }
00845
00846
00847
00848
00849
00850
00851
00852
if (!
NT_SUCCESS( status )) {
00853 status = STATUS_SUCCESS;
00854
goto IoQueryDeviceControllerLoop;
00855 }
00856
00857
00858
00859
00860
00861
00862 maxPeripheralNum = peripheralTypeInfo->SubKeys;
00863 peripheralNum = 0;
00864
00865
ExFreePool( peripheralTypeInfo );
00866 peripheralTypeInfo =
NULL;
00867 }
00868
00869
00870
00871
00872
00873
00874 peripheralBackupRegistryPathName = registryPathName;
00875
00876
00877
00878
00879
00880
00881
00882
00883
for ( ; peripheralNum < maxPeripheralNum; peripheralNum++) {
00884
00885
00886
00887
00888
00889 registryPathName = peripheralBackupRegistryPathName;
00890
00891
00892
00893
00894
00895
00896 bufferUnicodeString.Length =
00897 (
UNICODE_NUM_LENGTH-1) *
sizeof(WCHAR);
00898 status =
RtlIntegerToUnicodeString( peripheralNum,
00899 10,
00900 &bufferUnicodeString );
00901
00902
if (
NT_SUCCESS( status )) {
00903
00904 status =
RtlAppendUnicodeToString( ®istryPathName,
00905 L
"\\" );
00906
00907
if (
NT_SUCCESS( status )) {
00908
00909 status =
RtlAppendUnicodeStringToString(
00910 ®istryPathName,
00911 &bufferUnicodeString );
00912
00913 }
00914 }
00915
00916
if (!
NT_SUCCESS( status )) {
00917
break;
00918 }
00919
00920
00921
00922
00923
00924
00925
00926 status =
IopOpenRegistryKey( &peripheralHandle,
00927 (HANDLE) NULL,
00928 ®istryPathName,
00929 KEY_READ,
00930 FALSE );
00931
00932
if (
NT_SUCCESS( status )) {
00933
00934 status =
IopGetRegistryValues( peripheralHandle,
00935 &peripheralValueInfo[0] );
00936
00937 ZwClose( peripheralHandle );
00938 peripheralHandle =
NULL;
00939 }
00940
00941
00942
00943
00944
00945
00946
if (
NT_SUCCESS( status )) {
00947
00948 status = QueryDescription->
CalloutRoutine(
00949 QueryDescription->
Context,
00950 ®istryPathName,
00951 *(QueryDescription->
BusType),
00952 BusNum,
00953 BusValueInfo,
00954 *(QueryDescription->
ControllerType),
00955 controllerNum,
00956 (PKEY_VALUE_FULL_INFORMATION *) controllerValueInfo,
00957 *(QueryDescription->
PeripheralType),
00958 peripheralNum,
00959 (PKEY_VALUE_FULL_INFORMATION *) peripheralValueInfo );
00960
00961
00962
00963
00964
00965
if (peripheralValueInfo[0]) {
00966
ExFreePool( peripheralValueInfo[0] );
00967 peripheralValueInfo[0] =
NULL;
00968 }
00969
if (peripheralValueInfo[1]) {
00970
ExFreePool( peripheralValueInfo[1] );
00971 peripheralValueInfo[1] =
NULL;
00972 }
00973
if (peripheralValueInfo[2]) {
00974
ExFreePool( peripheralValueInfo[2] );
00975 peripheralValueInfo[2] =
NULL;
00976 }
00977
00978
00979
00980
00981
00982
00983
if (!
NT_SUCCESS( status )) {
00984
break;
00985 }
00986 }
00987
00988 }
00989
00990 IoQueryDeviceControllerLoop:
00991
00992
00993
00994
00995
00996
if (controllerValueInfo[0]) {
00997
ExFreePool( controllerValueInfo[0] );
00998 controllerValueInfo[0] =
NULL;
00999 }
01000
if (controllerValueInfo[1]) {
01001
ExFreePool( controllerValueInfo[1] );
01002 controllerValueInfo[1] =
NULL;
01003 }
01004
if (controllerValueInfo[2]) {
01005
ExFreePool( controllerValueInfo[2] );
01006 controllerValueInfo[2] =
NULL;
01007 }
01008
01009
if (!
NT_SUCCESS( status )) {
01010
break;
01011 }
01012
01013 }
01014
01015
01016
return( status );
01017 }