• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆-23  評(píng)論-73  文章-3  trackbacks-0

            #include <ntifs.h>
            #include <ntddscsi.h>
            #include <ntdddisk.h>
            #include <stdio.h>


             


            void PrintIdeInfo (int drive, ULONG diskdata [256]);


            char *ConvertToString (ULONG diskdata [256], int firstIndex, int lastIndex);


            BOOLEAN getDiskID( PDEVICE_OBJECT DeviceObject,ULONG drive );


             


            #define IDENTIFY_BUFFER_SIZE 512


            #define  IDE_ATAPI_IDENTIFY  0xA1  //  Returns ID sector for ATAPI.
            #define  IDE_ATA_IDENTIFY    0xEC  //  Returns ID sector for ATA.


            #define  DFP_RECEIVE_DRIVE_DATA   0x0007c088


             


            //輸出地址
            char IdOutCmd [sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];


             


            BOOLEAN getDiskID( PDEVICE_OBJECT DeviceObject,ULONG drive )
            /*
            * DeviceObject:物理PDO
            * drive:磁盤(pán)設(shè)備號(hào)
            */
            {
                PUCHAR buffer;
                PSRB_IO_CONTROL srbControl;
                ULONG         controlCode = 0;
                PIRP irp2;
                KEVENT event;
                IO_STATUS_BLOCK ioStatus;   
                NTSTATUS status;
                ULONG length;
             PSENDCMDINPARAMS cmdInParameters;
             
             SENDCMDINPARAMS  scip;


             memset (&scip, 0, sizeof(scip));
                memset (IdOutCmd, 0, sizeof(IdOutCmd));
             scip.cBufferSize = IDENTIFY_BUFFER_SIZE;
             scip.irDriveRegs.bFeaturesReg = 0;
             scip.irDriveRegs.bSectorCountReg = 1;
             scip.irDriveRegs.bSectorNumberReg = 1;
             scip.irDriveRegs.bCylLowReg = 0;
             scip.irDriveRegs.bCylHighReg = 0;


               // Compute the drive number.
             scip.irDriveRegs.bDriveHeadReg = 0xA0 | (((UCHAR)drive & 1) << 4);


               // The command can either be IDE identify or ATAPI identify.
             scip.irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
             scip.bDriveNumber = (UCHAR)drive;
             scip.cBufferSize = IDENTIFY_BUFFER_SIZE;


                //
                // 發(fā)DeviceIo,IdOutCmd接收結(jié)果
                //
                irp2 = IoBuildDeviceIoControlRequest(DFP_RECEIVE_DRIVE_DATA,
                                        DeviceObject,
                                        &scip,
                                        sizeof(SENDCMDINPARAMS) - 1,
                                        IdOutCmd,
                                        sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,
                                        FALSE,
                                        &event,
                                        &ioStatus);


                if (irp2 == NULL) {
                    DbgPrint("Build DeviceIoControl Error \n");
              return FALSE;
                }


                //
                // 向設(shè)備發(fā)Irp
                //


                status = IoCallDriver(DeviceObject, irp2);


                if (status == STATUS_PENDING) {
                    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
                    status = ioStatus.Status;
                }


                //
                // 發(fā)送成功打印信息
                //
               
                if (NT_SUCCESS(status)) {
                      ULONG diskdata [256];
                      int ijk = 0;
                      USHORT *pIdSector = (USHORT *)
                                         ((PSENDCMDOUTPARAMS) IdOutCmd) -> bBuffer;
                DbgPrint("successs in read disk id \n");   


                      for (ijk = 0; ijk < 256; ijk++)
                        diskdata [ijk] = pIdSector [ijk];
                   
                 //打印函數(shù)
                    PrintIdeInfo (drive, diskdata);
              //這要調(diào)用完成例程而不是釋放IRP,具體請(qǐng)看DDK文檔
              IoCompleteRequest( irp2,IO_NO_INCREMENT );
                    return TRUE;    
                     
                } else {
                   DbgPrint("get disk id error\n");
               
                }
               
                return FALSE;
            }


            void PrintIdeInfo (int drive, ULONG diskdata [256])
            {
             char string1 [1024];


             strcpy (string1, ConvertToString (diskdata, 10, 19));


             DbgPrint("Disk NO. %d DiskID %s \n",drive,ConvertToString (diskdata, 10, 19));
            }


            char *ConvertToString (ULONG diskdata [256], int firstIndex, int lastIndex)
            {
            /*
            * 功能如下:高低字節(jié)對(duì)調(diào),結(jié)尾補(bǔ)'\0'
            * string[10-19]遇空結(jié)尾
            */
               static char string [1024];
               int index = 0;
               int position = 0;


                  //  each integer has two characters stored in it backwards
               for (index = firstIndex; index <= lastIndex; index++)
               {
                     //  高字節(jié)
                  string [position] = (char) (diskdata [index] / 256);
                  position++;


                     //  低字節(jié)
                  string [position] = (char) (diskdata [index] % 256);
                  position++;
               }


                  //  結(jié)尾
               string [position] = '\0';
                 
               for (index = position - 1; index > 0 && ' ' == string [index]; index--)
                  string [index] = '\0';


               return string;
            }

            posted on 2008-04-19 13:05 ViskerWong 閱讀(1388) 評(píng)論(2)  編輯 收藏 引用

            評(píng)論:
            # re: 得到物理磁盤(pán)序列號(hào) 2008-04-19 16:57 | Lenuns
            驅(qū)動(dòng)的代碼,ms不完整啊  回復(fù)  更多評(píng)論
              
            # re: 得到物理磁盤(pán)序列號(hào) 2008-04-21 14:59 | ViskerWong
            想看完整的代碼可以找Diskid32的源代碼
            這只是一個(gè)庫(kù)  回復(fù)  更多評(píng)論
              

            只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            国内精品久久国产大陆| 久久夜色精品国产噜噜亚洲a| 久久亚洲AV永久无码精品| 亚洲va中文字幕无码久久不卡| 99精品久久精品一区二区| 国产精品欧美亚洲韩国日本久久 | 久久青青草原精品国产| 亚洲国产高清精品线久久| 国产99久久久久久免费看| 久久久国产一区二区三区| 国产精品成人精品久久久| 久久久久久免费一区二区三区| 91久久精品无码一区二区毛片| 99久久精品免费看国产免费| 久久香蕉一级毛片| 国产精品免费久久久久影院| 2020最新久久久视精品爱| 一级做a爰片久久毛片免费陪| 久久婷婷五月综合色高清| av无码久久久久不卡免费网站| 99久久精品九九亚洲精品| 91久久成人免费| 久久久精品久久久久影院| 亚洲精品乱码久久久久久中文字幕| 精品国产VA久久久久久久冰 | 国产精品美女久久久m| 99久久成人18免费网站| 久久精品亚洲乱码伦伦中文| 亚洲国产日韩欧美久久| 国产婷婷成人久久Av免费高清| 久久夜色撩人精品国产| 久久婷婷人人澡人人爽人人爱| 91久久福利国产成人精品| 久久无码国产| 成人久久精品一区二区三区| 精品多毛少妇人妻AV免费久久| 无码伊人66久久大杳蕉网站谷歌| yellow中文字幕久久网 | 97久久超碰国产精品2021| 理论片午午伦夜理片久久| 99久久免费国产精品热|