如何获得硬盘id号,C++调用汇编(TASM)篇

今天在看C++栏中时,看到一篇文章C++的获得硬盘id号文章,它使用了DLL库,此文的出处http://blog.csdn.net/fangshi168775/archive/2005/09/04/471016.aspx,很不错,它的CODE简单

这里我给出以前的一段C++结合汇编的代码,在BC++下运行通过,支持ASM必须安装TASM才能调试,不是微软的MASM哦

#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
//#include "mmsystem.h"
//#include "ntport.h"

 

#include <vcl.h>
#pragma hdrstop

//---------------------------------------------------------------------------

#pragma argsused

#pragma warning (disable:4035)
static int inp(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in al, dx
}

static WORD inpw(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in ax, dx
}

static void outp(WORD rdx, int ral)
{
_asm mov dx, rdx
_asm mov eax, ral
_asm out dx, al
}

char *getascii (unsigned int in_data [], int off_start, int off_end);


char *getascii (unsigned int in_data [], int off_start, int off_end)
{
static char ret_val[255];
int loop, loop1;

for (loop = off_start, loop1 = 0; loop <= off_end; loop++)
{
ret_val[loop1++] = (char)(in_data[loop] / 256); /* Get High byte */
ret_val[loop1++] = (char)(in_data[loop] % 256); /* Get Low byte */
}
ret_val[loop1] = '0'; /* Make sure it ends in a NULL character */
return (ret_val);
}

int main(int argc, char* argv[])
{
unsigned int dd [256]; /* DiskData */
unsigned int dd_off; /* DiskData offset */

while (inp(0x1F7) != 0x50) /* Wait for controller not busy */
;

outp(0x1F6, 0xA0); /* Get first/second drive */

outp(0x1F7, 0xEC); /* Get drive info data */

while(inp(0x1F7) != 0x58) /* Wait for data ready */
;

for (dd_off = 0; dd_off != 256; dd_off++) /* Read "sector" */
dd[dd_off] = inpw(0x1F0);

printf ("Hard Disk [C] 的序列号 %s", getascii (dd, 10, 19));

    return 0;
}
//---------------------------------------------------------------------------

我的主页:itbaby.jss.cn

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值