home *** CD-ROM | disk | FTP | other *** search
- ; ******************************************************************
- ; SNOOP.ASM Created 6/24/1989 by L. Brett Glass
- ; ******************************************************************
- ; This TSR logs disk all hard disk reads and writes that pass through
- ; the IBM PC BIOS on the way to the first hard disk to a RAM buffer.
- ; The sector, cylinder, head, drive, operation, and number of sectors
- ; are recorded.
- ;
- ; Copyright (C) 1989 by L. Brett Glass, Systems Consultant
- ;
- ; Usenet: apple!well!rogue
- ; ARPANET: well!rogue@APPLE.COM
- ; BIX: glass
- ; CompuServe: [72267,3673] (Also reachable from MCIMail)
- ;
- ; This program may be freely redistributed for non-commercial purposes
- ; only. It may not be made part of any hardware or software product
- ; without the express written consent of the copyright owner. This
- ; program is supplied on an "as-is" basis. The author assumes no
- ; responsibility for its correctness or its fitness for a given
- ; purpose, nor for consequential damages which may arise from its use.
- ;
- ; ******************************************************************
- ;
- DISKINT equ 13h ; Disk I/O Interrupt number
- DOS equ 21h ; Interrupt number for: DOS function
- TSR equ 27h ; Terminate/stay resident
- GETVEC equ 35h ; DOS Function numbers: Get interrupt vector
- SETVEC equ 25h ; Set interrupt vector
- PRINTMSG equ 9 ; Print message
- HARD equ 80h ; Mask to test for hard disk #
- DISKREAD equ 2 ; BIOS functions: Read
- DISKWRITE equ 3 ; Write
- GETBUFADDR equ 99AAh ; Special Int 13h request for snoop buffer address
- BADCMD equ 1 ; Bad command result code for BIOS call
- SENTINEL equ 4321h ; Sentinel value to signal that SNOOP is present
-
- MAXTRANSACTIONS equ 8 * 1024 ; Log 8K disk transactions
- BUFFERSIZE equ 6 * MAXTRANSACTIONS ; Each transaction is 6 bytes
-
- Code segment
- assume cs:Code,ds:Nothing
- org 100h
- Entry: jmp near ptr Init ; Jump to transient portion of program
- ;
- ; Store the original vector here
- ;
- DiskIO label dword ; Make a label for the whole vector
- DiskIOOfs dw 0 ; Now make labels for segment and offset
- DiskIOSeg dw 0
- ;
- ; Define constants that indicate where buffer starts and ends
- ;
- BufferStart equ (offset NextLoc) + 2
- BufferEnd equ (offset NextLoc) + 2 + BUFFERSIZE
- ;
- Snoop proc far
- cmp dl,80h ; Is it a call to the first hard disk?
- jnz Chain ; Nope, let it through
- cmp ah,DISKREAD ; Is it a read request?
- je Log ; If so, log it
- cmp ah,DISKWRITE ; Is it a write request?
- je Log
- cmp ax,GETBUFADDR ; Is it a buffer address request?
- jne Chain ; If not read or write or addr request, pass on
- GetAddr: mov ax,cs ; Get address
- mov es,ax
- mov bx,offset WrapFlag
- mov dx,SENTINEL ; Tell program SNOOP is present on the sly
- mov ah,BADCMD ; Look like bad command
- stc ; Generate apparent error
- sti ; And enable interrupts
- ret 2 ; Do not restore original flags when returning
- Log: push di ; Use di as a pointer into the buffer
- mov di,cs:NextLoc ; Get the next position to be written
- mov cs:[di],dx ; Store DX
- add di,2
- mov cs:[di],cx ; Then CX
- add di,2
- mov cs:[di],ax ; Then AX
- add di,2
- cmp di,BufferEnd ; End of buffer?
- jb @F
- mov di,BufferStart ; If so, wrap to beginning
- mov cs:WrapFlag,1 ; And set a flag so we know we've wrapped
- @@: mov cs:NextLoc,di
- pop di
- Chain: jmp cs:[DiskIO] ; Jump to disk BIOS
- Snoop endp
- ;
- ; Labels used by TSR portion of program
- ;
- WrapFlag db 0 ; Flag to indicate buffer has wrapped at least once
- NextLoc label word ; Next location to store disk info
- ;
- ; "Transient" area (also used for logging transactions) begins here
- ;
- Message db 'Hard Disk Log Utility'
- db 0Dh,0Ah,'Copyright (C) 1989 by L. Brett Glass'
- db 0Dh,0Ah,'Reboot to remove this TSR.'
- db 0Dh,0Ah,'$'
- ;
- ; assume cs:Code,ds:Code
- ;
- Init proc near ; This code executed on entry
- mov ax,(GETVEC shl 8) + DISKINT ; Get interrupt vector from DOS
- int DOS ; DOS call
- mov [DiskIOOfs],bx ; Save the old vector
- mov [DiskIOSeg],es
- mov dx,offset Snoop ; Get ready to add our own routine
- mov ah,SETVEC ; Set interrupt vector thru DOS
- int DOS ; DOS call
- mov dx,offset Message ; Prepare to print message
- mov ah,PRINTMSG ; Print message through DOS
- int DOS ; DOS call
- mov NextLoc,BufferStart ; Start from beginning of buffer
- mov dx,BufferEnd ; Reserve space for buffer
- int TSR ; Terminate and stay resident
- Init endp
- Code ends
- end Entry
-