home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / ARTFIX04.ZIP / NETMGR / NETMGR.ASM < prev    next >
Encoding:
Assembly Source File  |  1999-08-16  |  13.9 KB  |  478 lines

  1. ; Netmgr.Asm written 1999 by Tobias Ernst.
  2. ;
  3. ; This file installs interrupt service handlers that are needed by the
  4. ; patched NetMgr executable and then spawns the patched Netmgr executable,
  5. ; and afterwards deinstalls the interrupt service handlers. The patched
  6. ; Netmgr executable is expected to have the name "netmgr.ovl" and reside
  7. ; in the same directory as the netmgr.com file that is assembled from
  8. ; netmgr.asm.
  9. ;
  10. ; This file is written for Borland TASM, but should also work with
  11. ; microsoft MASM and compatible assemblers, though I didn't test it.
  12. ; Assemble as follows:
  13. ;
  14. ; tasm netmgr.asm
  15. ; tlink netmgr /t
  16. ;
  17. ; If you use another linker, assure that a .COM file is generated, or
  18. ; convert the EXE file with EXE2BIN. It is important that the file is
  19. ; a .COM file!
  20.  
  21. DGROUP group  _TEXT, _DATA
  22.  
  23. _TEXT        SEGMENT BYTE PUBLIC 'CODE'
  24.         ASSUME CS: DGROUP, DS:DGROUP, SS:DGROUP
  25.  
  26. org             0100h
  27. start:          jmp main
  28.  
  29.  
  30. ; Symbolic contants for the interrupt vectors to use
  31.  
  32. vector1         equ 04Bh
  33. vector2         equ 04Ch
  34. vector3         equ 04Dh
  35. vector4         equ 04Eh
  36.  
  37.  
  38. ;  Interrupt Service Routine #1
  39. ;  Function: - Get a two digit year number from [bp-10h] to AX
  40. ;            - Convert AX to a "tm.tm_year" compatible year number, that
  41. ;              is, the number of years that have passed since 1900.
  42. ;  Purpose:  This routine is called when reading in a message from the
  43. ;            Hudson Message Base. HMB only has a two digit year field,
  44. ;            so we have to interpret a two digit year number somehow.
  45. ;            Here, we assume that a year number of 00..79 is in 20xx,
  46. ;            while a year number of 80..99 is in 19xx. This makes HMB
  47. ;            save until 12/31/2079.
  48. service1:
  49.  
  50.        mov ax, word ptr [bp-10h]
  51.        cmp ax, 80d    ; is ax >= 80
  52.        jae twc2       ; if so ->   19xx
  53.        add ax, 100d   ; otherwise: 20xx, add 100 dec
  54. twc2:  iret
  55.  
  56.  
  57. ;  Interrupt Service Routines #2
  58. ;  Function:  Get a year number in tm.tm_year format from [si+0a],
  59. ;             and push the modulo of the division of this number by 100
  60. ;             to the stack.
  61. ;  Notes:     As an interrupt normally does not leave anything on the
  62. ;             stack, this code looks a bit unconventional
  63. ;  Purpose:   This routine is called when writing a FTSC date stamp into
  64. ;             a PKT file, or when creating a textual header represenatation
  65. ;             (in boundes, forwards, etc) and prevents the 2 digit date
  66. ;             field from spilling  (without the modulo 100 operation, "100"
  67. ;             would be written there in the year 2000 instead of 00).
  68.  
  69. service2:       mov cs:[tmpax],ax      ;save AX
  70.  
  71.                 pop ax                 ;get the return address from stack
  72.                 mov cs:[retadd1],ax
  73.                 pop ax
  74.                 mov cs:[retadd2],ax
  75.                 pop ax
  76.                 mov cs:[retadd3],ax
  77.  
  78.                 mov ax, word ptr[si+0ah]
  79.                 push cx
  80.                 mov cl, 064h          ; only pass the modulo 100 value
  81.                 idiv cl               ; to sprintf
  82.                 pop cx
  83.                 mov al,ah
  84.                 xor ah,ah
  85.                 push ax
  86.  
  87.                 push cs:[retadd3]      ;Now jump back
  88.                 push cs:[retadd2]
  89.                 push cs:[retadd1]
  90.                 mov ax,cs:[tmpax]
  91.                 iret
  92.  
  93. tmpax           dw 0
  94. retadd1         dw 0
  95. retadd2         dw 0
  96. retadd3         dw 0
  97.  
  98. ;  Interrupt Service Routines #3
  99. ;  Function:  Get a year number in tm.tm_year format from [bx+0a],
  100. ;             and push the modulo of the division of this number by 100
  101. ;             to the stack.
  102. ;  Notes:     As an interrupt normally does not leave anything on the
  103. ;             stack, this code looks a bit unconventional
  104. ;  Purpose:   This routine is called when writing a FTSC date stamp
  105. ;             into a *.squish or *.msg base, and when writing a hudson
  106. ;             time stamp. It prevents the 2 digit date field from spilling
  107. ;             (without the modulo 100 operation, "100" would be written
  108. ;             there in the year 2000 instead of 00).
  109.  
  110. service3:       mov cs:[tmp2ax],ax      ;save AX
  111.  
  112.                 pop ax                 ;get the return address from stack
  113.                 mov cs:[ret2add1],ax
  114.                 pop ax
  115.                 mov cs:[ret2add2],ax
  116.                 pop ax
  117.                 mov cs:[ret2add3],ax
  118.  
  119.                 mov ax, word ptr[bx+0ah]
  120.                 push cx
  121.                 mov cl, 064h          ; only pass the modulo 100 value
  122.                 idiv cl               ; to sprintf
  123.                 pop cx
  124.                 mov al,ah
  125.                 xor ah,ah
  126.                 push ax
  127.  
  128.                 push cs:[ret2add3]      ;Now jump back
  129.                 push cs:[ret2add2]
  130.                 push cs:[ret2add1]
  131.                 mov ax,cs:[tmp2ax]
  132.                 iret
  133.  
  134. tmp2ax           dw 0
  135. ret2add1         dw 0
  136. ret2add2         dw 0
  137. ret2add3         dw 0
  138.  
  139. ;  Interrupt Service Routines #4
  140. ;  Function:  Get a year number in tm.tm_year format from [bx+0a],
  141. ;             and push the modulo of the division of this number by 100
  142. ;             to the stack.
  143. ;  Notes:     As an interrupt normally does not leave anything on the
  144. ;             stack, this code looks a bit unconventional
  145. ;  Purpose:   This routine is called when writing a FTSC date stamp
  146. ;             into a *.squish or *.msg base, and when writing a hudson
  147. ;             time stamp. It prevents the 2 digit date field from spilling
  148. ;             (without the modulo 100 operation, "100" would be written
  149. ;             there in the year 2000 instead of 00).
  150.  
  151. service4:       mov cs:[tmp3ax],ax       ;save AX
  152.  
  153.                 pop ax                   ;get the return address from stack
  154.                 mov cs:[ret3add1],ax
  155.                 pop ax
  156.                 mov cs:[ret3add2],ax
  157.                 pop ax
  158.                 mov cs:[ret3add3],ax
  159.  
  160.                 mov ax, word ptr[bx+0ah] ;get tm->tm_year
  161.                 add ax, 1900d            ;convert to 4 digit year
  162.                 push ax
  163.  
  164.                 push cs:[ret3add3]       ;Now jump back
  165.                 push cs:[ret3add2]
  166.                 push cs:[ret3add1]
  167.                 mov ax,cs:[tmp3ax]
  168.                 iret
  169.  
  170. tmp3ax           dw 0
  171. ret3add1         dw 0
  172. ret3add2         dw 0
  173. ret3add3         dw 0
  174.  
  175.  
  176.  
  177.  
  178.  
  179. ; The main program. These routines install the correct interrupt handlers,
  180. ; execute timed.ovl, and restore the original interrupt handlers. This code
  181. ; is fairly uninteresting.
  182.  
  183. main:
  184.                 mov ax, cs         ; set up the segment registers and stack
  185.                 mov ds, ax
  186.                 mov ss, ax
  187.                 mov es, ax
  188.                 mov ax, offset DGROUP:stack_high
  189.                 mov sp, ax
  190.  
  191.                                    ; free unneeded memory
  192.                 mov bx, offset DGROUP:highwater
  193.                 shr bx, 4
  194.                 inc bx
  195.                 mov ah, 4Ah
  196.                 int 21h
  197.  
  198.                                    ; store the old interrupt vectors
  199.                 mov ah, 35h
  200.                 mov al, vector1
  201.                 int 21h
  202.                 mov [oldofs1],bx
  203.                 mov [oldseg1],es
  204.  
  205.                 mov ah, 35h
  206.                 mov al, vector2
  207.                 int 21h
  208.                 mov [oldofs2],bx
  209.                 mov [oldseg2],es
  210.  
  211.                 mov ah, 35h
  212.                 mov al, vector3
  213.                 int 21h
  214.                 mov [oldofs3],bx
  215.                 mov [oldseg3],es
  216.  
  217.                 mov ah, 35h
  218.                 mov al, vector4
  219.                 int 21h
  220.                 mov [oldofs4],bx
  221.                 mov [oldseg4],es
  222.  
  223.  
  224.                                   ; set the new interrupt vectors
  225.                 mov ah,25h
  226.                 mov al, vector1
  227.                 mov dx, offset DGROUP:service1
  228.                 int 21h
  229.  
  230.                 mov ah,25h
  231.                 mov al, vector2
  232.                 mov dx, offset DGROUP:service2
  233.                 int 21h
  234.  
  235.                 mov ah,25h
  236.                 mov al, vector3
  237.                 mov dx, offset DGROUP:service3
  238.                 int 21h
  239.  
  240.                 mov ah,25h
  241.                 mov al, vector4
  242.                 mov dx, offset DGROUP:service4
  243.                 int 21h
  244.  
  245.                                    ; prepare the call to stringops
  246.                 push ds
  247.                 mov ax, offset DGROUP:paramoff
  248.                 push ax
  249.                 push ds
  250.                 mov ax, offset DGROUP:paramseg
  251.                 push ax
  252.                 push ds
  253.                 mov ax, offset DGROUP:prognameoff
  254.                 push ax
  255.                 push ds
  256.                 mov ax, offset DGROUP:prognameseg
  257.                 push ax
  258.  
  259.                 mov ah,062h        ; get PSP
  260.                 int 21h
  261.                 push bx
  262.                 xor  ax,ax
  263.                 push ax
  264.  
  265.                 call _stringops    ; fill in the various structures
  266.                 add sp, 014h
  267.  
  268.  
  269.                 mov ax, [paramseg] ; call the DOS EXEC function
  270.                 mov es, ax
  271.                 mov bx, [paramoff]
  272.                 mov dx, [prognameoff]
  273.                 mov ax, [prognameseg]
  274.                 mov ds, ax
  275.                 mov ax, 04B00h
  276.                 int 21h
  277.  
  278.                 mov ax, cs         ; restore the registers
  279.                 mov ds, ax
  280.                 mov ss, ax
  281.                 mov ax, offset DGROUP:stack_high
  282.                 mov sp, ax
  283.  
  284.  
  285.                                         ; restore the interrupt vectors
  286.                 mov bx, ds
  287.                 mov ah, 25h
  288.                 mov al, vector1
  289.                 mov dx, [oldofs1]
  290.                 mov cx, [oldseg1]
  291.                 mov ds, cx
  292.                 int 21h
  293.                 mov ds, bx
  294.  
  295.                 mov bx, ds
  296.                 mov ah, 25h
  297.                 mov al, vector2
  298.                 mov dx, [oldofs2]
  299.                 mov cx, [oldseg2]
  300.                 mov ds, cx
  301.                 int 21h
  302.                 mov ds, bx
  303.  
  304.                 mov bx, ds
  305.                 mov ah, 25h
  306.                 mov al, vector3
  307.                 mov dx, [oldofs3]
  308.                 mov cx, [oldseg3]
  309.                 mov ds, cx
  310.                 int 21h
  311.                 mov ds, bx
  312.  
  313.                 mov bx, ds
  314.                 mov ah, 25h
  315.                 mov al, vector4
  316.                 mov dx, [oldofs4]
  317.                 mov cx, [oldseg4]
  318.                 mov ds, cx
  319.                 int 21h
  320.                 mov ds, bx
  321.  
  322.  
  323.                 mov ah, 04dh     ; query return code of the .OVL module
  324.                 int 21h
  325.                 mov ax, 04ch     ; terminate program
  326.                 int 21h
  327.  
  328.  
  329. ; _stringops
  330. ; This function fills in the huge bunch of tables that is required for the
  331. ; DOS exec function. It looks a bit weired, because it has originally been
  332. ; created by a C compiler.
  333.  
  334. _stringops    proc    near
  335.     push    bp
  336.     mov    bp,sp
  337.     sub    sp,12
  338.     push    si
  339.     push    di
  340.  
  341.  
  342.    ;        /* pass the command line on as is */
  343.     les    bx,dword ptr [bp+4]
  344.     mov    al,byte ptr es:[bx+128]
  345.     mov    byte ptr DGROUP:_cmdlin,al
  346.     cmp    byte ptr DGROUP:_cmdlin,126
  347.     jle    short @1@534
  348.     mov    byte ptr DGROUP:_cmdlin,126
  349. @1@534:
  350.     xor    si,si
  351.     jmp    short @1@618
  352. @1@562:
  353.     les    bx,dword ptr [bp+4]
  354.     add    bx,si
  355.     mov    al,byte ptr es:[bx+129]
  356.     mov    byte ptr DGROUP:_cmdlin[si+1],al
  357.     inc    si
  358. @1@618:
  359.     mov    al,byte ptr DGROUP:_cmdlin
  360.     cbw
  361.     cmp    ax,si
  362.     jg    short @1@562
  363.     mov    byte ptr DGROUP:_cmdlin[si+1],13
  364.  
  365.    ;        /* adjust the name of the file to be spawned in the env_block */
  366.     les    bx,dword ptr [bp+4]
  367.     mov    ax,word ptr es:[bx+44]
  368.     mov    word ptr [bp-2],ax
  369.     mov    word ptr [bp-4],0
  370.     mov    ax,word ptr [bp-2]
  371.     mov    dx,word ptr [bp-4]
  372.     mov    word ptr [bp-6],ax
  373.     mov    word ptr [bp-8],dx
  374.     jmp    short @1@702
  375. @1@674:
  376.     inc    word ptr [bp-8]
  377. @1@702:
  378.     les    bx,dword ptr [bp-8]
  379.     cmp    byte ptr es:[bx],1
  380.     jne    short @1@674
  381.     les    bx,dword ptr [bp-8]
  382.     cmp    byte ptr es:[bx+1],0
  383.     jne    short @1@674
  384.  
  385.     mov    ax,word ptr [bp-6]
  386.     mov    dx,word ptr [bp-8]
  387.     add    dx,2
  388.     mov    word ptr [bp-10],ax
  389.     mov    word ptr [bp-12],dx
  390.     mov    word ptr [bp-6],ax
  391.     mov    word ptr [bp-8],dx
  392.     jmp    short @1@814
  393. @1@786:
  394.     inc    word ptr [bp-8]
  395. @1@814:
  396.     les    bx,dword ptr [bp-8]
  397.     cmp    byte ptr es:[bx],0
  398.     jne    short @1@786
  399.     les    bx,dword ptr [bp-8]
  400.     mov    byte ptr es:[bx-3],79
  401.     les    bx,dword ptr [bp-8]
  402.     mov    byte ptr es:[bx-2],86
  403.     les    bx,dword ptr [bp-8]
  404.     mov    byte ptr es:[bx-1],76
  405.    ;        /* fill in the parameter block */
  406.     mov    ax,word ptr [bp-2]
  407.     mov    word ptr DGROUP:_paramblock,ax
  408.     mov    word ptr DGROUP:_paramblock+2,offset DGROUP:_cmdlin
  409.     mov    word ptr DGROUP:_paramblock+4,ds
  410.     mov    word ptr DGROUP:_paramblock+6,offset DGROUP:_fcb2
  411.     mov    word ptr DGROUP:_paramblock+8,ds
  412.     mov    word ptr DGROUP:_paramblock+10,offset DGROUP:_fcb2
  413.          mov    word ptr DGROUP:_paramblock+12,ds
  414.     les    bx,dword ptr [bp+16]
  415.     mov    word ptr es:[bx],ds
  416.     les    bx,dword ptr [bp+20]
  417.     mov    word ptr es:[bx],offset DGROUP:_paramblock
  418.     les    bx,dword ptr [bp+8]
  419.     mov    ax,word ptr [bp-10]
  420.     mov    word ptr es:[bx],ax
  421.     les    bx,dword ptr [bp+12]
  422.     mov    ax,word ptr [bp-12]
  423.     mov    word ptr es:[bx],ax
  424.     pop    di
  425.     pop    si
  426.     mov    sp,bp
  427.     pop    bp
  428.     ret
  429. _stringops    endp
  430.  
  431.  
  432. _TEXT ENDS
  433.  
  434. _DATA        SEGMENT WORD PUBLIC 'DATA'
  435.  
  436.  
  437. ; These variables store the old interrupt vectors
  438. oldseg1      dw ?
  439. oldofs1      dw ?
  440. oldseg2      dw ?
  441. oldofs2      dw ?
  442. oldseg3      dw ?
  443. oldofs3      dw ?
  444. oldseg4      dw ?
  445. oldofs4      dw ?
  446.  
  447.  
  448. ; These variables are used to exchange data between the main program
  449. ; and the _stringops subroutine
  450. paramoff    dw 1
  451. paramseg    dw 2
  452. prognameoff dw 3
  453. prognameseg dw 4
  454.  
  455. ; We do need a little bit of stack for our own ...
  456. stack_low       dw 128 dup (10)
  457. stack_high      dw 0
  458.  
  459.  
  460. ; These structures are filled in and passed to the DOS EXEC function
  461. _cmdlin    label    byte
  462.     db    128 dup (0)
  463. _paramblock    label    word
  464.     db    16 dup (0)
  465. _fcb2    label    word
  466.     db    35 dup (0)
  467. _fcb1    label    word
  468.     db    35 dup (0)
  469.  
  470. ; This variable marks the last address in the file, so that the rest
  471. ; of the memory can be freed.
  472. highwater db 0
  473.  
  474. _DATA ENDS
  475.  
  476. END start
  477.  
  478.