200分求一段C++转换成相应的delphi代码,谢谢! (200分)

  • 主题发起人 主题发起人 mmww
  • 开始时间 开始时间
M

mmww

Unregistered / Unconfirmed
GUEST, unregistred user!
我的邮箱:gold_net@163.com<br>这是一段不用vxd读取硬盘物理信息的C程序,哪位大侠能把它转换成delphi,急!谢谢!!<br><br>#include &lt;stdafx.h&gt;<br>//#include &lt;windows.h&gt;<br>//#include &lt;dos.h&gt;<br>//#include &lt;conio.h&gt;<br>#include &lt;stdio.h&gt;<br>//#include &lt;string.h&gt;<br><br>#define &nbsp;SENDIDLENGTH &nbsp;sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE<br>#define &nbsp;IDENTIFY_BUFFER_SIZE &nbsp;512<br>#define &nbsp;FILE_DEVICE_SCSI &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x0000001b<br>#define &nbsp;IOCTL_SCSI_MINIPORT_IDENTIFY &nbsp;((FILE_DEVICE_SCSI &lt;&lt; 16) + 0x0501)<br>#define &nbsp;IOCTL_SCSI_MINIPORT 0x0004D008 &nbsp;// &nbsp;see NTDDSCSI.H for definition<br>#define &nbsp;IDE_ATAPI_IDENTIFY &nbsp;0xA1 &nbsp;// &nbsp;Returns ID sector for ATAPI.<br>#define &nbsp;IDE_ATA_IDENTIFY &nbsp; &nbsp;0xEC &nbsp;// &nbsp;Returns ID sector for ATA.<br>#define &nbsp;DFP_RECEIVE_DRIVE_DATA &nbsp; 0x0007c088<br> typedef struct _IDSECTOR<br>{<br>&nbsp; &nbsp;USHORT &nbsp;wGenConfig;<br>&nbsp; &nbsp;USHORT &nbsp;wNumCyls;<br>&nbsp; &nbsp;USHORT &nbsp;wReserved;<br>&nbsp; &nbsp;USHORT &nbsp;wNumHeads;<br>&nbsp; &nbsp;USHORT &nbsp;wBytesPerTrack;<br>&nbsp; &nbsp;USHORT &nbsp;wBytesPerSector;<br>&nbsp; &nbsp;USHORT &nbsp;wSectorsPerTrack;<br>&nbsp; &nbsp;USHORT &nbsp;wVendorUnique[3];<br>&nbsp; &nbsp;CHAR &nbsp; &nbsp;sSerialNumber[20];<br>&nbsp; &nbsp;USHORT &nbsp;wBufferType;<br>&nbsp; &nbsp;USHORT &nbsp;wBufferSize;<br>&nbsp; &nbsp;USHORT &nbsp;wECCSize;<br>&nbsp; &nbsp;CHAR &nbsp; &nbsp;sFirmwareRev[8];<br>&nbsp; &nbsp;CHAR &nbsp; &nbsp;sModelNumber[40];<br>&nbsp; &nbsp;USHORT &nbsp;wMoreVendorUnique;<br>&nbsp; &nbsp;USHORT &nbsp;wDoubleWordIO;<br>&nbsp; &nbsp;USHORT &nbsp;wCapabilities;<br>&nbsp; &nbsp;USHORT &nbsp;wReserved1;<br>&nbsp; &nbsp;USHORT &nbsp;wPIOTiming;<br>&nbsp; &nbsp;USHORT &nbsp;wDMATiming;<br>&nbsp; &nbsp;USHORT &nbsp;wBS;<br>&nbsp; &nbsp;USHORT &nbsp;wNumCurrentCyls;<br>&nbsp; &nbsp;USHORT &nbsp;wNumCurrentHeads;<br>&nbsp; &nbsp;USHORT &nbsp;wNumCurrentSectorsPerTrack;<br>&nbsp; &nbsp;ULONG &nbsp; ulCurrentSectorCapacity;<br>&nbsp; &nbsp;USHORT &nbsp;wMultSectorStuff;<br>&nbsp; &nbsp;ULONG &nbsp; ulTotalAddressableSectors;<br>&nbsp; &nbsp;USHORT &nbsp;wSingleWordDMA;<br>&nbsp; &nbsp;USHORT &nbsp;wMultiWordDMA;<br>&nbsp; &nbsp;BYTE &nbsp; &nbsp;bReserved[128];<br>} IDSECTOR, *PIDSECTOR;<br><br>typedef struct _DRIVERSTATUS<br>{<br>&nbsp; &nbsp;BYTE &nbsp;bDriverError; &nbsp;// &nbsp;Error code from driver, or 0 if no error.<br>&nbsp; &nbsp;BYTE &nbsp;bIDEStatus; &nbsp; &nbsp;// &nbsp;Contents of IDE Error register.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;Only valid when bDriverError is SMART_IDE_ERROR.<br>&nbsp; &nbsp;BYTE &nbsp;bReserved[2]; &nbsp;// &nbsp;Reserved for future expansion.<br>&nbsp; &nbsp;DWORD &nbsp;dwReserved[2]; &nbsp;// &nbsp;Reserved for future expansion.<br>} DRIVERSTATUS, *PDRIVERSTATUS, *LPDRIVERSTATUS;<br><br> typedef struct _SENDCMDOUTPARAMS<br>{<br>&nbsp; &nbsp;DWORD &nbsp; &nbsp; &nbsp; &nbsp; cBufferSize; &nbsp; // &nbsp;Size of bBuffer in bytes<br>&nbsp; &nbsp;DRIVERSTATUS &nbsp;DriverStatus; &nbsp;// &nbsp;Driver status structure.<br>&nbsp; &nbsp;BYTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;bBuffer[1]; &nbsp; &nbsp;// &nbsp;Buffer of arbitrary length in which to store the data read from the &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // drive.<br>} SENDCMDOUTPARAMS, *PSENDCMDOUTPARAMS, *LPSENDCMDOUTPARAMS;<br>typedef struct _SRB_IO_CONTROL<br>{<br>&nbsp; &nbsp;ULONG HeaderLength;<br>&nbsp; &nbsp;UCHAR Signature[8];<br>&nbsp; &nbsp;ULONG Timeout;<br>&nbsp; &nbsp;ULONG ControlCode;<br>&nbsp; &nbsp;ULONG ReturnCode;<br>&nbsp; &nbsp;ULONG Length;<br>} SRB_IO_CONTROL, *PSRB_IO_CONTROL;<br>typedef struct _IDEREGS<br>{<br>&nbsp; &nbsp;BYTE bFeaturesReg; &nbsp; &nbsp; &nbsp; // Used for specifying SMART "commands".<br>&nbsp; &nbsp;BYTE bSectorCountReg; &nbsp; &nbsp;// IDE sector count register<br>&nbsp; &nbsp;BYTE bSectorNumberReg; &nbsp; // IDE sector number register<br>&nbsp; &nbsp;BYTE bCylLowReg; &nbsp; &nbsp; &nbsp; &nbsp; // IDE low order cylinder value<br>&nbsp; &nbsp;BYTE bCylHighReg; &nbsp; &nbsp; &nbsp; &nbsp;// IDE high order cylinder value<br>&nbsp; &nbsp;BYTE bDriveHeadReg; &nbsp; &nbsp; &nbsp;// IDE drive/head register<br>&nbsp; &nbsp;BYTE bCommandReg; &nbsp; &nbsp; &nbsp; &nbsp;// Actual IDE command.<br>&nbsp; &nbsp;BYTE bReserved; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// reserved for future use. &nbsp;Must be zero.<br>} IDEREGS, *PIDEREGS, *LPIDEREGS;<br><br>typedef struct _SENDCMDINPARAMS<br>{<br>&nbsp; &nbsp;DWORD &nbsp; &nbsp; cBufferSize; &nbsp; // &nbsp;Buffer size in bytes<br>&nbsp; &nbsp;IDEREGS &nbsp; irDriveRegs; &nbsp; // &nbsp;Structure with drive register values.<br>&nbsp; &nbsp;BYTE bDriveNumber; &nbsp; &nbsp; &nbsp; // &nbsp;Physical drive number to send <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp;command to (0,1,2,3).<br>&nbsp; &nbsp;BYTE bReserved[3]; &nbsp; &nbsp; &nbsp; // &nbsp;Reserved for future expansion.<br>&nbsp; &nbsp;DWORD &nbsp; &nbsp; dwReserved[4]; // &nbsp;For future use.<br>&nbsp; &nbsp;BYTE &nbsp; &nbsp; &nbsp;bBuffer[1]; &nbsp; &nbsp;// &nbsp;Input buffer.<br>} SENDCMDINPARAMS, *PSENDCMDINPARAMS, *LPSENDCMDINPARAMS;<br>typedef struct _GETVERSIONOUTPARAMS<br>{<br>&nbsp; &nbsp;BYTE bVersion; &nbsp; &nbsp; &nbsp;// Binary driver version.<br>&nbsp; &nbsp;BYTE bRevision; &nbsp; &nbsp; // Binary driver revision.<br>&nbsp; &nbsp;BYTE bReserved; &nbsp; &nbsp; // Not used.<br>&nbsp; &nbsp;BYTE bIDEDeviceMap; // Bit map of IDE devices.<br>&nbsp; &nbsp;DWORD fCapabilities; // Bit mask of driver capabilities.<br>&nbsp; &nbsp;DWORD dwReserved[4]; // For future use.<br>} GETVERSIONOUTPARAMS, *PGETVERSIONOUTPARAMS, *LPGETVERSIONOUTPARAMS;<br><br>WORD serial[256];<br>DWORD OldInterruptAddress;<br>DWORDLONG IDTR;<br>void _stdcall ReadIdeSerialNumber();<br>static unsigned int WaitHardDiskIde() <br>{<br> BYTE xx;<br><br>Waiting:<br> __asm{<br> mov dx, 0x1f7<br> in al, dx<br> cmp al, 0x80<br> jb Endwaiting<br> jmp Waiting<br> }<br>Endwaiting:<br> __asm{<br> mov xx, al<br> }<br><br> return xx; <br>} <br>void __declspec( naked ) InterruptProcess(void)//中断服务程序<br>{<br> int &nbsp; xx;<br>&nbsp; &nbsp; int &nbsp; i;<br> WORD temp;<br> //保存寄存器值<br>&nbsp; &nbsp; &nbsp;__asm<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; &nbsp; push ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; push ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; push edx<br>&nbsp; &nbsp; &nbsp; &nbsp; push esi<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; WaitHardDiskIde();//等待硬盘空闲状态<br>&nbsp; &nbsp; &nbsp; __asm{<br> mov dx, 0x1f6<br> mov al, 0xa0<br> out dx, al<br> }<br> xx = WaitHardDiskIde(); //若直接在Ring3级执行等待命令,会进入死循环<br> if ((xx&amp;0x50)!=0x50)<br> {<br> __asm{<br>&nbsp; &nbsp; &nbsp; &nbsp; pop esi<br>&nbsp; &nbsp; &nbsp; &nbsp; pop edx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop eax<br> iretd<br> }<br> }<br> <br> __asm{<br> mov dx, 0x1f6 //命令端口1f6,选择驱动器0<br> mov al, 0xa0<br> out dx, al<br> inc dx<br> mov al, 0xec<br> out dx, al //发送读驱动器参数命令<br> }<br><br> xx = WaitHardDiskIde(); <br> if ((xx&amp;0x58)!=0x58) <br>&nbsp; &nbsp; {<br> __asm{<br>&nbsp; &nbsp; &nbsp; &nbsp; pop esi<br>&nbsp; &nbsp; &nbsp; &nbsp; pop edx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop eax<br> iretd<br> }<br> }<br>&nbsp; &nbsp; //读取硬盘控制器的全部信息<br> for (i=0;i&lt;256;i++) {<br> __asm{<br> mov dx, 0x1f0<br> in ax, dx<br> mov temp, ax<br> }<br> serial = temp;<br> } <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> __asm{<br>&nbsp; &nbsp; &nbsp; &nbsp; pop esi<br>&nbsp; &nbsp; &nbsp; &nbsp; pop edx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop eax<br> iretd<br>&nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; &nbsp; &nbsp;//_asm iretd<br>}<br> <br>int Win9xHDSerialNumRead(WORD * buffer)<br>{ <br> int i; <br> for(i=0;i&lt;256;i++) <br> buffer=0;<br> ReadIdeSerialNumber();<br> for(i=0;i&lt;256;i++) <br> buffer=serial;<br> return 1;<br>}<br>void _stdcall ReadIdeSerialNumber()<br>{ &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; _asm<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; push eax &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; //获取修改的中断的中断描述符(中断门)地址<br>&nbsp; &nbsp; &nbsp; &nbsp; sidt IDTR <br>&nbsp; &nbsp; &nbsp; &nbsp; mov eax,dword ptr [IDTR+02h] &nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; add eax,3*08h+04h<br>&nbsp; &nbsp; &nbsp; &nbsp; cli<br>&nbsp; &nbsp; &nbsp; &nbsp; //保存原先的中断入口地址<br>&nbsp; &nbsp; &nbsp; &nbsp; push ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; mov ecx,dword ptr [eax]<br>&nbsp; &nbsp; &nbsp; &nbsp; mov cx,word ptr [eax-04h]<br>&nbsp; &nbsp; &nbsp; &nbsp; mov dword ptr OldInterruptAddress,ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; //设置修改的中断入口地址为新的中断处理程序入口地址<br>&nbsp; &nbsp; &nbsp; &nbsp; push ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; lea ebx,InterruptProcess <br>&nbsp; &nbsp; &nbsp; &nbsp; mov word ptr [eax-04h],bx<br>&nbsp; &nbsp; &nbsp; &nbsp; shr ebx,10h<br>&nbsp; &nbsp; &nbsp; &nbsp; mov word ptr [eax+02h],bx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ebx<br>&nbsp; &nbsp; &nbsp; &nbsp; //执行中断,转到Ring 0(类似CIH病毒原理)<br> int 3h<br>&nbsp; &nbsp; &nbsp; &nbsp; //恢复原先的中断入口地址<br>&nbsp; &nbsp; &nbsp; &nbsp; push ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; mov ecx,dword ptr OldInterruptAddress<br>&nbsp; &nbsp; &nbsp; &nbsp; mov word ptr [eax-04h],cx<br>&nbsp; &nbsp; &nbsp; &nbsp; shr ecx,10h<br>&nbsp; &nbsp; &nbsp; &nbsp; mov word ptr [eax+02h],cx<br>&nbsp; &nbsp; &nbsp; &nbsp; pop ecx<br>&nbsp; &nbsp; &nbsp; &nbsp; sti<br>&nbsp; &nbsp; &nbsp; &nbsp; pop eax<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>}<br><br>char *ConvertToString (WORD diskdata [256], int firstIndex, int lastIndex)<br>{<br>&nbsp; &nbsp;static char string [1024];<br>&nbsp; &nbsp;int index = 0;<br>&nbsp; &nbsp;int position = 0;<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;each integer has two characters stored in it backwards<br>&nbsp; &nbsp;for (index = firstIndex; index &lt;= lastIndex; index++)<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;get high byte for 1st character<br>&nbsp; &nbsp; &nbsp; string [position] = (char) (diskdata [index] / 256);<br>&nbsp; &nbsp; &nbsp; position++;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;get low byte for 2nd character<br>&nbsp; &nbsp; &nbsp; string [position] = (char) (diskdata [index] % 256);<br>&nbsp; &nbsp; &nbsp; position++;<br>&nbsp; &nbsp;}<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;end the string<br>&nbsp; &nbsp;string [position] = '/0';<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;cut off the trailing blanks<br>&nbsp; &nbsp;for (index = position - 1; index &gt; 0 &amp;&amp; ' ' == string [index]; index--)<br>&nbsp; &nbsp; &nbsp; string [index] = '/0';<br><br>&nbsp; &nbsp;return string;<br>}<br><br>char *ConvertToString2 (DWORD diskdata [256], int firstIndex, int lastIndex)<br>{<br>&nbsp; &nbsp;static char string [1024];<br>&nbsp; &nbsp;int index = 0;<br>&nbsp; &nbsp;int position = 0;<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;each integer has two characters stored in it backwards<br>&nbsp; &nbsp;for (index = firstIndex; index &lt;= lastIndex; index++)<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;get high byte for 1st character<br>&nbsp; &nbsp; &nbsp; string [position] = (char) (diskdata [index] / 256);<br>&nbsp; &nbsp; &nbsp; position++;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;get low byte for 2nd character<br>&nbsp; &nbsp; &nbsp; string [position] = (char) (diskdata [index] % 256);<br>&nbsp; &nbsp; &nbsp; position++;<br>&nbsp; &nbsp;}<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;end the string <br>&nbsp; &nbsp;string [position] = '/0';<br><br>&nbsp; &nbsp; &nbsp; // &nbsp;cut off the trailing blanks<br>&nbsp; &nbsp;for (index = position - 1; index &gt; 0 &amp;&amp; ' ' == string [index]; index--)<br>&nbsp; &nbsp; &nbsp; string [index] = '/0';<br><br>&nbsp; &nbsp;return string;<br>}<br><br>int WinNTHDSerialNumAsScsiRead (DWORD * buffer)<br>{<br><br>&nbsp; &nbsp; &nbsp; &nbsp;buffer[0]='/n';<br>&nbsp; &nbsp;int controller = 0;<br><br>&nbsp; // for (controller = 0; controller &lt; 2; controller++)<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; HANDLE hScsiDriveIOCTL = 0;<br>&nbsp; &nbsp; &nbsp; char &nbsp; driveName [256];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Try to get a handle to PhysicalDrive IOCTL, report failure<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;and exit if can't.<br>&nbsp; &nbsp; &nbsp; sprintf (driveName, "////.//Scsi%d:", controller);<br>// &nbsp; &nbsp; &nbsp;driveName="////.//Scsi0";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Windows NT, Windows 2000, any rights should do<br>&nbsp; &nbsp; &nbsp; hScsiDriveIOCTL = CreateFile (driveName,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ | GENERIC_WRITE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING, 0, NULL);<br>&nbsp; &nbsp; &nbsp; // if (hScsiDriveIOCTL == INVALID_HANDLE_VALUE)<br>&nbsp; &nbsp; &nbsp; // &nbsp; &nbsp;printf ("Unable to open SCSI controller %d, error code: 0x%lX/n",<br>&nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;controller, GetLastError ());<br><br>&nbsp; &nbsp; &nbsp; if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE)<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int drive = 0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (drive = 0; drive &lt; 2; drive++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SENDCMDINPARAMS *pin =<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DWORD dummy;<br>&nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset (buffer, 0, sizeof (buffer));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p -&gt; HeaderLength = sizeof (SRB_IO_CONTROL);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p -&gt; Timeout = 10000;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p -&gt; Length = SENDIDLENGTH;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p -&gt; ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; strncpy ((char *) p -&gt; Signature, "SCSIDISK", 8);<br>&nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pin -&gt; irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pin -&gt; bDriveNumber = drive;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof (SRB_IO_CONTROL) +<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof (SENDCMDINPARAMS) - 1,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;dummy, NULL))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SENDCMDOUTPARAMS *pOut =<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;IDSECTOR *pId = (IDSECTOR *) (pOut -&gt; bBuffer);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (pId -&gt; sModelNumber [0])<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int ijk = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USHORT *pIdSector = (USHORT *) pId;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (ijk = 0; ijk &lt; 256; ijk++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buffer[ijk] =pIdSector [ijk];<br>// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PrintIdeInfo (controller * 2 + drive, diskdata);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return 1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CloseHandle (hScsiDriveIOCTL);<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp;}<br><br>&nbsp; &nbsp;return -1;<br>}<br>BOOL DoIDENTIFY (HANDLE hPhysicalDriveIOCTL, PSENDCMDINPARAMS pSCIP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PDWORD lpcbBytesReturned)<br>{<br>&nbsp; &nbsp; &nbsp; // Set up data structures for IDENTIFY command.<br>&nbsp; &nbsp;pSCIP -&gt; cBufferSize = IDENTIFY_BUFFER_SIZE;<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bFeaturesReg = 0;<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bSectorCountReg = 1;<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bSectorNumberReg = 1;<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bCylLowReg = 0;<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bCylHighReg = 0;<br><br>&nbsp; &nbsp; &nbsp; // Compute the drive number.<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum &amp; 1) &lt;&lt; 4);<br><br>&nbsp; &nbsp; &nbsp; // The command can either be IDE identify or ATAPI identify.<br>&nbsp; &nbsp;pSCIP -&gt; irDriveRegs.bCommandReg = bIDCmd;<br>&nbsp; &nbsp;pSCIP -&gt; bDriveNumber = bDriveNum;<br>&nbsp; &nbsp;pSCIP -&gt; cBufferSize = IDENTIFY_BUFFER_SIZE;<br><br>&nbsp; &nbsp;return ( DeviceIoControl (hPhysicalDriveIOCTL, DFP_RECEIVE_DRIVE_DATA,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(LPVOID) pSCIP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof(SENDCMDINPARAMS) - 1,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(LPVOID) pSCOP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof(SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpcbBytesReturned, NULL) );<br>}<br><br>int WinNTHDSerialNumAsPhysicalRead (DWORD * buffer)<br>{<br>#define &nbsp;DFP_GET_VERSION &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x00074080<br>BYTE IdOutCmd [sizeof (SENDCMDOUTPARAMS) + IDENTIFY_BUFFER_SIZE - 1];<br><br>&nbsp; &nbsp;int done = FALSE;<br>&nbsp; &nbsp;int drive = 0;<br><br>&nbsp; // for (drive = 0; drive &lt; MAX_IDE_DRIVES; drive++)<br>&nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; HANDLE hPhysicalDriveIOCTL = 0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Try to get a handle to PhysicalDrive IOCTL, report failure<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;and exit if can't.<br>&nbsp; &nbsp; &nbsp; char driveName [256];<br><br>&nbsp; &nbsp; &nbsp; sprintf (driveName, "////.//PhysicalDrive%d", drive);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// &nbsp;Windows NT, Windows 2000, must have admin rights<br>&nbsp; &nbsp; &nbsp; hPhysicalDriveIOCTL = CreateFile (driveName,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GENERIC_READ | GENERIC_WRITE,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OPEN_EXISTING, 0, NULL);<br>&nbsp; &nbsp; &nbsp; // if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)<br>&nbsp; &nbsp; &nbsp; // &nbsp; &nbsp;printf ("Unable to open physical drive %d, error code: 0x%lX/n",<br>&nbsp; &nbsp; &nbsp; // &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;drive, GetLastError ());<br><br>&nbsp; &nbsp; &nbsp; if (hPhysicalDriveIOCTL != INVALID_HANDLE_VALUE)<br>&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GETVERSIONOUTPARAMS VersionParams;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cbBytesReturned = 0;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Get the version, etc of PhysicalDrive IOCTL<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;memset ((void*) &amp;VersionParams, 0, sizeof(VersionParams));<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( ! DeviceIoControl (hPhysicalDriveIOCTL, DFP_GET_VERSION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;VersionParams,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof(VersionParams),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;cbBytesReturned, NULL) )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{ &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // printf ("DFP_GET_VERSION failed for drive %d/n", i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // continue;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // If there is a IDE device at number "i" issue commands<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // to the device<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (VersionParams.bIDEDeviceMap &gt; 0)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BYTE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bIDCmd = 0; &nbsp; // IDE or ATAPI IDENTIFY cmd<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SENDCMDINPARAMS &nbsp;scip;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //SENDCMDOUTPARAMS OutCmd;<br><br> // Now, get the ID sector for all IDE devices in the system.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// If the device is ATAPI use the IDE_ATAPI_IDENTIFY command,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// otherwise use the IDE_ATA_IDENTIFY command<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bIDCmd = (VersionParams.bIDEDeviceMap &gt;&gt; drive &amp; 0x10) ? /<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IDE_ATAPI_IDENTIFY : IDE_ATA_IDENTIFY;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset (&amp;scip, 0, sizeof(scip));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; memset (IdOutCmd, 0, sizeof(IdOutCmd));<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ( DoIDENTIFY (hPhysicalDriveIOCTL, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;scip, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(PSENDCMDOUTPARAMS)&amp;IdOutCmd,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(BYTE) bIDCmd,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(BYTE) drive,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;cbBytesReturned))<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//DWORD diskdata [256];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;int ijk = 0;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;USHORT *pIdSector = (USHORT *)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((PSENDCMDOUTPARAMS) IdOutCmd) -&gt; bBuffer;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (ijk = 0; ijk &lt; 256; ijk++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;buffer[ijk] = pIdSector [ijk];<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // &nbsp; PrintIdeInfo (drive, diskdata);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;done = TRUE;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br> &nbsp; &nbsp;}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;CloseHandle (hPhysicalDriveIOCTL);<br>&nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp;}<br><br>&nbsp; &nbsp;return done;<br>}<br><br><br><br>LPCWSTR FAR HDSerialNumRead()<br>{ <br> char &nbsp;buffer[256];<br>&nbsp;buffer[0]='/n';<br>&nbsp; OSVERSIONINFO OSVersionInfo;<br>&nbsp; OSVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br>&nbsp; GetVersionEx( &amp;OSVersionInfo);<br>&nbsp; if (OSVersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT)<br>&nbsp; { &nbsp; <br> &nbsp;WORD m_wSeri[256];<br> &nbsp;Win9xHDSerialNumRead(m_wSeri); &nbsp;<br>&nbsp; &nbsp; &nbsp; strcpy (buffer, ConvertToString (m_wSeri, 10, 19));<br>&nbsp; }<br>&nbsp; else{<br>&nbsp; DWORD m_wStr[256];<br>&nbsp; <br>&nbsp; if ( ! WinNTHDSerialNumAsPhysicalRead(m_wStr)) WinNTHDSerialNumAsScsiRead;<br><br>&nbsp; strcpy (buffer, ConvertToString2 (m_wStr, 10, 19));<br>&nbsp; } ;<br>&nbsp; <br>&nbsp; return LPCWSTR(LPCSTR(buffer)); &nbsp;<br><br>}<br><br>int WEP(int nParam)<br>{<br>return 1;<br>}<br><br>
 
有高搞错,你没一点基础,搞什么飞机嘛<br><br><br>如果只是头文件转成pascal,我可以帮你转,我有工具,需要的朋友请联系<br>blueshrimp &nbsp;@yeah.net &nbsp;@sohu.com<br><br>好像playicq.com上有下载
 
talk a look,<br><br>我可没能力答,你的用户名跟我的一个朋友一样。。
 
to 天空还下着沙:<br>看来老兄是高手了,能否提供一段此功能的代码?先谢了,,
 
这么长,你烦不烦。不如做个Dll给Delphi调用,简单易行。
 
哦,DLL太容易被破解了,:)
 
原来是要用在注册码之类吧。<br>程序写得不好,没用,没人会破你。否则,做什么都白费。象征性就好了,还是集中精力写好程序,<br>用的人多,用的人多,总会有人付钱。否则就别写通用软件。<br>
 
现在我可以给你一个比较完满的解答:<br>你不需要修改代码,Delphi就可以用。你的代码其实是C,而不是C++,你只需要Delphi能够<br>使用一个函数对不对?Delphi可以之间链接C的obj,调用其函数。把你的代码存成.c(注意不<br>是.cpp),用C++ Builder编译。然后在delphi中将此函数声明为external,使用{$L来链接<br>你的Obj,OK,直接使用吧。
 
呵呵!取硬盘的物理信息 DELPHI 也可以做到啊!不过目前我还没有相关的代码,嘿嘿!
 
这代码在2000和XP可以正常工作?
 

Similar threads

I
回复
0
查看
728
import
I
I
回复
0
查看
681
import
I
I
回复
0
查看
814
import
I
I
回复
0
查看
751
import
I
后退
顶部