home *** CD-ROM | disk | FTP | other *** search
- ;; I3HANDLR.ASM
- ;;
- ;; Copyright (c) Dave Maxey, 1992
- ;;
- ;; From Chapter 4 of "Undocumented Windows" (Addison-Wesley 1992)
- ;; by Andrew Schulman, Dave Maxey and Matt Pietrek
- ;;
- ;; Int 3 handler function - subroutine of SNOOP.C
- ;; Hooks DefXXXXXProcs
-
- .286P
-
- PUBLIC _Int3Handler
- PUBLIC _WndProcExit
- EXTRN _Int3EntryProc : near
- EXTRN _WndProcExitProc : near
-
-
- DGROUP GROUP _DATA
- _DATA segment WORD PUBLIC 'DATA'
-
- _DATA ends
-
- _TEXT segment BYTE PUBLIC 'CODE'
-
-
- ;; Relatively simple. Resets the return address to the address
- ;; that generated the int 3. Relies on the fact that int 3 is a
- ;; single byte opcode (0CCh). Int3EntryProc has the job of restoring
- ;; the instruction that was there before we smacked in the int 3, and
- ;; ensuring that WndProcExit gets invoked upon return.
- _Int3Handler proc far
- assume cs:_TEXT, ds:_DATA
- mov bx, sp
- dec word ptr ss:[bx] ;; reset return address
- push ds
- mov ds, ax ;; establish DS
-
- ;IFDEF 0
- mov ax, sp
- add ax, 8
- push ss
- push ax ;; pass current stack ptr
- ;ENDIF
-
- call _Int3EntryProc ;; must be declared cdecl
-
- ;IFDEF 0
- add sp, 4 ;; throw away stack ptr parameter
- ;ENDIF
-
- pop ds
- iret
-
- _Int3Handler endp
-
-
- ;; More complex because of DX:AX return and other register
- ;; preservation issues. The SNOOP MakeProcInstanceBX function must
- ;; have been used to create a procedure instance for this function,
- ;; because a regular MakeProcInstance thunk trashes AX. The address
- ;; of the MakeProcInstanceBX thunk was put onto the stack at original
- ;; int 3 time by Int3EntryProc, and the previous return was stored
- ;; on a separate stack. WndProcExitProc returns us the original return
- ;; address off that stack, and we insert it back onto the stack before
- ;; retf-ing to it.
- _WndProcExit proc far
- assume cs:_TEXT, ds:_DATA
- push dx ;; save DX:AX
- push ax
- push ds
- mov ds, bx ;; establish DS (MakeProcInstanceBX)
-
- ;IFDEF 0
- mov bx, sp
- sub bx, 10 ;; Was +6 by calculation, is actually -10
- push ss
- push bx ;; stack ptr is this brkpnt's identity
- ;ENDIF
-
- call _WndProcExitProc ;; returns orig ret address in DX:AX
-
- ;IFDEF 0
- add sp, 4 ;; throw away identity
- ;ENDIF
-
- pop ds
- mov bx, sp
- xchg ax, ss:[bx] ;; get back previous DX:AX, while
- xchg dx, ss:[bx+2] ;; restoring orig ret address
- ret ;; ... and returning to it.
-
- _WndProcExit endp
-
-
- _TEXT ends
-
- end
-