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

ldcui 2008-03-17 04:49:18
// 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[i] = 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;
}
...全文
70 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
baihacker 2008-03-17
  • 打赏
  • 举报
回复
mark,等高人

64,850

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧