home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / KGB104.ZIP / KGB.ASM next >
Encoding:
Assembly Source File  |  1992-04-16  |  12.7 KB  |  633 lines

  1.         .8086
  2.         .model small
  3.         .stack 200h
  4.         .code
  5. ResBeg        label byte
  6. BuffPos        dw    0
  7. BuffSize    dw    100h
  8. Old21        dd    ?
  9. status        dd    ?
  10. Off        db    0
  11. path        db    'C:\HISTORY.DAT',0
  12.         db    112 dup (0)
  13. functions    db    3ch,3dh,41h,4bh,5bh
  14. IFDEF        FIND
  15.         db    4eh
  16. ENDIF
  17. NFunc        equ    $ - functions
  18. OK        db    ?
  19. func_table      dw      CreateFil       ;3ch - create handle
  20.         dw    OpenFil        ;3dh - open handle
  21.         dw    DeleteFil    ;41h - delete file
  22.         dw    Exec        ;4bh - load & execute
  23.         dw    CreateNew    ;5bh - create New File
  24. IFDEF        FIND
  25.         dw    FindFile    ;4eh - find file
  26. ENDIF
  27. MyPSP        dw    ?
  28. ;----------------- Program ---------------------
  29. IntHandler    proc    far
  30.         cmp    cs:[Off],1
  31.         je    Done
  32.         push    ax
  33.         push    bx
  34.         push    cx
  35.         push    dx
  36.         push    si
  37.         push    di
  38.         push    es
  39.         push    ds
  40.         push    bp
  41.         mov    bp,sp
  42. ParDs        equ    ss: word ptr [bp+ 2]
  43. ParEs        equ    ss: word ptr [bp+ 4]
  44. ParDx        equ    ss: word ptr [bp+10]
  45. ParCx        equ    ss: word ptr [bp+12]
  46. ParBx        equ    ss: word ptr [bp+14]
  47. ParAx        equ    ss: word ptr [bp+16]
  48. ParFlg        equ    ss: word ptr [bp+22]
  49.         cmp    ax,0c6c6h
  50.         jne    PolCont
  51.         mov    ax,ParFlg
  52.         or    ax,1
  53.         mov    ParFlg,ax
  54.         mov    ax,cs
  55.         add    sp,18
  56.         iret
  57. PolCont:    mov    ax,cs
  58.         mov    ds,ax
  59.         mov    ax,ParAx
  60.         mov    si,0
  61. next:        cmp    si,NFunc
  62.         je    cont
  63.         cmp    ah,functions[si]
  64.         je    subr
  65.         inc    si
  66.         jmp    next
  67. Subr:        shl    si,1
  68.                 call    func_table[si]
  69. cont:        mov    sp,bp
  70.         pop    bp
  71.         pop    ds
  72.         pop    es
  73.         pop    di
  74.         pop    si
  75.         pop    dx
  76.         pop    cx
  77.         pop    bx
  78.         pop    ax
  79. Done:        jmp    cs:[Old21]
  80. ;----------------------------------------------------------
  81. IntHandler    ENDP
  82. ;---------------------------------------------------------
  83. CreateFil:    call    cont1
  84.         db      'CreateFile  : ',0
  85. CreateNew:    call    Cont1
  86.         db      'CreateNew   : ',0
  87. DeleteFil:    call    cont1
  88.         db      'DeleteFile  : ',0
  89. IFDEF        FIND
  90. FindFile:    call    cont1
  91.         db      'FindFile    : ',0
  92. ENDIF
  93. ;---------------------------------------------------------
  94. OpenFil:    mov     ax,ParAX
  95.         cmp     al,0
  96.         jne     OpenFil1
  97.         call    cont1
  98.         db      'OpenFile-R  : ',0
  99. OpenFil1:    cmp     al,1
  100.         jnz     OpenFil2
  101.         call    cont1
  102.         db      'OpenFile-W  : ',0
  103. OpenFil2:    call    cont1
  104.         db      'OpenFile-R/W: ',0
  105. ;---------------------------------------------------------
  106. Exec:        call    Exec1
  107.         db      'Exec        : ',0
  108. Exec1:        pop     si
  109. ExLop:        lodsb
  110.         or      al,al
  111.         jz      ExCont
  112.         call    PutBuff
  113.         jmp     ExLop
  114. ExCont:        call    PutStr
  115.         mov     al,' '
  116.         call    PutBuff
  117.         call    PutParStr
  118.         call    PutCrLf
  119.         call    ApendTMP
  120.         retn
  121. ;---------------------------------------------------------
  122. Cont1:        pop     si
  123. CoLop:        lodsb
  124.         or      al,al
  125.         jz      CoCont
  126.         call    PutBuff
  127.         jmp     CoLop
  128. CoCont:        call    PutStr
  129.         call    PutCrLf
  130.         call    ApendTMP
  131.         retn
  132. ;---------------------------------------------------------
  133. PutParStr:    mov    es,parES
  134.         mov    bx,parBX
  135.         inc    bx
  136.         inc    bx
  137.         mov    si,es:[bx]
  138.         inc    bx
  139.         inc    bx
  140.         mov    ax,es:[bx]
  141.         mov    ds,ax
  142.         lodsb
  143.         cmp    al,0
  144.         jz    ParEnd
  145.         xor    ah,ah
  146.         mov    cx,ax
  147. Par1:        lodsb
  148.         cmp    al,0
  149.         jz    ParEnd
  150.         cmp    al,0dh
  151.         jz    ParEnd
  152.         call    PutBuff
  153.         loop    Par1
  154. ParEnd:        retn
  155. ;---------------------------------------------------------
  156. PutStr:        mov    ds,parDS
  157.         mov    si,parDX
  158. put1:        lodsb
  159.         cmp    al,0
  160.         jz    StrEnd
  161.         call    PutBuff
  162.         jmp    Put1
  163. StrEnd:        retn
  164. ;---------------------------------------------------------
  165. PutCrLf:    mov    al,0dh
  166.         call    PutBuff
  167.         mov    al,0ah
  168.         call    PutBuff
  169.         retn
  170. ;---------------------------------------------------------
  171. putbuff        proc    near
  172.         mov    bx,cs:[BuffPos]
  173.         inc    bx
  174.         cmp    bx,cs:[BuffSize]
  175.         je    rret
  176.         mov    cs:[BuffPos],bx
  177.         add    bx,offset ResEnd
  178.         dec    bx
  179.         mov    cs:[bx],al
  180. rret:        retn
  181. putbuff        endp
  182. ;-----------------------------------------------------------
  183. ApendTMP    proc    near
  184.         call    SetCrit
  185.         call    DosOK
  186.         jnz    stop
  187.         Call    OpenFile
  188.         JNB    handleOk
  189.         call    CreateFile
  190.         Call    OpenFile
  191.         jc    stop
  192. handleOk:    MOV    BX,AX        ;store file handle
  193.         MOV    AL,02h        ;eof move
  194.         MOV    CX,0        ;file offset
  195.         MOV    DX,0        ;lo(offset)
  196.         MOV    AH,42h        ;set file pointer
  197.         pushf
  198.         call    cs:[Old21]
  199. WriteTMP:    MOV    DX,offset ResEnd
  200.         mov    ax,cs
  201.         mov    ds,ax
  202.         mov    cx,buffpos    ;number of bytes
  203.         MOV    AH,40h        ;write to the file
  204.         pushf
  205.         call    cs:[Old21]
  206.         MOV    AH,3Eh        ;close file
  207.         pushf
  208.         call    cs:[Old21]
  209.         mov    buffpos,0
  210. stop:        call    RestoreCrit
  211.         retn
  212. ApendTMP    ENDP
  213. ;-----------------------------------------------------------
  214. OpenFile    proc    near
  215.         PUSH    CS
  216.         POP    DS
  217.         MOV    DX,offset path
  218.         MOV    AL,1        ;writing
  219.         MOV    AH,3Dh        ;open file handle
  220.         pushf
  221.         call    cs:[Old21]
  222.         ret
  223. OpenFile    endp
  224. ;----------------------------------------------------------
  225. CreateFile    proc    near
  226.         call    DosOK
  227.         jz    CreateCnt
  228.         stc
  229.         ret
  230. CreateCnt:    push    cs
  231.         pop    ds
  232.         MOV    DX,offset path
  233.         MOV    CX,0        ;file attribute
  234.         MOV    AH,5bh        ;create new file
  235.         pushf
  236.         call    cs:[Old21]
  237.         jnb    CreateCnt1
  238.         stc
  239.         ret
  240. CreateCnt1:    MOV    BX,AX        ;store file handle
  241.         MOV    AH,3Eh        ;close file handle
  242.         pushf
  243.         call    cs:[Old21]
  244.         clc
  245.         ret
  246. CreateFile    endp
  247. ;-----------------------------------------------------------
  248. DosOK        proc    near
  249.         PUSH    BX
  250.         PUSH    ES
  251.         LES     BX,cs:[status]
  252.         CMP     BYTE PTR es:[BX],0
  253.         POP     ES
  254.         POP     BX
  255.         RETN
  256. DosOK        ENDP
  257. ;----------------------------------------------------------
  258. SetCrit        proc    near
  259.         pushf
  260.         push    ax
  261.         push    dx
  262.         push    es
  263.         cli
  264.         mov    ax,0
  265.         mov    es,ax
  266.         mov    ax,Word Ptr es:[24h*4]
  267.         mov    Word Ptr cs:[Old24],ax
  268.         mov    ax,Word Ptr es:[24h*4+2]
  269.         mov    Word Ptr cs:[offset Old24 + 2],ax
  270.         mov    ax,cs
  271.         mov    Word Ptr es:[24h*4+2],ax
  272.         mov    ax,offset New24
  273.         mov    Word Ptr es:[24h*4],ax
  274.         mov    ax,3300h
  275.         pushf
  276.         call    cs:Old21    ;get ctrl-break state
  277.         mov    cs:[CtrlC],dl
  278.         sub    dl,dl
  279.         mov    al,1
  280.         pushf
  281.         call    cs:Old21    ;set ctrl-break off
  282.         pop    es
  283.         pop    dx
  284.         pop    ax
  285.         popf
  286.         ret
  287. SetCrit        endp
  288. ;----------------------------------------------------------
  289. RestoreCrit    proc    near
  290.         pushf
  291.         push    ax
  292.         push    dx
  293.         push    es
  294.         cli
  295.         mov    ax,0
  296.         mov    es,ax
  297.         mov    ax,Word Ptr cs:[Old24]
  298.         mov    Word Ptr es:[24h*4],ax
  299.         mov    ax,Word Ptr cs:[offset Old24 + 2]
  300.         mov    Word Ptr es:[24h*4+2],ax
  301.         mov    ax,3301h
  302.         mov    dl,cs:[CtrlC]
  303.         pushf
  304.         call    cs:[Old21]
  305.         pop    es
  306.         pop    dx
  307.         pop    ax
  308.         popf
  309.         ret
  310. RestoreCrit    endp
  311. ;----------------------------------------------------------
  312. Old24        dd    ?
  313. CtrlC        db    ?
  314. ;----------------------------------------------------------
  315. New24        proc    far    ;critical err.
  316.         mov    al,3    ;fail
  317.         mov    Byte Ptr CS:[Off],1
  318.         iret
  319. ;----------------------------------------------------------
  320. New24        endp
  321. ;----------------------------------------------------------
  322. ResEnd        label byte
  323. ;----------------------------------------------------------
  324. prompt        db    'Runtime saving of file actions.',13,10
  325.         db    'ver. 1.04',13,10
  326.         db    'Petr Horák, Praha 1992',13,10
  327.         db    'Usage: kgb [file] [/Options] ..',13,10
  328.         db    'Options:',0dh,0ah
  329.         db    '    /u unload',0dh,0ah
  330.         db    '    /dX drive X (A-Z)',0dh,0ah
  331.         db    '    /on (off)',0dh,0ah,'$'
  332. ;----------------------------------------------------------
  333. UnloadReq    db    0
  334. Default        db    1
  335. ;----------------------------------------------------------
  336. ReadCmdLine:    mov    ax,6200h
  337.         int    21h        ;get PSP address
  338.         mov    ds,bx
  339.         MOV    si,81h
  340.         MOV    cl,Byte Ptr ds:[80h]
  341.         xor    ch,ch
  342. ReadLoop:    call    SkipSpace
  343.         cmp    al,'/'
  344.         jnz    ReadCont
  345.         call    Switch
  346.         jmp    ReadLoop
  347. ReadCont:    cmp    Byte Ptr cs:[Default],0
  348.         je    ReadLoop    ;name
  349.         push    cx
  350.         dec    si
  351.         call    NameSet
  352.         inc    si
  353.         pop    cx
  354.         jmp    ReadLoop
  355. ;----------------------------------------------------------
  356. SkipSpace:    cmp    cx,0
  357.         jz    CmdEnd
  358.         dec    cx
  359.         lodsb            ;al <- ds:[si]
  360.         cmp    al,'/'
  361.         jz    SkipEnd
  362.         cmp    al,0dh
  363.         jz    CmdEnd
  364.         cmp    al,0
  365.         jz    CmdEnd
  366.         cmp    al,' '
  367.         jnz    SkipSpace
  368. SkipSpace1:    cmp    cx,0
  369.         jz    CmdEnd
  370.         dec    cx
  371.         lodsb            ;al <- ds:[si]
  372.         cmp    al,0dh
  373.         jz    CmdEnd
  374.         cmp    al,0
  375.         jz    CmdEnd
  376.         cmp    al,' '
  377.         jz    SkipSpace1
  378. SkipEnd:    ret
  379. ;----------------------------------------------------------
  380. CmdEnd:        pop    ax
  381.         ret
  382. ;----------------------------------------------------------
  383. Switch:        cmp    cx,0
  384.         jz    CmdEnd
  385.         lodsb
  386.         dec    cx
  387.         cmp    al,'u'
  388.         jnz    Read4
  389.         mov    cs:[UnloadReq],1
  390.         jmp    CmdEnd
  391. Read4:        cmp    al,'d'
  392.         jnz    Read5
  393.         cmp    cs:[Default],0
  394.         jz    Read5
  395.         call    DriveSet
  396.         ret
  397. Read5:        cmp    al,'o'
  398.         jnz    Read6
  399.         call    OnOffSet
  400. Read6:        ret
  401. ;----------------------------------------------------------
  402. OnOffSet:    mov    al,ds:[si]
  403.         cmp    al,'f'
  404.         jnz    R6
  405.         mov    Byte Ptr cs:[Off],1
  406. R6:        ret
  407. ;----------------------------------------------------------
  408. DriveSet:    mov    al,ds:[si]
  409.         and    al,0dfh
  410.         cmp    al,'A'
  411.         jb    DriveSetRet
  412.         cmp    al,'Z'
  413.         ja    DriveSetRet
  414.         mov    cs:Path,al
  415.         mov    cs:[Default],0
  416. DriveSetRet:    ret
  417. ;----------------------------------------------------------
  418. NameSet:    push    cs
  419.         pop    es
  420.         mov    di,offset Path
  421.         call    FExpand
  422.         mov    cs:[Default],0
  423. NameSetRet:    ret
  424. ;----------------------------------------------------------
  425. FExpand        PROC
  426.             push    si    ;preserve calling program's register
  427.         push    di    ;variable, if any
  428.         cld
  429.         xor    cx,cx
  430.         push    si
  431. StringCountLoop:
  432.         lodsb        ;get the next character
  433.         and    al,al
  434.         jz      EndStringCount
  435.         cmp    al,0dh
  436.         jz      EndStringCount
  437.         cmp    al,0ah
  438.         jz      EndStringCount
  439.         cmp    al,' '
  440.         jz      EndStringCount
  441.         cmp    al,'/'
  442.         jz      EndStringCount
  443.         inc     cx 
  444.         jmp     StringCountLoop
  445. EndStringCount: pop    si
  446.         add    cx,si
  447.         lodsw
  448.         cmp    si,cx
  449.         ja     GetDrive
  450.         cmp    ah,3Ah
  451.         jne    GetDrive
  452.         cmp    al,'a'
  453.         jb     o33
  454.         cmp    al,'z'
  455.         ja     o33
  456.         sub    al,' '
  457.         jmp    o33
  458. GetDrive:    dec    si
  459.         dec    si
  460.         mov    ah,19h    ;get drive
  461.         int    21h
  462.         add    al,'A'
  463.         mov    ah,':'
  464. o33:        stosw
  465.         cmp    si,cx
  466.         je     GetPath
  467.         cmp    byte ptr [si],'\'
  468.         je     o65
  469. GetPath:    sub    al,40h
  470.         mov    dl,al
  471.         mov    al,'\'
  472.         stosb
  473.         push   si
  474.         push   ds
  475.         mov    ah,47h
  476.         mov    si,di
  477.         push   es
  478.         pop    ds
  479.         int    21h    ;get dir
  480.         pop    ds
  481.         pop    si
  482.         jb     o65
  483.         cmp    es:byte ptr [di],00
  484.         je     o65
  485.         push   cx
  486.         mov    cx,0FFFFh
  487.         xor    al,al
  488.         repnz scasb
  489.         dec    di
  490.         mov    al,'\'
  491.         stosb
  492.         pop    cx
  493. o65:        sub    cx,si
  494.         rep movsb
  495.         xor    al,al
  496.         stosb
  497. o6C:        pop    di    ;restore si, di
  498.         pop    si
  499.         push    si    ;and move back
  500.         push    di    ;on stack
  501.         mov    di,si
  502. o73:        lodsb
  503.         or     al,al
  504.         je     o89
  505.         cmp    al,'\'
  506.         je     o89
  507.         cmp    al,'a'
  508.         jb     o86
  509.         cmp    al,'z'
  510.         ja     o86
  511.         sub    al,20h
  512. o86:        stosb
  513.         jmp    o73
  514. o89:        cmp    word ptr [di-02],2E5Ch    ;'.\'
  515.         jne    o94
  516.         dec    di
  517.         dec    di
  518.         jmp    oB0
  519. o94:        cmp    word ptr [di-02],2E2Eh    ;'..'
  520.         jne    oB0
  521.         cmp    byte ptr [di-03],'\'
  522.         jne    oB0
  523.         sub    di,3
  524.         cmp    byte ptr [di-01],':'
  525.         je     oB0
  526. oAA:        dec    di
  527.         cmp    byte ptr [di],'\'
  528.         jne    oAA
  529. oB0:        or     al,al
  530.         jne    o86
  531.         cmp    byte ptr [di-01],':'
  532.         jne    oBD
  533.         mov    al,'\'
  534.         stosb
  535. oBD:;        mov    ax,di
  536.         xor    al,al
  537.         stosb
  538.         pop    di    ;restore calling si, di
  539.         pop    si
  540.         ret
  541. FExpand        ENDP
  542. ;----------------------------------------------------------
  543. Start        PROC
  544.         Call    ReadCmdLine
  545.         MOV    AH,34h   ;dos reentrancy status adress
  546.         INT    21h
  547.         MOV    word ptr cs:[status+2],ES
  548.         MOV    word ptr cs:[status],BX
  549.         mov    dx,offset prompt
  550.         call    DisplayString
  551.         call    FindSec
  552. InstCont:    mov    ax,3521h
  553.         int    21h
  554.         mov    word ptr cs:Old21,bx
  555.         mov    word ptr cs:Old21[2],es
  556.         mov    ax,2521h
  557.         push    cs
  558.         pop    ds
  559.         mov    dx,offset IntHandler
  560.         int    21h
  561. Residence:    mov    ah,62h        ;get PSP
  562.         int    21h
  563.         mov    cs:[MyPSP],bx
  564.         mov    ds,bx
  565.         mov    ah,49h        ;free alocated mem bl
  566.         mov    es,ds:[2ch]    ;addr. dos enviroment
  567.         int    21h        ;free dos enviroment
  568.         mov    dx,ResEnd-ResBeg+100h
  569.         add    dx,cs:[BuffSize]
  570.         mov    cl,4
  571.         shr    dx,cl
  572.         inc    dx
  573.         mov    ax,3100h
  574.         int    21h
  575. Start        ENDP
  576. ;-----------------------------------------------------------
  577. KantUnload    db    'Second Call, can''t uninstall.',13,10,'$'
  578. Unloadet    db    'Second Call, uninstaled.',13,10,'$'
  579. MadeChanges    db    'Second Call, made changes.',13,10,'$'
  580. FindSec        proc    near
  581.         clc
  582.         mov    ax,0c6c6h
  583.         int    21h
  584.         jnb    FindSec1
  585.         cmp    cs:[UnloadReq],1
  586.         je    Unload
  587.         mov    cx,1
  588.         cmp    cs:[Default],1
  589.         je    o8
  590.         mov    cx,129    ;délka path+off
  591. o8:        push    cs
  592.         pop    ds
  593.         mov    es,ax    ;resident cs
  594.         mov    si,offset Off
  595.         mov    di,si
  596.         repnz    movsb
  597.         mov    dx,offset MadeChanges
  598.         jmp    SecDone
  599. Unload:        push    ax
  600.         mov    ax,3521h
  601.         int    21h
  602.         pop    ax
  603.         mov    cx,es
  604.         cmp    ax,cx
  605.         jne    o3
  606.         cmp    bx,offset IntHandler
  607.         jne    o3
  608.         mov    ax,2521h
  609.         lds    dx,es:[Old21]
  610.         int    21h
  611.         mov    ax,es:[MyPSP]
  612.         mov    es,ax
  613.         mov    ah,49h        ;free mem. bl.
  614.         int    21h
  615.         jc    o3
  616.         mov    dx,offset Unloadet
  617.         jmp    SecDone
  618. o3 :        mov    dx,offset KantUnload
  619. SecDone:    call    DisplayString
  620.         mov    ax,4c00h    ;exit while found
  621.         int    21h
  622. FindSec1:    retn
  623. FindSec        endp
  624. ;----------------------------------------------------------
  625. DisplayString:    mov    ax,cs
  626.         mov    ds,ax
  627.         mov    ah,9    ;display message
  628.         int    21h
  629.         ret
  630. ;----------------------------------------------------------
  631.         END    Start
  632. ;----------------------------------------------------------
  633.