home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / SWIFT.ASM < prev   
Encoding:
Assembly Source File  |  1998-10-26  |  2.6 KB  |  125 lines

  1. ;
  2. ; GRDB
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;
  8. ;
  9. ; swift.asm
  10. ;
  11. ; function: swift (relatively) tracing to find the end of a procedure
  12. ;
  13.     .model small
  14.     .code
  15.     .386
  16.  
  17. include eexec.inc
  18.  
  19. traceon    db    0    ;is swift tracing enabled
  20. int3trace db    0    ;are we in the middle of a full-speed run to int3
  21. image    db    0    ;image at place int 3 is found
  22. oldcs    dw    0    ;position of int 3
  23. oldip    dw    0
  24. oldsp    dw    0    ;save so we can detect int 3 that we didn't
  25. oldss    dw    0    ; put there during swift trace...
  26.  
  27.     public    swiftrace,traceon,untrace
  28.     assume    ds:nothing, es:dgroup
  29. untrace    proc
  30.     test    [int3trace],1    ;
  31.     jz    nounload2    ;
  32.     push    ax        ; registers picked because this used in
  33.     mov    es,[oldcs]    ; break interrupt too!!!!
  34.     mov    bp,[oldip]
  35.     mov    al,[image]    ;
  36.     mov    es:[bp],al    ;
  37.     mov    [int3trace],0    ;
  38.     pop    ax
  39. nounload2:
  40.     mov    [traceon],0
  41.     ret
  42. untrace    endp
  43. swiftrace PROC
  44.     test    [traceon],0ffh
  45.     jz    notrace
  46.     add    sp,2        ; bump past ret
  47.     pusha            ; get user CS:IP
  48.     mov    bp,sp
  49.     push    fs
  50.     push    es
  51.     push    dgroup
  52.     pop    es
  53.     mov    fs,[bp + 16 + 2]
  54.     mov    bx,[bp + 16]    ; unload int 3 call again
  55.     test    [int3trace],1    ;
  56.     jz    nounload    ;
  57.     mov    fs,[oldcs]
  58.     mov    bx,[oldip]
  59.     cmp    sp,[oldsp]    ; this is a hack in case we run into an int 3
  60.     jnz    noupdate    ; during a subroutine run
  61.     mov    ax,ss
  62.     cmp    ax,[oldss]
  63.     jnz    noupdate
  64.     mov    [bp+16],bx    ; point back where int 3 was
  65. noupdate:
  66.     mov    al,[image]    ;
  67.     mov    fs:[bx],al    ;
  68.     mov    [int3trace],0    ;
  69. nounload:
  70.     mov    al,fs:[bx]
  71.     cmp    al,0cch
  72.     jz    found3
  73.     
  74.     call    WadePrefix    ; wade through prefixes
  75.     cmp    al,9dh        ; ehcek for popf
  76.     jnz    notpopf
  77.     or    word ptr [bp + 4 + 2 + 16],100h    ; make sure popf will trace
  78.     jmp    stx
  79. notpopf:
  80.     cmp    al,0c2h        ; now check for rets
  81.     jz    retx
  82.     cmp    al,0c3h
  83.     jz    retx
  84.     cmp    al,0cbh
  85.     jz    retx
  86.     cmp    al,0cah
  87.     jz    retx
  88.     cmp    al,0cfh        ; we WILL check iret here
  89.     jnz    tracex        ; none of those, check for call/int/string stepping
  90.     or    word ptr [bp + 4 + 6 + 16],100h ; be sure iret will trace
  91. retx:
  92.            mov    [traceon],0    ; else kill trace flag and trace past ret/iret
  93. tracex:    
  94.     or    word ptr [bp + 4+16],100h    ; set trace flag
  95.     call    callcheck    ; see if call.int
  96.     jz    setcall        ; yep, set a break there
  97.     call    cmpstring    ; see if is string instruction
  98.     mov    ax,1        ; else one byte
  99.     jz    short setcall    ; yes, set an int 3 instruction in place
  100. stx:
  101.     pop    es
  102.     pop    fs
  103.     popa
  104.     iret
  105. setcall:        
  106.     add    bx,ax
  107.     mov    al,fs:[bx]
  108.     mov    [image],al
  109.     mov    byte ptr fs:[bx],0cch
  110.     inc    [int3trace]
  111.     mov    [oldcs],fs
  112.     mov    [oldip],bx
  113.     mov    [oldss],ss
  114.     mov    [oldsp],sp
  115.     and    word ptr [bp + 4 +16],0FEFFH    ; no trace here
  116.     jmp    stx
  117. found3:
  118.     mov    [traceon],0
  119.     pop    es
  120.     pop    fs
  121.     popa
  122. notrace:
  123.     ret
  124. swiftrace ENDP
  125.     end