Get the hard disk serial number directly from Ring3

zhaozj2021-02-16  61

'********************************************************** *************** 'Original: BARDO' Source: "Oriental Hot News" Website: www.easthot.net '************ *********************************************************** * '(If you need to reprint, please don't delete the above information, otherwise it is considered to be infringement!)' ************************************** ****************************************

What is the use of this? You can generate registration code related to hardware. Control software is not reused! So, many people think that VB is not realized. Naturally, the method is not found, it must be realized. However, thanks to WWW, we can find the source code of the VC above it, Delphi's source code. But VB is not seen. To this end, I decided to change the source code of the VC to VB. The following is:

'VC Original Description Part (when released, please pay attention to the way to use an annotation, please do not delete the way to infringe, thank you!)' ********************* *********************************************************** * 'Normally, we monitor the IDE port by = & hec command. Get hard disk information.' Under normal circumstances, we write a VXD or Driver to complete. But now, through the MS's Smart interface, 'We can directly Ring3 calls API Deviceiocontrol () to get the hard disk information. Below is my routine: 'Additionally, there are also compiled versions for everyone to use. Welcome download.' / * 'hdid.cpp'written by lu Lin 'http://lu0.126.com'2000.11.3'--- *************************************** ******************************************* VB program: BARDO 'I originally wanted to write a serial number of only the disc. But considering everyone's easy learning. Still translating the original code '. If you need a single program that only checks a serial number of a primary hard drive, please go to this site to download. '' Website: Oriental Hot News: http://www.eaSt.net 'Mail: Sales@eaStht.Net'2003.01.23' *************************** *********************************************************** *** Option Explicit 'The following lines are required and difficult to make structure replication. There are arrays in the structure. So, there is no way to displays OPTION Base 0

PRIVATE CONST DFP_GET_VERSION = & H74080PRIVATE CONST DFP_SEND_DRIVE_COMMAND = & H7C084Private const DFP_RECEIVE_DRIVE_DATA = & H7C088

'#Pragma pack (1) Private Type TGETVERSIONOUTPARAMS' {bVersion As Byte 'Binary driver version. BRevision As Byte' Binary driver revision. BReserved As Byte 'Not used. BIDEDeviceMap As Byte' Bit map of IDE devices. FCapabilities As Long 'Bit mask of driver capabilities. dwReserved (4) As Long 'for future use.End TypePrivate Type TIDEREGS bFeaturesReg As Byte' Used for specifying SMART "commands". bSectorCountReg As Byte 'IDE sector count register bSectorNumberReg As Byte' IDE sector number register bCylLowReg As byte 'IDE low order cylinder value bCylHighReg As byte' IDE high order cylinder value bDriveHeadReg As byte 'IDE drive / head register bCommandReg As byte' Actual IDE command. bReserved As byte 'reserved for future use. Must be zero.End Type

Private Type TSENDCMDINPARAMS cBufferSize As Long 'Buffer size in bytes irDriveRegs As TIDEREGS' Structure with drive register values. BDriveNumber As Byte 'Physical drive number to send' command to (0,1,2,3). BReserved (2) As Byte ' Reserved for Future Expansion. Dwreserved (3) As long 'forfuture us.' 'Byte Bbuffer (1)' Input Buffer.end Type

Private Type TDRIVERSTATUS bDriverError As Byte 'Error code from driver,' or 0 if no error. BIDEStatus As Byte 'Contents of IDE Error register.' Only valid when bDriverError 'is SMART_IDE_ERROR. BReserved (1) As Byte' Reserved for future expansion. DWRESERVED (1) As long 'reserved for Future Expansion.end Type

Private Type TSENDCMDOUTPARAMS cBufferSize As Long 'Size of bBuffer in bytes DRIVERSTATUS As TDRIVERSTATUS' Driver status structure. BBuffer (511) As Byte 'Buffer of arbitrary length' in which to store the data read from the drive.End Type 'following structure To copy data from another structure, it must be the number of bytes and the VC's full consistent 'and we cannot use compatible variables, but we still use compatible variables, Integer, because this' type in this structure The variable program is not used, if you want to use, it is recommended to change to the Byte type. Because VB is not Ushort

Private Type TIDSECTOR wGenConfig As Integer wNumCyls As Integer wReserved As Integer wNumHeads As Integer wBytesPerTrack As Integer wBytesPerSector As Integer wSectorsPerTrack As Integer wVendorUnique (2) As Integer sSerialNumber (19) As Byte wBufferType As Integer wBufferSize As Integer wECCSize As Integer sFirmwareRev (7) As byte sModelNumber (39) As byte wMoreVendorUnique As Integer wDoubleWordIO As Integer wCapabilities As Integer wReserved1 As Integer wPIOTiming As Integer wDMATiming As Integer wBS As Integer wNumCurrentCyls As Integer wNumCurrentHeads As Integer wNumCurrentSectorsPerTrack As Integer ulCurrentSectorCapacity (3) As byte 'here only with byte, because VB is no LONG unsigned variable wMultSectorStuff as Integer ulTotalAddressableSectors (3) as byte 'here only by byte, because there is no VB unsigned variable LONG wSingleWordDMA as Integer wMultiWordDMA as Integer bReserved (127) as ByteEnd type

'/ * Global Vars' --- * / Private Vers As TgetversionOutParamsprivate In_Data As Tsendcmdinparamsprivate Out_Data As Tsendcmdoutparamsprivate H AS Longprivate I As LongPrivate J AS Byte

Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128End TypePrivate Declare Function GetVersionEx Lib "kernel32" Alias ​​"GetVersionExA" _ (LpVersionInformation As OSVERSIONINFO) As Long

Private const ver_platform_win32s = 0Private const ver_platform_win32_windows = 1Private const ver_platform_win32_nt = 2

Private Declare Function CreateFile Lib "kernel32" _ Alias ​​"CreateFileA" (ByVal lpFileName As String, _ ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _ ByVal lpSecurityAttributes As Long, _ ByVal dwCreationDisposition As Long, _ ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As long) _ as long

Private Const CREATE_NEW = 1Private Const GENERIC_READ = & H80000000Private Const GENERIC_WRITE = & H40000000Private Const OPEN_EXISTING = 3Private Const FILE_SHARE_READ = & H1Private Const FILE_SHARE_WRITE = & H2

Private Type Overlapped Internal As Long InternalHigh As Long Offset As Long Offseth AS Long HEVENT AS LONGEND TYPE

Private Declare Function DeviceIoControl Lib "kernel32" _ (ByVal hDevice As Long, ByVal dwIoControlCode As Long, _ lpInBuffer As Any, ByVal nInBufferSize As Long, _ lpOutBuffer As Any, ByVal nOutBufferSize As Long, _ lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As Long

Private Declare Function CloseHandle Lib "Kernel32" (Byval Hobject As Long) AS Long

Private Declare Sub CopyMemory LIB "kernel32" Alias ​​"RTLMoveMemory" (_ hpvdest as any, hpvsource as any, byval cbcopy as long) private sub copyright () 'vc original copyright code (, please pay attention to the way to use annotations, please Don't delete the way to infringe, thank you!) '*********************************************************** ******************************************** 'CERR << Endl << "HDD Identifier v1.0 for WIN95 / 98 / ME / NT / 2000. Written By Lu Lin "<< endl 'cerr <<" for more information, please visit inside programming: http:' lu0.126.com "<< Endl 'CERR <<" 2000.11 .3 "<< Endl << endl '************************************************** ************************************* DIM STRMSG AS STRINGSTRMSG = STRMSG & "Call directly from Ring3 API Deviceiocontrol () To get the hard disk information "strmsg = strmsg & vbrlf &" VC source is as follows: "strmsg = strmsg & vbcrlf &" **************** ****************************************** "Strmsg = strmsg & vbcrlf &" HDD Identifier V1.0 for WIN95 / 98 / ME / NT / 2000. Written by Lu Lin "strmsg = strmsg & vbcrf &" for more information, please visits inside program "strmsg = strmsg & vbcrlf & "2000.11.3" ST RMSG = strmsg & vbcrf & "************************************************** **************** "strmsg = strmsg & vbrlf &" VB program: BARDO "strmsg = strmsg & vbcrlf &" website: Oriental Hot News: http://www.eashot .NET "strmsg = strmsg & vbcrlf &" Mail: Sales@eastHot.Net "strmsg = strmsg & vbcrlf &" 2003.01.23 "MSGBOX STRMSGEND SUB

SUB ChangeByte, USCSTRING () AS BYTE, USCSTRSIZE, USCSTRSIZE TEMP AS STRING for I = 0 TO USCSTRSIZE - 1 Step 2 Temp = Szstring (i) Szstring (i) = szstring (i 1) szstring i 1) = Temp next Iend Subprivate function hdid9x () AS String

'We Start in 95/98 / meh = CreateFile ("//./ SmartVSD", 0, 0, 0, Create_New, 0, 0) IF H = 0 THEN HDID9X = "Open SmartVsd.vxd Failed" EXIT FUNCTIONEND IF

Dim olp As OVERLAPPEDDim lRet As LonglRet = DeviceIoControl (h, DFP_GET_VERSION, ByVal 0 &, 0, vers, Len (vers), ByVal i, olp) If lRet = 0 Then hdid9x = "DeviceIoControl failed: DFP_GET_VERSION" CloseHandle (h) Exit FunctionEnd IF

'Ide Identify Command Not Supported, Failsif (Vers.Fcapabilities and 1) <> 1 THEN HDID9X = "Error: IDE Identify Command Not Supported." CloseHandle (H) exit functionendiff

'Display IDE DRIVE NUMBER Detectedddim Spreoutstr AS StringspreoutStr = Detectide (VERS.BidedEviceMap) HDID9X = SpreoutStr

'Identify the IDE drivesFor j = 0 To 3 Dim phdinfo As TIDSECTOR Dim s (40) As Byte If (j And 1) = 1 Then in_data.irDriveRegs.bDriveHeadReg = & HB0 Else in_data.irDriveRegs.bDriveHeadReg = & HA0 End If If (vers .fcapabilities and (16 / (2 ^ j))) = (16 / (2 ^ j)) THEN 'We don't detect a atapi device. hdid9x = "drive" & cstr (j 1) & "is A ATAPI device, we do not detect it "Else in_data.irDriveRegs.bCommandReg = & HEC in_data.bDriveNumber = j in_data.irDriveRegs.bSectorCountReg = 1 in_data.irDriveRegs.bSectorNumberReg = 1 in_data.cBufferSize = 512 lRet = DeviceIoControl (h, DFP_RECEIVE_DRIVE_DATA, IN_DATA, LEN (In_Data), OUT_DATA, LEN (OUT_DATA), BYVAL I, OLP) IF LRET = 0 THEN HDID9X = "Deviceiocontrol Failed: DFP_RECEIVE_DRIVE_DATA" CloseHandle (H) EXIT FUNCTION END IF DIM STROUT AS STRING CopyMemory PHDINFO, OUT_DATA.BBUFFER (0), LEN (PHDINFO) CopyMemory S (0), phdinfo.smodelnumber (0), 40 s (40) = 0 ChangebyteORDER S, 40 STROUT = Bytearrtostring (s, 40) HDID9X = HDID9X & VBCRLF & "Module Number:" & strout CopyMemory S (0), phdinfo.sfirmwarerev (0), 8 s (8) = 0 ChangebyteORDER S, 8 STROUT = byterrtostring (s, 8) hdid9x = HDID9X & VBCRLF & "FIRMWARE REV : "&

Strout CopyMemory S (0), phdinfo.sserialnumber (0), 20 s (20) = 0 ChangeByteorder S, 20 Strout = bytearrtostring (s, 20) HDID9X = HDID9X & VBCRLF & "Serial Number:" & strout CopyMemory S (0 ), phdinfo.ultataLadDressables (0), 4 s (5) = 0 DIM DBLSTROURRTOLONG (S) HDID9X = HDID9X & VBCRLF & "Capacity:" & DBLSTROUT / 2/1024 & "M" end ifnext j ' Close Handle Before QuitCloseHandle (H) Copyright

END FUNCTION

Private function hdidnt () AS STRINGDIM HD AS STRING * 80DIM PhDINFO As TidsectOrdim S (40) AS BYTEDIM STROUT AS STRING

Hdidnt = "" 'We Start in NT / Win2000

转载请注明原文地址:https://www.9cbs.com/read-24261.html

New Post(0)