Ring0的一个例子

I

import

Unregistered / Unconfirmed
GUEST, unregistred user!
网上找到好多Ring3层运行Ring0级的资料,可惜都是Asm,C/C++的代码,有一个用Delphi编写VXD的例子,还只能在Delphi3上编译。经过多方参考,终于搞定。让各位大虾见笑了。此段代码只能在95/98中运行,其实原理和CIH的开头获取特权级部分一样。小弟很菜,不足之处请各位大虾指教。谢谢。 button1 : 直接执行Int 03h,在IDE环境中会产生单步调试的中断,独立运行会发生异常,是为了证明button2执行的代码正确性而设置的。
button2 : 实际获取Ring 0 级的代码,使用了内嵌汇编。
button3 : 停止button2中的发声
unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
var IDT : array [0..5] of byte; // 保存中断描述符表
lpOldGate : dword; // 存放旧向量
implementation
{$R *.DFM}
procedure aa; stdcall;
const ExceptionUsed = $03; // 中断号。
begin
asm
sidt IDT // 读入中断描述符表
mov ebx, dword ptr [IDT+2]
add ebx, 8*ExceptionUsed
cli
mov dx, word ptr [ebx+6]
shl edx, 16d
mov dx, word ptr [ebx]
mov [lpOldGate], edx
mov eax, offset @@Ring0Code // 修改向量,指向Ring0级代码段
mov word ptr [ebx], ax
shr eax, 16d
mov word ptr [ebx+6], ax
int ExceptionUsed // 发生中断
mov ebx, dword ptr [IDT+2]
add ebx, 8*ExceptionUsed
mov edx, [lpOldGate]
mov word ptr [ebx], dx
shr edx, 16d
mov word ptr [ebx+6], dx // 恢复被改了的向量
ret
@@Ring0Code: // Ring0级代码段
mov eax,cr0 // 此句在Ring3级会发生异常错误
mov dx, $61 // 以下语句是为了证明执行了此段代码,让PCSpeak发声
mov al, $ff
out dx, al
mov dx, $43
mov al, $b6
out dx, al
mov dx, $42
mov al, $f0
out dx, al
mov dx, $42
mov al, $0
out dx, al
iretd // 中断返回
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
aa;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
asm
int 03h //
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var bvalue : byte;
value : word;
begin // 停止PCSpeak发声
asm
mov dx, $61
in al, dx
mov bValue, al
end
value := bValue and $fc;
bValue := Trunc(Value and 255);
asm
 mov dx, $61
   mov al, bValue
   out dx, al
end;
end;
end.
 

Similar threads

I
回复
0
查看
763
import
I
I
回复
0
查看
476
import
I
I
回复
0
查看
639
import
I
I
回复
0
查看
561
import
I
I
回复
0
查看
563
import
I
顶部