获取本机信息.docx

上传人:b****5 文档编号:3309307 上传时间:2022-11-21 格式:DOCX 页数:15 大小:18.23KB
下载 相关 举报
获取本机信息.docx_第1页
第1页 / 共15页
获取本机信息.docx_第2页
第2页 / 共15页
获取本机信息.docx_第3页
第3页 / 共15页
获取本机信息.docx_第4页
第4页 / 共15页
获取本机信息.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

获取本机信息.docx

《获取本机信息.docx》由会员分享,可在线阅读,更多相关《获取本机信息.docx(15页珍藏版)》请在冰豆网上搜索。

获取本机信息.docx

获取本机信息

#define  FILE_DEVICE_SCSI              0x0000001b

#define  IOCTL_SCSI_MINIPORT_IDENTIFY  ((FILE_DEVICE_SCSI<<16)+0x0501)

#define  IOCTL_SCSI_MINIPORT0x0004D008 

#define  IDENTIFY_BUFFER_SIZE  512

#define  SENDIDLENGTH  (sizeof(SENDCMDOUTPARAMS)+IDENTIFY_BUFFER_SIZE)

#define  IDE_ATAPI_IDENTIFY  0xA1  //  ReturnsIDsectorforATAPI.

#define  IDE_ATA_IDENTIFY    0xEC  //  ReturnsIDsectorforATA.

#define  DFP_RECEIVE_DRIVE_DATA   0x0007c088

 

typedefstruct_IDSECTOR

{

    USHORT  wGenConfig;

    USHORT  wNumCyls;

    USHORT  wReserved;

    USHORT  wNumHeads;

    USHORT  wBytesPerTrack;

    USHORT  wBytesPerSector;

    USHORT  wSectorsPerTrack;

    USHORT  wVendorUnique[3];

    CHAR    sSerialNumber[20];

    USHORT  wBufferType;

    USHORT  wBufferSize;

    USHORT  wECCSize;

    CHAR    sFirmwareRev[8];

    CHAR    sModelNumber[40];

    USHORT  wMoreVendorUnique;

    USHORT  wDoubleWordIO;

    USHORT  wCapabilities;

    USHORT  wReserved1;

    USHORT  wPIOTiming;

 

    USHORT  wDMATiming;

    USHORT  wBS;

    USHORT  wNumCurrentCyls;

    USHORT  wNumCurrentHeads;

    USHORT  wNumCurrentSectorsPerTrack;

    ULONG   ulCurrentSectorCapacity;

    USHORT  wMultSectorStuff;

    ULONG   ulTotalAddressableSectors;

    USHORT  wSingleWordDMA;

    USHORT  wMultiWordDMA;

    BYTE    bReserved[128];

}IDSECTOR,*PIDSECTOR;

 

 

typedefstruct_DRIVERSTATUS

{

    BYTE  bDriverError;  //  Errorcodefromdriver,or0ifnoerror.

    BYTE  bIDEStatus;    //  ContentsofIDEErrorregister.

    //  OnlyvalidwhenbDriverErrorisSMART_IDE_ERROR.

    BYTE  bReserved[2];  //  Reservedforfutureexpansion.

    DWORD  dwReserved[2];  //  Reservedforfutureexpansion.

}DRIVERSTATUS,*PDRIVERSTATUS,*LPDRIVERSTATUS;

 

typedefstruct_SENDCMDOUTPARAMS

{

    DWORD         cBufferSize;   //  SizeofbBufferinbytes

    DRIVERSTATUS  DriverStatus;  //  Driverstatusstructure.

    BYTE          bBuffer[1];    //  Bufferofarbitrarylengthinwhichtostorethedatareadfromthe                                                       //drive.

}SENDCMDOUTPARAMS,*PSENDCMDOUTPARAMS,*LPSENDCMDOUTPARAMS;

 

typedefstruct_SRB_IO_CONTROL

{

    ULONGHeaderLength;

    UCHARSignature[8];

    ULONGTimeout;

    ULONGControlCode;

    ULONGReturnCode;

    ULONGLength;

}SRB_IO_CONTROL,*PSRB_IO_CONTROL;

 

typedefstruct_IDEREGS

{

    BYTEbFeaturesReg;       //UsedforspecifyingSMART"commands".

    BYTEbSectorCountReg;    //IDEsectorcountregister

    BYTEbSectorNumberReg;   //IDEsectornumberregister

    BYTEbCylLowReg;         //IDElowordercylindervalue

    BYTEbCylHighReg;        //IDEhighordercylindervalue

    BYTEbDriveHeadReg;      //IDEdrive/headregister

    BYTEbCommandReg;        //ActualIDEcommand.

    BYTEbReserved;          //reservedforfutureuse.  Mustbezero.

}IDEREGS,*PIDEREGS,*LPIDEREGS;

 

typedefstruct_SENDCMDINPARAMS

{

    DWORD     cBufferSize;   //  Buffersizeinbytes

    IDEREGS   irDriveRegs;   //  Structurewithdriveregistervalues.

BYTEbDriveNumber;       //  Physicaldrivenumbertosend

 

//  commandto(0,1,2,3).

    BYTEbReserved[3];       //  Reservedforfutureexpansion.

    DWORD     dwReserved[4];//  Forfutureuse.

    BYTE      bBuffer[1];    //  Inputbuffer.

}SENDCMDINPARAMS,*PSENDCMDINPARAMS,*LPSENDCMDINPARAMS;

 

 

typedefstruct_GETVERSIONOUTPARAMS

{

    BYTEbVersion;      //Binarydriverversion.

    BYTEbRevision;     //Binarydriverrevision.

    BYTEbReserved;     //Notused.

    BYTEbIDEDeviceMap;//BitmapofIDEdevices.

    DWORDfCapabilities;//Bitmaskofdrivercapabilities.

    DWORDdwReserved[4];//Forfutureuse.

}GETVERSIONOUTPARAMS,*PGETVERSIONOUTPARAMS,*LPGETVERSIONOUTPARAMS;

 

//////////////////////////////////////////////////////////////////////

 

//结构定义

typedefstruct_UNICODE_STRING

{

    USHORT  Length;//长度

    USHORT  MaximumLength;//最大长度

    PWSTR  Buffer;//缓存指针

}UNICODE_STRING,*PUNICODE_STRING;

 

typedefstruct_OBJECT_ATTRIBUTES

{

    ULONGLength;//长度 18h

    HANDLERootDirectory;//  00000000

    PUNICODE_STRINGObjectName;//指向对象名的指针

    ULONGAttributes;//对象属性00000040h

    PVOIDSecurityDescriptor;        //PointstotypeSECURITY_DESCRIPTOR,0

    PVOIDSecurityQualityOfService;  //PointstotypeSECURITY_QUALITY_OF_SERVICE,0

}OBJECT_ATTRIBUTES;

typedefOBJECT_ATTRIBUTES*POBJECT_ATTRIBUTES;

 

 

//函数指针变量类型

typedefDWORD  (__stdcall*ZWOS)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES);

typedefDWORD  (__stdcall*ZWMV)(HANDLE,HANDLE,PVOID,ULONG,ULONG,PLARGE_INTEGER,PSIZE_T,DWORD,ULONG,ULONG);

typedefDWORD  (__stdcall*ZWUMV)(HANDLE,PVOID);

 

BOOLWinNTHDSerialNumAsScsiRead(BYTE*dwSerial,UINT*puSerialLen,UINTuMaxSerialLen)

{

    BOOLbInfoLoaded=FALSE;

   

    for(intiController=0;iController<2;++iController)

    {

        HANDLEhScsiDriveIOCTL=0;

        char   szDriveName[256];

       

        //  TrytogetahandletoPhysicalDriveIOCTL,reportfailure

        //  andexitifcan't.

        sprintf(szDriveName,"\\\\.\\Scsi%d:

",iController);

 

        //  WindowsNT,Windows2000,anyrightsshoulddo

        hScsiDriveIOCTL=CreateFile(szDriveName,

            GENERIC_READ|GENERIC_WRITE,

            FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,

            OPEN_EXISTING,0,NULL);

 

        //if(hScsiDriveIOCTL==INVALID_HANDLE_VALUE)

        //    printf("UnabletoopenSCSIcontroller%d,errorcode:

0x%lX\n",

        //            controller,GetLastError());

       

        if(hScsiDriveIOCTL!

=INVALID_HANDLE_VALUE)

        {

            intiDrive=0;

            for(iDrive=0;iDrive<2;++iDrive)

            {

                charszBuffer[sizeof(SRB_IO_CONTROL)+SENDIDLENGTH]={0};

 

                SRB_IO_CONTROL*p=(SRB_IO_CONTROL*)szBuffer;

                SENDCMDINPARAMS*pin=(SENDCMDINPARAMS*)(szBuffer+sizeof(SRB_IO_CONTROL));

                DWORDdwResult;

 

                p->HeaderLength=sizeof(SRB_IO_CONTROL);

p->Timeout=10000;

                p->Length=SENDIDLENGTH;

                p->ControlCode=IOCTL_SCSI_MINIPORT_IDENTIFY;

                strncpy((char*)p->Signature,"SCSIDISK",8);

 

                pin->irDriveRegs.bCommandReg=IDE_ATA_IDENTIFY;

                pin->bDriveNumber=iDrive;

               

                if(DeviceIoControl(hScsiDriveIOCTL,IOCTL_SCSI_MINIPORT,

                    szBuffer,

                    sizeof(SRB_IO_CONTROL)+sizeof(SENDCMDINPARAMS)-1,

                    szBuffer,

                    sizeof(SRB_IO_CONTROL)+SENDIDLENGTH,IT资讯之家 

                    &dwResult,NULL))

                {

                    SENDCMDOUTPARAMS*pOut=(SENDCMDOUTPARAMS*)(szBuffer+sizeof(SRB_IO_CONTROL));

                    IDSECTOR*pId=(IDSECTOR*)(pOut->bBuffer);

                    if(pId->sModelNumber[0])

                    {

                        if(*puSerialLen+20U<=uMaxSerialLen)

                        {

                            // 序列号

                            CopyMemory(dwSerial+*puSerialLen,((USHORT*)pId)+10,20);

                            //Cutoffthetrailingblanks

                            for(UINTi=20;i!

=0U&&''==dwSerial[*puSerialLen+i-1];--i)

                            {}

                            *puSerialLen+=i;

 

                            // 型号

                            CopyMemory(dwSerial+*puSerialLen,((USHORT*)pId)+27,40);

                            //Cutoffthetrailingblanks

                            for(i=40;i!

=0U&&''==dwSerial[*puSerialLen+i-1];--i)

                            {}

*puSerialLen+=i;

 

                            bInfoLoaded=TRUE;

                        }

                        else

                        {

                            :

:

CloseHandle(hScsiDriveIOCTL);

                            returnbInfoLoaded;

                        }

 

                    }

                }

            }

            :

:

CloseHandle(hScsiDriveIOCTL);

        }

    }

    returnbInfoLoaded;

}

 

 

BOOLDoIdentify(HANDLEhPhysicalDriveIOCTL,PSENDCMDINPARAMSpSCIP,

                 PSENDCMDOUTPARAMSpSCOP,BYTEbIDCmd,BYTEbDriveNum,

                 PDWORDlpcbBytesReturned)

{

    //SetupdatastructuresforIDENTIFYcommand.

    pSCIP->cBufferSize                  =IDENTIFY_BUFFER_SIZE;

    pSCIP->irDriveRegs.bFeaturesReg     =0;

    pSCIP->irDriveRegs.bSectorCountReg  =1;

    pSCIP->irDriveRegs.bSectorNumberReg=1;

    pSCIP->irDriveRegs.bCylLowReg       =0;

    pSCIP->irDriveRegs.bCylHighReg      =0;

   

    //calcthedrivenumber.

    pSCIP->irDriveRegs.bDriveHeadReg=0xA0|((bDriveNum&1)<<4);

 

    //ThecommandcaneitherbeIDEidentifyorATAPIidentify.

    pSCIP->irDriveRegs.bCommandReg=bIDCmd;

    pSCIP->bDriveNumber=bDriveNum;

    pSCIP->cBufferSize=IDENTIFY_BUFFER_SIZE;

   

    returnDeviceIoControl(hPhysicalDriveIOCTL,DFP_RECEIVE_DRIVE_DATA,

        (LPVOID)pSCIP,

        sizeof(SENDCMDINPARAMS)-1,

        (LPVOID)pSCOP,

        sizeof(SENDCMDOUTPARAMS)+IDENTIFY_BUFFER_SIZE-1,

        lpcbBytesReturned,NULL);

}

 

 

BOOLWinNTHDSerialNumAsPhysicalRead(BYTE*dwSerial,UINT*puSerialLen,UINTuMaxSerialLen)

{

#define  DFP_GET_VERSION          0x00074080

    BOOLbInfoLoaded=FALSE;

 

    for(UINTuDrive=0;uDrive<4;++uDrive)

    {

        HANDLEhPhysicalDriveIOCTL=0;

 

 

        //  TrytogetahandletoPhysicalDriveIOCTL,reportfailure

        //  andexitifcan't.

        charszDriveName[256];

        s

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 初中教育 > 学科竞赛

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1