blog

枪手亨利

博客园 首页 新随笔 联系 订阅 管理
©2005 黄友生。本文由原作者发布于MSN Space、CSDN。你可以保存、在非商业软件中使用、在非盈利性文章中引用本文中的部分或全部文字,但请注明作者及原文地址。要用于其它用途,请先联系作者(<A href="mailto:eien@eyou.com">eien@eyou.com</A>)。作者不保证本文完全正确无误、不对因本文中的理论或代码缺陷造成的损失负责。 <P><IFRAME id=ad_top name=ad_top align=left marginWidth=0 marginHeight=0 src="http://adv.pconline.com.cn/adpuba/show?id=pc.rjzx.kaifa.wenzhang.hzh.&media=html&pid=cs.pconline.rjzx.hzh." frameBorder=0 width=320 scrolling=no height=280></IFRAME>  本文中所有原理及思想均取自网络,有修改。其中获取硬盘序列号、获取CPU编号、获取BIOS编号的原始代码的著作权归各自作者所有。</P> <P><BR>  以下代码可以取得系统特征码(网卡MAC、硬盘序列号、CPU ID、BIOS编号)</P> <P clear=both>    BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码<BR>    UINT uSystemInfoLen = 0; // 在程序执行完毕后,此处存储取得的系统特征码的长度<BR><BR>    // 网卡 MAC 地址,注意: MAC 地址是可以在注册表中修改的<BR>    {<BR>        UINT uErrorCode = 0;<BR>        IP_ADAPTER_INFO iai;<BR>        ULONG uSize = 0;<BR>        DWORD dwResult = GetAdaptersInfo( &iai, &uSize );<BR>        if( dwResult == ERROR_BUFFER_OVERFLOW )<BR>        {<BR>            IP_ADAPTER_INFO* piai = ( IP_ADAPTER_INFO* )HeapAlloc( GetProcessHeap( ), 0, uSize );<BR>            if( piai != NULL )<BR>            {<BR>                dwResult = GetAdaptersInfo( piai, &uSize );<BR>                if( ERROR_SUCCESS == dwResult )<BR>                {<BR>                    IP_ADAPTER_INFO* piai2 = piai;<BR>                    while( piai2 != NULL && ( uSystemInfoLen + piai2->AddressLength ) < 4096U )<BR>                    {<BR>                        CopyMemory( szSystemInfo + uSystemInfoLen, piai2->Address, piai2->AddressLength );<BR>                        uSystemInfoLen += piai2->AddressLength;<BR>                        piai2 = piai2->Next;                        <BR>                    }<BR>                }<BR>                else<BR>                {<BR>                    uErrorCode = 0xF0000000U + dwResult;<BR>                }<BR>                VERIFY( HeapFree( GetProcessHeap( ), 0, piai ) );<BR>            }<BR>            else<BR>            {<BR>                return FALSE;<BR>            }<BR>        }<BR>        else<BR>        {<BR>            uErrorCode = 0xE0000000U + dwResult;<BR>        }<BR>        if( uErrorCode != 0U )<BR>        {<BR>            return FALSE;<BR>        }<BR>    }</P> <P>    // 硬盘序列号,注意:有的硬盘没有序列号<BR>    {<BR>        OSVERSIONINFO ovi = { 0 };<BR>        ovi.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );<BR>        GetVersionEx( &ovi );<BR>        <BR>        if( ovi.dwPlatformId != VER_PLATFORM_WIN32_NT )<BR>        {<BR>            // Only Windows 2000, Windows XP, Windows Server 2003...<BR>            return FALSE;<BR>        }<BR>        else<BR>        {<BR>            if( !WinNTHDSerialNumAsPhysicalRead( szSystemInfo, &uSystemInfoLen, 1024 ) )<BR>            {<BR>                WinNTHDSerialNumAsScsiRead( szSystemInfo, &uSystemInfoLen, 1024 );<BR>            }<BR>        }<BR>    }<BR><BR>    // CPU ID<BR>    {<BR>        BOOL bException = FALSE;<BR>        BYTE szCpu[16]  = { 0 };<BR>        UINT uCpuID     = 0U;</P> <P>        __try <BR>        {<BR>            _asm <BR>            {<BR>                mov eax, 0<BR>                cpuid<BR>                mov dword ptr szCpu[0], ebx<BR>                mov dword ptr szCpu[4], edx<BR>                mov dword ptr szCpu[8], ecx<BR>                mov eax, 1<BR>                cpuid<BR>                mov uCpuID, edx<BR>            }<BR>        }<BR>        __except( EXCEPTION_EXECUTE_HANDLER )<BR>        {<BR>            bException = TRUE;<BR>        }<BR>        <BR>        if( !bException )<BR>        {<BR>            CopyMemory( szSystemInfo + uSystemInfoLen, &uCpuID, sizeof( UINT ) );<BR>            uSystemInfoLen += sizeof( UINT );</P> <P>            uCpuID = strlen( ( char* )szCpu );<BR>            CopyMemory( szSystemInfo + uSystemInfoLen, szCpu, uCpuID );<BR>            uSystemInfoLen += uCpuID;<BR>        }<BR>    }<BR>    <BR>    // BIOS 编号,支持 AMI, AWARD, PHOENIX<BR>    {<BR>        SIZE_T ssize; </P> <P>        LARGE_INTEGER so; <BR>        so.LowPart=0x000f0000;<BR>        so.HighPart=0x00000000; <BR>        ssize=0xffff; <BR>        wchar_t strPH[30]=L\\device\\physicalmemory; <BR><BR>        DWORD ba=0;<BR><BR>        UNICODE_STRING struniph; <BR>        struniph.Buffer=strPH; <BR>        struniph.Length=0x2c; <BR>        struniph.MaximumLength =0x2e; <BR><BR>        OBJECT_ATTRIBUTES obj_ar; <BR>        obj_ar.Attributes =64;<BR>        obj_ar.Length =24;<BR>        obj_ar.ObjectName=&struniph;<BR>        obj_ar.RootDirectory=0; <BR>        obj_ar.SecurityDescriptor=0; <BR>        obj_ar.SecurityQualityOfService =0; <BR><BR>        HMODULE hinstLib = LoadLibrary("ntdll.dll"); <BR>        ZWOS ZWopenS=(ZWOS)GetProcAddress(hinstLib,"ZwOpenSection"); <BR>        ZWMV ZWmapV=(ZWMV)GetProcAddress(hinstLib,"ZwMapViewOfSection"); <BR>        ZWUMV ZWunmapV=(ZWUMV)GetProcAddress(hinstLib,"ZwUnmapViewOfSection"); <BR>        <BR>        //调用函数,对物理内存进行映射 <BR>        HANDLE hSection; <BR>        if( 0 == ZWopenS(&hSection,4,&obj_ar) && <BR>            0 == ZWmapV( <BR>            ( HANDLE )hSection,   //打开Section时得到的句柄 <BR>            ( HANDLE )0xFFFFFFFF, //将要映射进程的句柄, <BR>            &ba,                  //映射的基址 <BR>            0,<BR>            0xFFFF,               //分配的大小 <BR>            &so,                  //物理内存的地址 <BR>            &ssize,               //指向读取内存块大小的指针 <BR>            1,                    //子进程的可继承性设定 <BR>            0,                    //分配类型 <BR>            2                     //保护类型 <BR>            ) )<BR>        //执行后会在当前进程的空间开辟一段64k的空间,并把f000:0000到f000:ffff处的内容映射到这里 <BR>        //映射的基址由ba返回,如果映射不再有用,应该用ZwUnmapViewOfSection断开映射 <BR>        {<BR>            BYTE* pBiosSerial = ( BYTE* )ba;<BR>            UINT uBiosSerialLen = FindAwardBios( &pBiosSerial );<BR>            if( uBiosSerialLen == 0U )<BR>            {<BR>                uBiosSerialLen = FindAmiBios( &pBiosSerial );<BR>                if( uBiosSerialLen == 0U )<BR>                {<BR>                    uBiosSerialLen = FindPhoenixBios( &pBiosSerial );<BR>                }<BR>            }<BR>            if( uBiosSerialLen != 0U )<BR>            {<BR>                CopyMemory( szSystemInfo + uSystemInfoLen, pBiosSerial, uBiosSerialLen );<BR>                uSystemInfoLen += uBiosSerialLen;<BR>            }<BR>            ZWunmapV( ( HANDLE )0xFFFFFFFF, ( void* )ba );<BR>        }<BR>    }<BR>    // 完毕, 系统特征码已取得。<BR><BR><BR><BR>以下是其中用到的某些结构及函数的定义:</P> <P>#define  FILE_DEVICE_SCSI              0x0000001b<BR>#define  IOCTL_SCSI_MINIPORT_IDENTIFY  ( ( FILE_DEVICE_SCSI << 16 ) + 0x0501 )<BR><BR>#define  IOCTL_SCSI_MINIPORT 0x0004D008  //  see NTDDSCSI.H for definition<BR><BR>#define  IDENTIFY_BUFFER_SIZE  512<BR>#define  SENDIDLENGTH  ( sizeof( SENDCMDOUTPARAMS ) + IDENTIFY_BUFFER_SIZE )<BR><BR>#define  IDE_ATAPI_IDENTIFY  0xA1  //  Returns ID sector for ATAPI.<BR>#define  IDE_ATA_IDENTIFY    0xEC  //  Returns ID sector for ATA.<BR>#define  DFP_RECEIVE_DRIVE_DATA   0x0007c088<BR><BR>typedef struct _IDSECTOR<BR>{<BR>    USHORT  wGenConfig;<BR>    USHORT  wNumCyls;<BR>    USHORT  wReserved;<BR>    USHORT  wNumHeads;<BR>    USHORT  wBytesPerTrack;<BR>    USHORT  wBytesPerSector;<BR>    USHORT  wSectorsPerTrack;<BR>    USHORT  wVendorUnique[3];<BR>    CHAR    sSerialNumber[20];<BR>    USHORT  wBufferType;<BR>    USHORT  wBufferSize;<BR>    USHORT  wECCSize;<BR>    CHAR    sFirmwareRev[8];<BR>    CHAR    sModelNumber[40];<BR>    USHORT  wMoreVendorUnique;<BR>    USHORT  wDoubleWordIO;<BR>    USHORT  wCapabilities;<BR>    USHORT  wReserved1;<BR>    USHORT  wPIOTiming;<BR>    USHORT  wDMATiming;<BR>    USHORT  wBS;<BR>    USHORT  wNumCurrentCyls;<BR>    USHORT  wNumCurrentHeads;<BR>    USHORT  wNumCurrentSectorsPerTrack;<BR>    ULONG   ulCurrentSectorCapacity;<BR>    USHORT  wMultSectorStuff;<BR>    ULONG   ulTotalAddressableSectors;<BR>    USHORT  wSingleWordDMA;<BR>    USHORT  wMultiWordDMA;<BR>    BYTE    bReserved[128];<BR>} IDSECTOR, *PIDSECTOR;<BR><BR>typedef struct _DRIVERSTATUS<BR><BR>{<BR>    BYTE  bDriverError;  //  Error code from driver, or 0 if no error.<BR>    BYTE  bIDEStatus;    //  Contents of IDE Error register.<BR>    //  Only valid when bDriverError is SMART_IDE_ERROR.<BR>    BYTE  bReserved[2];  //  Reserved for future expansion.<BR>    DWORD  dwReserved[2];  //  Reserved for future expansion.<BR>} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;<BR><BR>typedef struct _SENDCMDOUTPARAMS<BR>{<BR>    DWORD         cBufferSize;   //  Size of bBuffer in bytes<BR>    DRIVERSTATUS  DriverStatus;  //  Driver status structure.<BR>    BYTE          bBuffer[1];    //  Buffer of arbitrary length in which to store the data read from the                                                       // drive.<BR>} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;<BR><BR>typedef struct _SRB_IO_CONTROL<BR>{<BR>    ULONG HeaderLength;<BR>    UCHAR Signature[8];<BR>    ULONG Timeout;<BR>    ULONG ControlCode;<BR>    ULONG ReturnCode;<BR>    ULONG Length;<BR>} SRB_IO_CONTROL, *PSRB_IO_CONTROL;<BR><BR>typedef struct _IDEREGS<BR>{<BR>    BYTE bFeaturesReg;       // Used for specifying SMART "commands".<BR>    BYTE bSectorCountReg;    // IDE sector count register<BR>    BYTE bSectorNumberReg;   // IDE sector number register<BR>    BYTE bCylLowReg;         // IDE low order cylinder value<BR>    BYTE bCylHighReg;        // IDE high order cylinder value<BR>    BYTE bDriveHeadReg;      // IDE drive/head register<BR>    BYTE bCommandReg;        // Actual IDE command.<BR>    BYTE bReserved;          // reserved for future use.  Must be zero.<BR>} IDEREGS, *PIDEREGS, *LPIDEREGS;<BR><BR>typedef struct _SENDCMDINPARAMS<BR>{<BR>    DWORD     cBufferSize;   //  Buffer size in bytes<BR>    IDEREGS   irDriveRegs;   //  Structure with drive register values.<BR>    BYTE bDriveNumber;       //  Physical drive number to send <BR>    //  command to (0,1,2,3).<BR>    BYTE bReserved[3];       //  Reserved for future expansion.<BR>    DWORD     dwReserved[4]; //  For future use.<BR>    BYTE      bBuffer[1];    //  Input buffer.<BR>} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;<BR><BR>typedef struct _GETVERSIONOUTPARAMS<BR>{<BR>    BYTE bVersion;      // Binary driver version.<BR>    BYTE bRevision;     // Binary driver revision.<BR>    BYTE bReserved;     // Not used.<BR>    BYTE bIDEDeviceMap; // Bit map of IDE devices.<BR>    DWORD fCapabilities; // Bit mask of driver capabilities.<BR>    DWORD dwReserved[4]; // For future use.<BR>} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;<BR><BR>//////////////////////////////////////////////////////////////////////<BR><BR>//结构定义 <BR>typedef struct _UNICODE_STRING <BR>{ <BR>    USHORT  Length;//长度 <BR>    USHORT  MaximumLength;//最大长度 <BR>    PWSTR  Buffer;//缓存指针 <BR>} UNICODE_STRING,*PUNICODE_STRING; <BR><BR>typedef struct _OBJECT_ATTRIBUTES <BR>{ <BR>    ULONG Length;//长度 18h <BR>    HANDLE RootDirectory;//  00000000 <BR>    PUNICODE_STRING ObjectName;//指向对象名的指针 <BR>    ULONG Attributes;//对象属性00000040h <BR>    PVOID SecurityDescriptor;        // Points to type SECURITY_DESCRIPTOR,0 <BR>    PVOID SecurityQualityOfService;  // Points to type SECURITY_QUALITY_OF_SERVICE,0 <BR>} OBJECT_ATTRIBUTES; <BR>typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES; <BR><BR>//函数指针变量类型<BR>typedef DWORD  (__stdcall *ZWOS )( PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES); <BR>typedef DWORD  (__stdcall *ZWMV )( HANDLE,HANDLE,PVOID,ULONG,ULONG,PLARGE_INTEGER,PSIZE_T,DWORD,ULONG,ULONG); <BR>typedef DWORD  (__stdcall *ZWUMV )( HANDLE,PVOID); <BR><BR>BOOL WinNTHDSerialNumAsScsiRead( BYTE* dwSerial, UINT* puSerialLen, UINT uMaxSerialLen )<BR>{<BR>    BOOL bInfoLoaded = FALSE;<BR>    <BR>    for( int iController = 0; iController < 2; ++ iController )<BR>    {<BR>        HANDLE hScsiDriveIOCTL = 0;<BR>        char   szDriveName[256];<BR>        <BR>        //  Try to get a handle to PhysicalDrive IOCTL, report failure<BR>        //  and exit if can't.<BR>        sprintf( szDriveName, "<A>\\\\.\\Scsi%d</A>:", iController );<BR><BR>        //  Windows NT, Windows 2000, any rights should do<BR>        hScsiDriveIOCTL = CreateFile( szDriveName,<BR>            GENERIC_READ | GENERIC_WRITE, <BR>            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<BR>            OPEN_EXISTING, 0, NULL);<BR><BR>        // if (hScsiDriveIOCTL == INVALID_HANDLE_VALUE)<BR>        //    printf ("Unable to open SCSI controller %d, error code: 0x%lX\n",<BR>        //            controller, GetLastError ());<BR>        <BR>        if( hScsiDriveIOCTL != INVALID_HANDLE_VALUE )<BR>        {<BR>            int iDrive = 0;<BR>            for( iDrive = 0; iDrive < 2; ++ iDrive )<BR>            {<BR>                char szBuffer[sizeof( SRB_IO_CONTROL ) + SENDIDLENGTH] = { 0 };<BR><BR>                SRB_IO_CONTROL* p = ( SRB_IO_CONTROL* )szBuffer;<BR>                SENDCMDINPARAMS* pin = ( SENDCMDINPARAMS* )( szBuffer + sizeof( SRB_IO_CONTROL ) );<BR>                DWORD dwResult;<BR><BR>                p->HeaderLength = sizeof( SRB_IO_CONTROL );<BR>                p->Timeout = 10000;<BR>                p->Length = SENDIDLENGTH;<BR>                p->ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;<BR>                strncpy( ( char* )p->Signature, "SCSIDISK", 8 );<BR><BR>                pin->irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;<BR>                pin->bDriveNumber = iDrive;<BR>                <BR>                if( DeviceIoControl( hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT, <BR>                    szBuffer,<BR>                    sizeof( SRB_IO_CONTROL ) + sizeof( SENDCMDINPARAMS ) - 1,<BR>                    szBuffer,<BR>                    sizeof( SRB_IO_CONTROL ) + SENDIDLENGTH,<BR>                    &dwResult, NULL ) )<BR>                {<BR>                    SENDCMDOUTPARAMS* pOut = ( SENDCMDOUTPARAMS* )( szBuffer + sizeof( SRB_IO_CONTROL ) );<BR>                    IDSECTOR* pId = ( IDSECTOR* )( pOut->bBuffer );<BR>                    if( pId->sModelNumber[0] )<BR>                    {<BR>                        if( * puSerialLen + 20U <= uMaxSerialLen )<BR>                        {<BR>                            // 序列号<BR>                            CopyMemory( dwSerial + * puSerialLen, ( ( USHORT* )pId ) + 10, 20 );<BR><BR>                            // Cut off the trailing blanks<BR>                            for( UINT i = 20; i != 0U && ' ' == dwSerial[* puSerialLen + i - 1]; -- i )<BR>                            {}<BR>                            * puSerialLen += i;<BR><BR>                            // 型号<BR>                            CopyMemory( dwSerial + * puSerialLen, ( ( USHORT* )pId ) + 27, 40 );<BR>                            // Cut off the trailing blanks<BR>                            for( i = 40; i != 0U && ' ' == dwSerial[* puSerialLen + i - 1]; -- i )<BR>                            {}<BR>                            * puSerialLen += i;<BR><BR>                            bInfoLoaded = TRUE;<BR>                        }<BR>                        else<BR>                        {<BR>                            ::CloseHandle( hScsiDriveIOCTL );<BR>                            return bInfoLoaded;<BR>                        }<BR>                    }<BR>                }<BR>            }<BR>            ::CloseHandle( hScsiDriveIOCTL );<BR>        }<BR>    }<BR>    return bInfoLoaded;<BR>}<BR><BR>BOOL DoIdentify( HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP,<BR>                 PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum,<BR>                 PDWORD lpcbBytesReturned )<BR>{<BR>    // Set up data structures for IDENTIFY command.<BR>    pSCIP->cBufferSize                  = IDENTIFY_BUFFER_SIZE;<BR>    pSCIP->irDriveRegs.bFeaturesReg     = 0;<BR>    pSCIP->irDriveRegs.bSectorCountReg  = 1;<BR>    pSCIP->irDriveRegs.bSectorNumberReg = 1;<BR>    pSCIP->irDriveRegs.bCylLowReg       = 0;<BR>    pSCIP->irDriveRegs.bCylHighReg      = 0;<BR>    <BR>    // calc the drive number.<BR>    pSCIP->irDriveRegs.bDriveHeadReg = 0xA0 | ( ( bDriveNum & 1 ) << 4 );<BR><BR>    // The command can either be IDE identify or ATAPI identify.<BR>    pSCIP->irDriveRegs.bCommandReg = bIDCmd;<BR>    pSCIP->bDriveNumber = bDriveNum;<BR>    pSCIP->cBufferSize = IDENTIFY_BUFFER_SIZE;<BR>    <BR>    return DeviceIoControl( hPhysicalDriveIOCTL, DFP_RECEIVE_DRIVE_DATA,<BR>        ( LPVOID ) pSCIP,<BR>        sizeof( SENDCMDINPARAMS ) - 1,<BR>        ( LPVOID ) pSCOP,<BR>        sizeof( SENDCMDOUTPARAMS ) + IDENTIFY_BUFFER_SIZE - 1,<BR>        lpcbBytesReturned, NULL );<BR>}<BR><BR>BOOL WinNTHDSerialNumAsPhysicalRead( BYTE* dwSerial, UINT* puSerialLen, UINT uMaxSerialLen )<BR>{<BR>#define  DFP_GET_VERSION          0x00074080<BR>    BOOL bInfoLoaded = FALSE;<BR><BR>    for( UINT uDrive = 0; uDrive < 4; ++ uDrive )<BR>    {<BR>        HANDLE hPhysicalDriveIOCTL = 0;<BR><BR>        //  Try to get a handle to PhysicalDrive IOCTL, report failure<BR>        //  and exit if can't.<BR>        char szDriveName [256];<BR>        sprintf( szDriveName, "<A>\\\\.\\PhysicalDrive%d</A>", uDrive );<BR><BR>        //  Windows NT, Windows 2000, must have admin rights<BR>        hPhysicalDriveIOCTL = CreateFile( szDriveName,<BR>            GENERIC_READ | GENERIC_WRITE, <BR>            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<BR>            OPEN_EXISTING, 0, NULL);<BR><BR>        if( hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE )<BR>        {<BR>            GETVERSIONOUTPARAMS VersionParams = { 0 };<BR>            DWORD               cbBytesReturned = 0;<BR><BR>            // Get the version, etc of PhysicalDrive IOCTL<BR>            if( DeviceIoControl( hPhysicalDriveIOCTL, DFP_GET_VERSION,<BR>                NULL, <BR>                0,<BR>                &VersionParams,<BR>                sizeof( GETVERSIONOUTPARAMS ),<BR>                &cbBytesReturned, NULL ) )<BR>            {<BR>                // If there is a IDE device at number "i" issue commands<BR>                // to the device<BR>                if( VersionParams.bIDEDeviceMap != 0 )<BR>                {<BR>                    BYTE             bIDCmd = 0;   // IDE or ATAPI IDENTIFY cmd<BR>                    SENDCMDINPARAMS  scip = { 0 };<BR><BR>                    // Now, get the ID sector for all IDE devices in the system.<BR>                    // If the device is ATAPI use the IDE_ATAPI_IDENTIFY command,<BR>                    // otherwise use the IDE_ATA_IDENTIFY command<BR>                    bIDCmd = ( VersionParams.bIDEDeviceMap >> uDrive & 0x10 ) ? IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;<BR>                    BYTE IdOutCmd[sizeof( SENDCMDOUTPARAMS ) + IDENTIFY_BUFFER_SIZE - 1] = { 0 };<BR><BR>                    if( DoIdentify( hPhysicalDriveIOCTL, <BR>                        &scip, <BR>                        ( PSENDCMDOUTPARAMS )&IdOutCmd, <BR>                        ( BYTE )bIDCmd,<BR>                        ( BYTE )uDrive,<BR>                        &cbBytesReturned ) )<BR>                    {<BR>                        if( * puSerialLen + 20U <= uMaxSerialLen )<BR>                        {<BR>                            CopyMemory( dwSerial + * puSerialLen, ( ( USHORT* )( ( ( PSENDCMDOUTPARAMS )IdOutCmd )->bBuffer ) ) + 10, 20 );  // 序列号<BR><BR>                            // Cut off the trailing blanks<BR>                            for( UINT i = 20; i != 0U && ' ' == dwSerial[* puSerialLen + i - 1]; -- i )  {}<BR>                            * puSerialLen += i;<BR><BR>                            CopyMemory( dwSerial + * puSerialLen, ( ( USHORT* )( ( ( PSENDCMDOUTPARAMS )IdOutCmd )->bBuffer ) ) + 27, 40 ); // 型号<BR><BR>                            // Cut off the trailing blanks<BR>                            for( i = 40; i != 0U && ' ' == dwSerial[* puSerialLen + i - 1]; -- i )  {}<BR>                            * puSerialLen += i;<BR><BR>                            bInfoLoaded = TRUE;<BR>                        }<BR>                        else<BR>                        {<BR>                            ::CloseHandle( hPhysicalDriveIOCTL );<BR>                            return bInfoLoaded;<BR>                        }<BR>                    }<BR>                }<BR>            }<BR>            CloseHandle( hPhysicalDriveIOCTL );<BR>        }<BR>    }<BR>    return bInfoLoaded;<BR>}<BR><BR>UINT FindAwardBios( BYTE** ppBiosAddr )<BR>{<BR>    BYTE* pBiosAddr = * ppBiosAddr + 0xEC71;<BR><BR>    BYTE szBiosData[128];<BR>    CopyMemory( szBiosData, pBiosAddr, 127 );<BR>    szBiosData[127] = 0;<BR>    <BR>    int iLen = lstrlen( ( char* )szBiosData );<BR>    if( iLen > 0 && iLen < 128 )<BR>    {<BR>        //AWard:         07/08/2002-i845G-ITE8712-JF69VD0CC-00 <BR>        //Phoenix-Award: 03/12/2002-sis645-p4s333<BR>        if( szBiosData[2] == '/' && szBiosData[5] == '/' )<BR>        {<BR>            BYTE* p = szBiosData;<BR>            while( * p )<BR>            {<BR>                if( * p < ' ' || * p >= 127 )<BR>                {<BR>                    break;<BR>                }<BR>                ++ p;<BR>            }<BR>            if( * p == 0 )<BR>            {<BR>                * ppBiosAddr = pBiosAddr;<BR>                return ( UINT )iLen;<BR>            }<BR>        }<BR>    }<BR>    return 0;<BR>}<BR><BR>UINT FindAmiBios( BYTE** ppBiosAddr )<BR>{<BR>    BYTE* pBiosAddr = * ppBiosAddr + 0xF478;<BR>    <BR>    BYTE szBiosData[128];<BR>    CopyMemory( szBiosData, pBiosAddr, 127 );<BR>    szBiosData[127] = 0;<BR>    <BR>    int iLen = lstrlen( ( char* )szBiosData );<BR>    if( iLen > 0 && iLen < 128 )<BR>    {<BR>        // Example: "AMI: 51-2300-000000-00101111-030199-"<BR>        if( szBiosData[2] == '-' && szBiosData[7] == '-' )<BR>        {<BR>            BYTE* p = szBiosData;<BR>            while( * p )<BR>            {<BR>                if( * p < ' ' || * p >= 127 )<BR>                {<BR>                    break;<BR>                }<BR>                ++ p;<BR>            }<BR>            if( * p == 0 )<BR>            {<BR>                * ppBiosAddr = pBiosAddr;<BR>                return ( UINT )iLen;<BR>            }<BR>        }<BR>    }<BR>    return 0;<BR>}<BR><BR>UINT FindPhoenixBios( BYTE** ppBiosAddr )<BR>{<BR>    UINT uOffset[3] = { 0x6577, 0x7196, 0x7550 };<BR>    for( UINT i = 0; i < 3; ++ i )<BR>    {<BR>        BYTE* pBiosAddr = * ppBiosAddr + uOffset[i];<BR><BR>        BYTE szBiosData[128];<BR>        CopyMemory( szBiosData, pBiosAddr, 127 );<BR>        szBiosData[127] = 0;<BR><BR>        int iLen = lstrlen( ( char* )szBiosData );<BR>        if( iLen > 0 && iLen < 128 )<BR>        {<BR>            // Example: Phoenix "NITELT0.86B.0044.P11.9910111055"<BR>            if( szBiosData[7] == '.' && szBiosData[11] == '.' )<BR>            {<BR>                BYTE* p = szBiosData;<BR>                while( * p )<BR>                {<BR>                    if( * p < ' ' || * p >= 127 )<BR>                    {<BR>                        break;<BR>                    }<BR>                    ++ p;<BR>                }<BR>                if( * p == 0 )<BR>                {<BR>                    * ppBiosAddr = pBiosAddr;<BR>                    return ( UINT )iLen;<BR>                }<BR>            }<BR>        }<BR>    }<BR>    return 0;<BR>}<BR><BR><A href="http://www.pconline.com.cn/pcedu/empolder/gj/vc/0508/691365.html">http://www.pconline.com.cn/pcedu/empolder/gj/vc/0508/691365.html</A></P>
posted on 2005-11-05 09:21  henry  阅读(1011)  评论(0编辑  收藏  举报