home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / SOURCE.ZIP / I3HANDLR.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-06-10  |  2.9 KB  |  99 lines

  1. ;; I3HANDLR.ASM 
  2. ;;
  3. ;; Copyright (c) Dave Maxey, 1992 
  4. ;;   
  5. ;; From Chapter 4 of "Undocumented Windows" (Addison-Wesley 1992)
  6. ;; by Andrew Schulman, Dave Maxey and Matt Pietrek
  7. ;;
  8. ;; Int 3 handler function - subroutine of SNOOP.C 
  9. ;; Hooks DefXXXXXProcs
  10.  
  11.     .286P
  12.  
  13.         PUBLIC  _Int3Handler
  14.         PUBLIC  _WndProcExit
  15.         EXTRN   _Int3EntryProc : near
  16.         EXTRN   _WndProcExitProc : near
  17.  
  18.  
  19. DGROUP  GROUP       _DATA
  20. _DATA   segment     WORD PUBLIC 'DATA'
  21.  
  22. _DATA   ends
  23.  
  24. _TEXT   segment     BYTE PUBLIC 'CODE'
  25.  
  26.  
  27. ;; Relatively simple. Resets the return address to the address
  28. ;; that generated the int 3. Relies on the fact that int 3 is a
  29. ;; single byte opcode (0CCh). Int3EntryProc has the job of restoring
  30. ;; the instruction that was there before we smacked in the int 3, and
  31. ;; ensuring that WndProcExit gets invoked upon return.
  32. _Int3Handler    proc far
  33.         assume  cs:_TEXT, ds:_DATA
  34.         mov     bx, sp
  35.         dec     word ptr ss:[bx]    ;; reset return address
  36.         push    ds
  37.         mov     ds, ax              ;; establish DS
  38.  
  39. ;IFDEF 0
  40.         mov     ax, sp
  41.         add     ax, 8
  42.         push    ss
  43.         push    ax                  ;; pass current stack ptr
  44. ;ENDIF
  45.  
  46.         call    _Int3EntryProc      ;; must be declared cdecl
  47.  
  48. ;IFDEF 0
  49.         add     sp, 4               ;; throw away stack ptr parameter
  50. ;ENDIF
  51.  
  52.         pop     ds
  53.         iret
  54.             
  55. _Int3Handler    endp        
  56.  
  57.  
  58. ;; More complex because of DX:AX return and other register
  59. ;; preservation issues. The SNOOP MakeProcInstanceBX function must
  60. ;; have been used to create a procedure instance for this function,
  61. ;; because a regular MakeProcInstance thunk trashes AX. The address
  62. ;; of the MakeProcInstanceBX thunk was put onto the stack at original
  63. ;; int 3 time by Int3EntryProc, and the previous return was stored
  64. ;; on a separate stack. WndProcExitProc returns us the original return
  65. ;; address off that stack, and we insert it back onto the stack before
  66. ;; retf-ing to it.
  67. _WndProcExit    proc far
  68.         assume  cs:_TEXT, ds:_DATA
  69.         push    dx                  ;; save DX:AX
  70.         push    ax
  71.         push    ds
  72.         mov     ds, bx              ;; establish DS (MakeProcInstanceBX)
  73.  
  74. ;IFDEF 0
  75.         mov     bx, sp
  76.         sub     bx, 10              ;; Was +6 by calculation, is actually -10
  77.         push    ss
  78.         push    bx                  ;; stack ptr is this brkpnt's identity
  79. ;ENDIF
  80.  
  81.         call    _WndProcExitProc    ;; returns orig ret address in DX:AX
  82.  
  83. ;IFDEF 0
  84.         add     sp, 4               ;; throw away identity
  85. ;ENDIF
  86.  
  87.         pop     ds
  88.         mov     bx, sp
  89.         xchg    ax, ss:[bx]         ;; get back previous DX:AX, while
  90.         xchg    dx, ss:[bx+2]       ;; restoring orig ret address
  91.         ret                         ;; ... and returning to it.
  92.             
  93. _WndProcExit    endp        
  94.  
  95.  
  96. _TEXT   ends
  97.  
  98.         end
  99.