Software 版 (精华区)

发信人: checcy (老巴夺), 信区: Software
标  题: 获得硬盘的出厂Serial Number
发信站: 哈工大紫丁香 (Wed Apr 29 06:13:37 1998), 转信

 FY>   请问如何才能获得硬盘的出厂Serial Number?
=== Cut ===
/********************************************************************
    idediag
    shows characteristics of IDE hard disks.
    Public Domain by Paolo Bevilacqua, Rome.
    You can add more disk type to the idetypes[]
    table, and distribuite freely.
********************************************************************/

/* read/write */
#define HDC_DATA    0x1F0
#define HDC_ERROR   0x1F1
#define HDC_SECCOU  0x1F2
#define HDC_SECNUM  0x1F3
#define HDC_CYLLOW  0x1F4
#define HDC_CYLHIGH 0x1F5
#define HDC_SDH     0x1F6

/* read */
#define HDC_STATUS  0x1F7
#define HDC_ALTSTA  0x3F6

/* write */
#define HDC_COMMAND 0x1F7
#define HDC_FIXED   0x3F6

/* commands */
#define HDC_COMMAND_RESTORE 0x10
#define HDC_COMMAND_SEEK    0x70
#define HDC_COMMAND_READ    0x20
#define HDC_COMMAND_WRITE   0x30
#define HDC_COMMAND_FORMAT  0x50
#define HDC_COMMAND_READVER 0x90
#define HDC_COMMAND_DIAG    0x90
#define HDC_COMMAND_SETPAR  0x91
#define HDC_COMMAND_WRSTACK 0xE8
#define HDC_COMMAND_RDSTACK 0xE4
#define HDC_COMMAND_READPAR 0xEC
#define HDC_COMMAND_POWER   0xE0

#define HDC_FIXED_IRQ        0x02
#define HDC_FIXED_RESET     0x04

#define HDC_STATUS_ERROR    0x01
#define HDC_STATUS_INDEX    0x02
#define HDC_STATUS_ECC        0x04
#define HDC_STATUS_DRQ        0x08
#define HDC_STATUS_COMPLETE 0x10
#define HDC_STATUS_WRFAULT  0x20
#define HDC_STATUS_READY    0x40
#define HDC_STATUS_BUSY     0x80

unsigned secbuf[256];
int drive;

struct ideinfo {
    unsigned genconf,
         fixcyls,
         remcyls,
         heads,
         bytetrack,     /* bytes per track */
         bytesector,    /* bytes per sector */
         sectors,      /* sectors per track */
         byteisg,      /* bytes intesector gap */
         byteplo,      /* bytes in sync */
         worduniq;     /* words unique status */
    char serial[20];
    unsigned contype,        /* controller type */
         bufsiz,      /* buffer size in 512 byte blocks */
         byteecc;      /* ECC bytes trasferred in read/write
long */
    char firmware[8],        /* firmware revision */
     model[40];       /* model ID */
    unsigned secsint,        /* number of sectors
transferred per interrupt */
         dblword,      /* double word transfer flag */
         writepro;     /* write protect */
};

main() {

        int i;
    drive = 0;

    /* disable interrupt from drive */
    outp(HDC_FIXED, HDC_FIXED_IRQ);

    /* set up task file parameter */
    outp(HDC_SDH, 0xA0 + (drive<<4));

    /* issue read parameters */
    outp(HDC_COMMAND, HDC_COMMAND_READPAR);

    /* read up sector */
        /* poll DRQ */
        while(inp(HDC_STATUS) & HDC_STATUS_BUSY)
        ;

        /* read up sector */
        for (i=0; i<256; ++i)
           secbuf[i] = inpw(HDC_DATA);
}
=== End ===

 FY> 我想用它作为加密识别点.
这只能识别该硬盘. 还不能识别具体是哪台机.

 FY> 另外还有什么可靠的识别机器唯一性的方法吗?
CPU, RAM, BIOS等, 但都只能识别一类机器(
象公司用户每次购机时都
是同样配置的机器, 这些资料就会相同 ).
如果不考虑兼容性和普遍性的话还有网卡的EtherNet网址,
IDE/SCSI设
备的系列号等配置信息可读的设备.
不过除非你想象CCED那样要求你的软件只能在某一个特定的机器上用,
否则最好只认硬盘就行了.

--
☆ 来源:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: checcy@public.hr.hl.]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.891毫秒