; ; FTrac (traces DOS file related calls) ; ; $Id: ftrac.asm 8 2004-11-08 07:13:24Z guillem $ ; ; Copyright (C) 1997-2001 Guillem Jover ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software Foundation, ; Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ; org 0x100 jmp Main Key db 0xF5 File dw 0 ; Handle of output file MyPSP dw 0 ; My PSP IntPSP dw 0 ; Interrupted PSP BufSize dw 0 ; Buffer size occupied SDA dd 0 ; Swappable DOS Area CriticalFlag equ 0 ; offset within SDA InDosFlag equ 1 ; offset within SDA BiosInt1C dd 0 DosServices dd 0 DosMultiplexor dd 0 NewInt1C: push ds push es push di push ax push bx push cx push dx mov ax, cs mov ds, ax les di, [SDA] cmp byte [es:di+InDosFlag], 0 ; Is Dos Busy ? jnz .NoAction cmp byte [es:di+CriticalFlag], 0 jnz .NoAction cmp word [BufSize], 0 ; Buffer have changed ? jz .NoAction mov ah, 0x51 ; Get interrupted process PSP int 0x21 mov [IntPSP], bx mov ah, 0x50 ; Set TSR PSP mov bx, [MyPSP] int 0x21 mov ah, 0x40 ; Write Buffer to File mov bx, [File] mov cx, [BufSize] mov dx, Buffer int 0x21 mov word [BufSize], 0 mov ah, 0x68 ; Flush DOS file buffer mov bx, [File] int 0x21 mov ah, 0x50 ; Set interrupted process PSP mov bx, [IntPSP] int 0x21 .NoAction: pop dx pop cx pop bx pop ax pop di pop es pop ds iret NewMultiplexor: cmp ah, byte [cs:Key] ; Is for me? jz .Catch jmp far [cs:DosMultiplexor] .Catch: cmp al, 0 ; Install Check jnz .Uninstall mov al, 0xFF jmp .Return .Uninstall: cmp al, 1 ; Uninstall jnz .Return push ds push es push dx push bx lds dx, [cs:DosServices] ; Restore Ints mov ax, 0x2521 int 0x21 lds dx, [cs:BiosInt1C] mov ax, 0x251C int 0x21 lds dx, [cs:DosMultiplexor] mov ax, 0x252F int 0x21 mov ah, 0x3E ; Close File mov bx, [cs:File] int 0x21 mov ax, cs ; Release Memory mov es, ax mov ah, 0x49 int 0x21 jc .MemErr xor ax, ax .MemErr: pop bx pop dx pop es pop ds .Return: iret NewDosServices: pushf push es push di push si push cx cmp ah, 0x0F ; Open File using FCB (DOS 1+) jz .FCB cmp ah, 0x3B ; Change Current Directory (DOS 2+) jz .StrDX cmp ah, 0x3D ; Open Existing File (DOS 2+) jz .StrDX cmp ah, 0x4B ; Exec File (DOS 2+) jz .StrDX cmp ax, 0x6C00 ; Extended Open/Create File (DOS 4.0+) jz .StrDI jmp .Return .FCB: mov si, dx cmp [si], byte 0xFF ; FCB offset 0 jz .ExtendedFCB inc si ; FCB offset 1 jmp .CopyFCB .ExtendedFCB: shl si, 3 ; FCB offset 1+7 .CopyFCB: mov di, Buffer add di, [cs:BufSize] mov cx, cs mov es, cx mov cx, 11 add [cs:BufSize], cx rep movsb jmp .Return .StrDX: mov si, dx jmp .PreCopy .StrDI: mov si, di .PreCopy: ; Copy file name to Buffer mov di, Buffer add di, [cs:BufSize] mov cx, cs mov es, cx xor cx, cx .Copy: movsb inc cx cmp byte [si-1], 0 jnz .Copy add [cs:BufSize], cx .Return: pop cx pop si pop di pop es popf jmp far [cs:DosServices] Buffer: FileName db 'ftrac.out', 0 MsgEntry db 'ftrac TSR v1.0 Guillem Jover (C) 1997-2001', 0xD, 0xA, db 0xD, 0xA, '$' MsgHelp db ' usage: ftrac [option]', 0xD, 0xA db 0x9, 0x9, '-h, ?', 0x9, 'prints this help.', 0xD, 0xA db 0x9, 0x9, '-r', 0x9, 'remove program from memory.$' MsgInst db ' installing... $' MsgUninst db ' uninstalling... $' MsgOk db 'ok', 0xD, 0xA, '$' MsgError db 'error: $' MsgEndLn db 0xD, 0xA, '$' MsgErrSyntax db 'syntax error$' MsgErrOpen db 'opening output file$' MsgErrWrite db 'writing output file$' MsgErrInst db 'already installed$' MsgErrNotInst db 'not installed$' MsgErrMem db 'problem releasing memory$' MsgErrOther db 'another TSR loaded (unload it first)$' %macro Write 1 mov ah, 9 mov dx, %1 int 0x21 %endmacro %macro Error 1 Write MsgError Write %1 %endmacro %macro GetInt 2 mov ax, 0x35%1 int 0x21 mov word [%2], bx mov word [%2+2], es %endmacro %macro SetInt 2 mov ax, 0x25%1 mov dx, %2 int 0x21 %endmacro Main: Write MsgEntry mov ax, cs mov es, ax mov ds, ax mov di, 0x80 ; Process command line mov cl, byte [di] xor ch, ch inc di mov al, '-' repne scasb jnz Install cmp byte [di], '?' jz near Help cmp byte [di], 'H' jz near Help cmp byte [di], 'h' jz near Help cmp byte [di], 'R' jz near Uninstall cmp byte [di], 'r' jz near Uninstall Error MsgErrSyntax jmp Exit Install: Write MsgInst mov ah, byte [Key] xor al, al int 0x2F cmp al, 0xFF jnz .NoInstErr Error MsgErrInst jmp Exit .NoInstErr: mov ah, 0x3C ; Open the output file mov cx, 0 mov dx, FileName int 0x21 jnc .NoOpenErr Error MsgErrOpen jmp Exit .NoOpenErr: mov [File], ax %ifdef DEBUG mov ah, 0x40 ; Write Debug Mark to File mov bx, [File] mov cx, 44 mov dx, MsgEntry int 0x21 jnc .NoWriteErr Error MsgErrWrite jmp Exit .NoWriteErr: mov ah, 0x68 mov bx, [File] int 0x21 %endif mov ah, 0x51 ; Save current PSP int 0x21 mov [MyPSP], bx push ds mov ax, 0x5D06 ; Locate SDA int 0x21 mov word [cs:SDA], si mov word [cs:SDA+2], ds pop ds push es GetInt 1C, BiosInt1C GetInt 21, DosServices GetInt 2F, DosMultiplexor pop es push ds SetInt 1C, NewInt1C SetInt 21, NewDosServices SetInt 2F, NewMultiplexor pop ds mov es, word [0x2C] ; Release evironment memory mov ah, 0x49 int 0x21 Write MsgOk mov ax, 0x3100 mov dx, ResidentSize int 0x21 ; Go TSR Uninstall: Write MsgUninst mov ah, byte [Key] xor al, al ; Install Check int 0x2F cmp al, 0xFF jz .doit Error MsgErrNotInst jmp Exit .doit: mov ah, byte [Key] ; Uninstall mov al, 1 int 0x2F cmp al, 0 jnz .ErrUninst Write MsgOk jmp Exit .ErrUninst: Error MsgErrMem jmp Exit Help: Write MsgHelp Exit: Write MsgEndLn mov ax, 0x4C00 int 21h BufferMaxSize equ ($ - Buffer) ResidentSize equ ((($ - $$) + 15) / 16) + 16