游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1264|回复: 0

汇编程序读取硬盘的序列号 在运行期出现错误?

[复制链接]

2

主题

3

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2008-3-17 16:54:00 | 显示全部楼层 |阅读模式
// Textapplication.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include    <windows.h>   
#include    <stdio.h>   

//////////////////////////////////////////////////////////////////////////
//功能:读取计算机硬盘的序列号
//能够编译通过,但是运行时出错,如下:
//void   GetIDEInfo()  
//{  
// DWORD   dwExcept;  
//
// dwExcept   =   (DWORD)NowInRing0;  
//
// _asm   {  
// mov   eax,   fs:[0]  
// push   eax   
// sidt   [esp-02h]   
// pop   ebx   
// mov   idt,   ebx  
// add   ebx,   0x1C  
// mov   int_idt,   ebx  
//
// mov   eax,   [ebx]  //运行到此处出现错误
//HD01.exe 中的 0x004113e1 处未处理的异常: 0xC0000005: 读取位置 0x8003f41c 时发生访问冲突
///////////////////////////////////////////////////////////////////////////
WORD   pw[256];  

static   DWORD   idt,   int_idt;  
static   DWORD   Base;  
static   WORD   Entry;  

#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  
}  

static   int   WaitIde()  
{  
int   al;  

while   ((al=inp(0x1F7))> =0x80)   ;  
return   al;  
}  

static   void   ReadIDE()  
{  
int   al;  
int   i;  

WaitIde();  
outp(0x1F6,0xA0);  
al   =   WaitIde();  
if   ((al&0x50)!=0x50)   return;  

outp(0x1F6,0xA0);  
outp(0x1F7,0xEC);  
al   =   WaitIde();  
if   ((al&0x58)!=0x58)   return;  

for   (i=0;i <256;i++)   {  
pw   =   inpw(0x1F0);  
}  
}  

static   void   __declspec(   naked   )   NowInRing0()  
{  
_asm   {  
push   ebp   
mov   ebp,esp  

call   ReadIDE  

cli  
mov   ebx,   int_idt  
mov   ax,   Entry  
mov   word   ptr   [ebx-4],   ax  
mov   eax,   Base  
shr   eax,   16   
mov   [ebx+2],   ax  
sti  
leave   
iretd  
}  
}  

void   GetIDEInfo()  
{  
DWORD   dwExcept;  

dwExcept   =   (DWORD)NowInRing0;  

_asm   {  
mov   eax,   fs:[0]  
push   eax   
sidt   [esp-02h]   
pop   ebx   
mov   idt,   ebx  
add   ebx,   0x1C  
mov   int_idt,   ebx  

mov   eax,   [ebx]   
mov   [Base],   eax  
mov   ax,   [ebx-4]   
mov   [Entry],   ax  

cli  
mov   esi,   dwExcept  
push   esi  
mov   [ebx-4],   si  
shr   esi,   16   
mov   [ebx+2],   si   
pop   esi  
sti  

int   3  
}  
}  

//main()  
//{  
//char   s[80];  
//register   i,j;  
//
//GetIDEInfo();  
//
//for   (i=0,j=0;i <10;i++)   {  
//s[j++]=pw[10+i]> > 8;  
//s[j++]=pw[10+i]&0xFF;  
//}  
//s[j]   =   0;  
//
//printf("Serial=%s\n",   s);  
//
//return   0;  
//}   


int _tmain(int argc, _TCHAR* argv[])
{
char   s[80];  
int register   i,j;  

GetIDEInfo();  

for   (i=0,j=0;i <10;i++)   {  
s[j++]=pw[10+i]> > 8;  
s[j++]=pw[10+i]&0xFF;  
}  
s[j]   =   0;  

printf("Serial=%s\n",   s);
return 0;
}abcabc [em24] [em24] [em24] [em24]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-20 11:07

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表