讀取硬碟序列號

2021-09-06 18:56:57 字數 4250 閱讀 4133

#pragma hdrstop

#pragma argsused

#include #include #include #include "hdd.h"

const word ide_atapi_identify = 0xa1; // 讀取atapi裝置的命令

const word ide_ata_identify = 0xec; // 讀取ata裝置的命令

const int disk_path_len = 128;

const int disk_info_buf_len = 128;

void changebyteorder(pchar szstring, ushort uscstrsize)

}dword getdiskmodelnumber(dword driver, char *modelnumber, char *sn_buf, char * fw_buf)

getversioninparams gvopversionparams;

result = deviceiocontrol(

hdevice,

smart_get_version,

null,

0,&gvopversionparams,

sizeof(gvopversionparams),

&readed,

null);

if (!result) //fail

if(0 == gvopversionparams.bidedevicemap)

// ide or atapi identify cmd

byte btidcmd;

sendcmdinparams inparams;

byte ndrive =0;

btidcmd = (gvopversionparams.bidedevicemap >> ndrive & 0x10) ? ide_atapi_identify : ide_ata_identify;

// output structure

byte outparams[sizeof(sendcmdoutparams) + identify_buffer_size - 1]; // + 512 - 1

//fill in the input buffer

inparams.cbuffersize = 0; //or identify_buffer_size ?

inparams.irdriveregs.bfeaturesreg = read_attributes;

inparams.irdriveregs.bsectorcountreg = 1;

inparams.irdriveregs.bsectornumberreg = 1;

inparams.irdriveregs.bcyllowreg = 0;

inparams.irdriveregs.bcylhighreg = 0;

inparams.irdriveregs.bdriveheadreg = (ndrive & 1) ? 0xb0 : 0xa0;

inparams.irdriveregs.bcommandreg = btidcmd;

= ndrive;

//get the attributes

result = deviceiocontrol(

hdevice,

smart_rcv_drive_data,

&inparams,

sizeof(sendcmdinparams) - 1,

outparams,

sizeof(sendcmdoutparams) + identify_buffer_size - 1,

&readed,

null);

if (!result) //fail

(void)closehandle(hdevice);

idinfo *ip = (idinfo *)((sendcmdoutparams*)outparams)->bbuffer ;

// get firmware number

memset(fw_buf, 0, 8);

memcpy(fw_buf, ip->sfirmwarerev, 8);

fw_buf[8] = '\0';

changebyteorder(fw_buf, 8);

printf("\n->firmware: %s", fw_buf);

// get serial number

memset(sn_buf, 0, 20);

memcpy(sn_buf, ip->sserialnumber, 20);

sn_buf[20] = '\0';

changebyteorder(sn_buf, 20);

printf("\n->serial: %s", sn_buf);

// get model number

memset(modelnumber, 0, 40);

memcpy(modelnumber, ip->smodelnumber, 40);

modelnumber[40] = '\0';

changebyteorder(modelnumber, 40);

printf("\n->model: %s", modelnumber);

return 0;

}int _tmain(int argc, _tchar* argv)

hdd.h

typedef struct _idinfo

wcapabilities; // word 49: 一般能力

ushort wreserved1; // word 50: 保留

ushort wpiotiming; // word 51: pio時序

ushort wdmatiming; // word 52: dma時序

struct wfieldvalidity; // word 53: 興許字段有效性標誌

ushort wnumcurcyls; // word 54: chs可定址的柱面數

ushort wnumcurheads; // word 55: chs可定址的磁頭數

ushort wnumcursectorspertrack; // word 56: chs可定址每磁軌扇區數

ushort wcursectorslow; // word 57: chs可定址的扇區數低位字

ushort wcursectorshigh; // word 58: chs可定址的扇區數高位字

struct wmultsectorstuff; // word 59: 多扇區讀寫設定

ulong dwtotalsectors; // word 60-61: lba可定址的扇區數

ushort wsingleworddma; // word 62: 單位元組dma支援能力

struct wmultiworddma; // word 63: 多位元組dma支援能力

struct wpiocapacity; // word 64: 高階pio支援能力

ushort wminmultiworddmacycle; // word 65: 多位元組dma傳輸週期的最小值

ushort wrecmultiworddmacycle; // word 66: 多位元組dma傳輸週期的建議值

ushort wminpionoflowcycle; // word 67: 無流控制時pio傳輸週期的最小值

ushort wminpoiflowcycle; // word 68: 有流控制時pio傳輸週期的最小值

ushort wreserved69[11]; // word 69-79: 保留

struct wmajorversion; // word 80: 主版本號

ushort wminorversion; // word 81: 副版本號

ushort wreserved82[6]; // word 82-87: 保留

struct wultradma; // word 88: ultra dma支援能力

ushort wreserved89[167]; // word 89-255

} idinfo, *pidinfo;



C 讀取硬碟的序列號

include include include define dfp get version 0x00074080 define dfp send drive command 0x0007c084 define dfp receive drive data 0x0007c088 pragma pac...

Delphi讀取硬碟的物理序列號

因要用到硬碟的物理序列號,從網上找了很多,最終確定使用了以下的一段程式 function tfrmmain.getideserialnumber pchar stdcall const identify buffer size 512 type tideregs packed record bfea...

DELPHI中讀取硬碟的物理序列號

讀取硬碟的物理序列號 獲得硬碟序列號 function getideserialnumber pchar stdcall const identify buffer size 512 type tideregs packed record bfeaturesreg byte used for spe...