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

📄 asm_stubs.asm

📁 Linux下的类似softice的调试工具
💻 ASM
字号:
;/*++;;Copyright (c) 1998-2001 Klaus P. Gerlicher;;Module Name:;;    asm_stubs.asm;;Abstract:;;    assembler stubs to C functions;;Environment:;;    LINUX 2.2.X;    Kernel mode only;;Author: ;;    Klaus P. Gerlicher;;Revision History:;;    02-Mar-2001:	created;;Copyright notice:;;  This file may be distributed under the terms of the GNU Public License.;;--*/;==============================================================================; Define imported data and functions;==============================================================================extern HandleEntryextern ulOldTraceHandlerextern ulOldBreakpointHandlerextern ulOldPageFaultHandlerextern ulOldGPFaultHandlerextern ulOldSyscallHandler;==============================================================================; Defines;==============================================================================REASON_INT3					equ     (0)REASON_SINGLESTEP			equ     (1)REASON_HOTKEY				equ     (2)REASON_PAGEFAULT			equ     (3)REASON_GP_FAULT				equ     (4)REASON_HARDWARE_BP			equ     (5)REASON_DOUBLE_FAULT			equ     (6)REASON_MODULE_LOAD			equ     (7)REASON_INTERNAL_ERROR		equ     (8)REASON_SYSCALL				equ     (9)REASON_STACK_FAULT			equ     (10)REASON_INVALID_OPCODE_FAULT	equ		(11)REASON_DIVBYZERO_FAULT	    equ		(12)REASON_TIMER			    equ		(13)REASON_NMI                  equ		(14)REASON_NOT_PRESENT          equ		(15)REASON_ALIGNMENT			equ		(16)REASON_BOOT_PARAMS			equ		(17)REASON_OTHER_CPU			equ		(18);==============================================================================; Functions;==============================================================================;==============================================================================; FlushCacheAndTLB;;==============================================================================align 4global FlushCacheAndTLBFlushCacheAndTLB:	push eax	mov eax,cr3	mov cr3,eax	wbinvd	pop eax	ret;======================================================================; DebuggerTrace ; ; handle INT1 irqs;;======================================================================align 4global DebuggerTraceDebuggerTrace:    push eax	mov eax,dr6	test eax,(1<<14)    pop eax	jz exceptionnotsinglestep 	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_SINGLESTEP    jmp DebuggerEntryexceptionnotsinglestep:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_HARDWARE_BP    jmp DebuggerEntry;======================================================================; DebuggerSyscall();; handle syscall (int 0x80) so we can see process creation/destruction;;======================================================================align 4global DebuggerSyscallDebuggerSyscall:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_SYSCALL	; call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerTimer();;;======================================================================align 4global DebuggerTimerDebuggerTimer:	; setup IRETD return address    pushfd	push cs	push DWORD DebuggerTimerReturnPoint	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_TIMER	; call debugger loop	jmp DebuggerEntryDebuggerTimerReturnPoint:	ret;======================================================================; DebuggerHotkey();;;======================================================================align 4global DebuggerHotkeyDebuggerHotkey:	; setup IRETD return address    pushfd	push cs	push DWORD DebuggerHotkeyReturnPoint	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_HOTKEY	; call debugger loop	jmp DebuggerEntryDebuggerHotkeyReturnPoint:	ret;======================================================================; DebuggerBootParams();;;======================================================================align 4global DebuggerBootParamsDebuggerBootParams:	; setup IRETD return address    pushfd	push cs	push DWORD DebuggerBootParamsReturnPoint	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_BOOT_PARAMS	; call debugger loop	jmp DebuggerEntryDebuggerBootParamsReturnPoint:	ret;======================================================================; DebuggerBreakpoint() ;;======================================================================align 4global DebuggerBreakpointDebuggerBreakpoint:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_INT3	; call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerAlignment() ;;======================================================================align 4global DebuggerAlignmentDebuggerAlignment:	; push reason code    push DWORD REASON_ALIGNMENT	; call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerDoubleFault() ;;======================================================================align 4global DebuggerDoubleFaultDebuggerDoubleFault:	; push reason code    push DWORD REASON_DOUBLE_FAULT	; call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerPageFault() ; ;======================================================================align 4global DebuggerPageFaultDebuggerPageFault:	; push reason code    push DWORD REASON_PAGEFAULT	; call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerGeneralProtectionFault() ;;======================================================================align 4global DebuggerGeneralProtectionFaultDebuggerGeneralProtectionFault:	; push reason code    push DWORD REASON_GP_FAULT	;call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerStackFault() ;;======================================================================align 4global DebuggerStackFaultDebuggerStackFault:	; push reason code    push DWORD REASON_STACK_FAULT	;call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerInvalidOpcodeFault() ;;======================================================================align 4global DebuggerInvalidOpcodeFaultDebuggerInvalidOpcodeFault:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_INVALID_OPCODE_FAULT	;call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerDivideByZeroFault() ;;======================================================================align 4global DebuggerDivideByZeroFaultDebuggerDivideByZeroFault:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_DIVBYZERO_FAULT	;call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerNmiFault() ;;======================================================================align 4global DebuggerNmiFaultDebuggerNmiFault:	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_NMI	;call debugger loop	jmp DebuggerEntry;======================================================================; DebuggerNotPresentFault() ;;======================================================================align 4global DebuggerNotPresentFaultDebuggerNotPresentFault:	; push reason code    push DWORD REASON_NOT_PRESENT	;call debugger loop	jmp DebuggerEntry;======================================================================; Debugger2ndProcessor() ;;======================================================================align 4global Debugger2ndProcessorDebugger2ndProcessor:	; setup IRETD return address    pushfd	push cs	push DWORD Debugger2ndProcessorReturnPoint	; push fake error code	push DWORD 0	; push reason code    push DWORD REASON_OTHER_CPU	;call debugger loop	jmp DebuggerEntryDebugger2ndProcessorReturnPoint:	ret;==============================================================================; DebuggerEntry;; handle entry into debugger;;==============================================================================align 4global DebuggerEntryDebuggerEntry:		; save registers	; !!! 	; NEVER EVER CHANGE THIS ORDER, IT'S A FIXED STRUCTURE	; !!!	pushad	push ds	push es	; FS,GS,SS are not changed by shell	push fs	push gs	push ss	; setup right selectors	mov ax,ss	mov ds,ax	mov es,ax	; go forward on string instruction, GCC needs that	cld	; push the frame pointer and call C routine	push esp	call HandleEntry	; remove call param, caller cleans up stack 	; restore registers	; !!! 	; NEVER EVER CHANGE THIS ORDER, IT'S A FIXED STRUCTURE	; !!!	add esp,byte 16	pop es	pop ds	;-------------------------------------------------------------------    ; do we need to call old syscall handler    cmp eax,REASON_SYSCALL    jne exit_not_syscall	; restore the register set	popad	; remove our artificial error code and reason code as we're called from a stub 	add esp,byte 8	; call old syscall handler	db 0x2e	jmp [ulOldSyscallHandler]exit_not_syscall:	;-------------------------------------------------------------------    ; do we need to call old INT1 handler    cmp eax,REASON_SINGLESTEP    jne exit_not_singlestep	; restore the register set	popad	; remove our artificial error code and reason code as we're called from a stub 	add esp,byte 8    ; call INT1 handler    db 0x2e    jmp [ulOldTraceHandler]exit_not_singlestep:	;-------------------------------------------------------------------    ; do we need to call old INT1 handler    cmp eax,REASON_HARDWARE_BP    jne exit_not_hardware_bp	; restore the register set	popad	; remove our artificial error code and reason code as we're called from a stub 	add esp,byte 8    ; call INT1 handler    db 0x2e    jmp [ulOldTraceHandler]exit_not_hardware_bp:	;-------------------------------------------------------------------	; do we need to call old INT3 handler    cmp eax,REASON_INT3    jne exit_not_int3	; restore the register set	popad	; remove our artificial error code and reason code as we're called from a stub 	add esp,byte 8		; call INT3 handler    db 0x2e    jmp [ulOldBreakpointHandler]	exit_not_int3:	;-------------------------------------------------------------------     ; do we need to call old pagefault handler    cmp eax,REASON_PAGEFAULT    jne exit_not_pagefault	; restore the register set	popad	; remove our reason code as we're called from a stub 	add esp,byte 4	; call old pagefault handler	db 0x2e    jmp [ulOldPageFaultHandler]exit_not_pagefault:	;-------------------------------------------------------------------    ; do we need to call old general protection fault handler    cmp eax,REASON_GP_FAULT    jne exit_not_gpfault	; restore the register set	popad	; remove our reason code as we're called from a stub 	add esp,byte 4    ; call old pagefault handler	db 0x2e    jmp [ulOldGPFaultHandler]exit_not_gpfault:	;-------------------------------------------------------------------	; simply returning (HOTKEY,TIMER)	; restore the register set	popad	; remove our artificial error code and reason code as we're called from a stub 	add esp,byte 8	iretd;= DebuggerEntry ======================================================;======================================================================; EOF;======================================================================

⌨️ 快捷键说明

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