⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ring0.asm

📁 硬盘的IDE驱动程序
💻 ASM
字号:
INTNUMBER	equ	3
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;	Programmed by 罗云彬, bigluo@telekbird.com.cn
;	Website: http://asm.yeah.net
;	LuoYunBin's Win32 ASM page (罗云彬的编程乐园)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 在 Windows9x 下切入特权级 0 执行特权指令
;	Version	1.0	Date: 2001.05.18
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 使用方法:
; _Ring0Call 程序用来切入特权级 0,可以将要在 Ring0 下执行的子程序
; 地址和参数作为参数传递给 _Ring0Call
; 如果原来要执行 invoke _ProcToCall,dwParam
; 那么可以 invoke _Ring0Call,offset _ProcToCall,dwParam
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
SEH		struct

PrevLink	dd	?	; the address of the previous seh structure
CurrentHandler	dd	?	; the address of the new exception handler
SafeOffset	dd	?	; The offset where it's safe to continue execution
PrevEsp		dd	?	; the old value in esp
PrevEbp		dd	?	; The old value in ebp

SEH		ends
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 新的中断过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_NewIntProc:
		mov	[ebx-4],cx
		shr	ecx,16
		mov	[ebx+2],cx
		push	edx
		call	eax
		iretd
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 出错处理代码
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ErrorHandle	proc	lpExcept,lpFrame,lpContext,lpDispatch

		pushad
		assume	edx:ptr SEH
		assume	eax:ptr CONTEXT

		mov	edx,lpFrame
		mov	eax,lpContext
		push	[edx].SafeOffset
		pop	[eax].regEip
		push	[edx].PrevEsp
		pop	[eax].regEsp
		push	[edx].PrevEbp
		pop	[eax].regEbp

		assume	edx:nothing
		assume	eax:nothing
		popad
		mov	eax,ExceptionContinueExecution
		ret

_ErrorHandle	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 进入 0 特权级
; 返回:eax = TRUE 成功
;	eax = FALSE 失败
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_Ring0Call	proc	_lpProc,_dwParam
		local	@dwReturn,@stSEH:SEH

		assume	fs:nothing

		pushad
		mov	@dwReturn,FALSE
;********************************************************************
; 建立新的 SEH,当程序在 Windows NT 下运行的时候可以截获到错误
;********************************************************************
		push	fs:[0]
		pop	@stSEH.PrevLink
		mov	@stSEH.CurrentHandler,offset _ErrorHandle
		mov	@stSEH.SafeOffset,offset @F
		mov	@stSEH.PrevEsp,esp
		mov	@stSEH.PrevEbp,ebp
		lea	eax,@stSEH
		mov	fs:[0],eax

		push	eax
		sidt	[esp-2]
		pop	ebx
		add	ebx,INTNUMBER*8+4

		cli
;********************************************************************
; 在 NT中,IDT 是不可访问的,执行下一句 mov ebp,[ebx] 会引起错误
; 跳到 @@ 执行,在 Win9x 下则可继续执行
;********************************************************************
		mov	ecx,[ebx]
		mov	cx,[ebx-4]

		mov	eax,offset _NewIntProc
		mov	[ebx-4],ax
		shr	eax,16
		mov	[ebx+2],ax

		mov	eax,_lpProc
		mov	edx,_dwParam
		int	INTNUMBER
		sti
		mov	@dwReturn,TRUE

		@@:
		push	@stSEH.PrevLink
		pop	fs:[0]
		popad
		mov	eax,@dwReturn
		ret

_Ring0Call	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 检测程序是否运行在 Windows NT 下
; 返回 eax = TRUE 表示程序运行在 NT 下
;      eax = FALSE 表示运行在 Windows 9x 下
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_CheckNT	proc
		local	@stVersion:OSVERSIONINFO

		mov	@stVersion.dwOSVersionInfoSize,sizeof OSVERSIONINFO
		invoke	GetVersionEx,addr @stVersion
		.if	@stVersion.dwPlatformId == VER_PLATFORM_WIN32_NT
			mov	eax,TRUE
		.else
			mov	eax,FALSE
		.endif
		ret

_CheckNT	endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -