home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / fwktl101.zip / SELFWRIT.1 < prev    next >
Text File  |  1996-05-28  |  5KB  |  170 lines

  1.  
  2.  
  3.         TITLE   SELFWRIT
  4.         NAME    SELFWRIT
  5.         .386
  6.         .387
  7.  
  8. ; Part of the FWKTL(TM) Text_program Launcher kit, version 1.01.
  9. ; (C)Copyright Frederick W. Kantor 1996. All rights reserved.
  10.  
  11. ; this program can store up to 32 bytes from its command tail in an
  12. ; internal array, and then overwrite its program file with that new
  13. ; material, or can display what it has currently in that array
  14. ; Usage:  FWKTL SELFWRIT.COM <enter>  to display current array contents
  15. ;         FWKTL SELFWRIT.COM string to load/w <enter>  to revise contents
  16.  
  17. PSETUP EQU 01     ; = 1  include address for SHOW utility
  18.  
  19. USE32             ; for A386 flat, protected_mode, 32_bit code.
  20.  
  21. ; structure for initial data:
  22.  
  23. P_ STRUC
  24. P_LOADEDAT DD ?   ; start of this memory block
  25. P_PWHENCE DD ?    ; points to ASCIIZ string re where program was found
  26. P_PCOMTAIL DD ?   ; points to ASCIIZ command tail
  27. P_GETFN DD ?      ; address for indirect call to FWKTL GETFN function:
  28. P_GETFNLIST DD ?  ; address for indirect call to FWKTL GETFNLIST
  29. P_HDOSCALLS DD ?  ; handle for DOSCALLS module as loaded by FWKTL,
  30. #IF PSETUP EQ 1
  31. P_SHOW DD ?        ; address for FWKTL SHOW function;
  32. P_USWORDCAPS DD ?  ; address for FWKTL capitalization function;
  33. #ENDIF ; PSETUP EQ 1
  34.  
  35. P_WROTE DD ?       ; used with the DOS32WRITE API
  36. P_HNL   DD ?       ; file handle
  37.  
  38. P_WRITE DD ?
  39. P_CLOSE DD ?
  40. P_OPEN  DD ?
  41.  
  42. P_ ENDS
  43.  
  44. CODESTART:   ; used as a reference point
  45.  
  46. RET          ; 4_byte header identification string
  47. DB 'FWK'     ;
  48. DD PSETUP    ; style
  49. DD TYPE P_   ; amount of free memory requested after code
  50. JMP >L0      ; execution entry point.
  51.  
  52. STORAGE:
  53. OSTORAGE EQU $-CODESTART
  54. DB 020H DUP 00
  55. LSTORAGE EQU $-STORAGE
  56. DB 00
  57.  
  58. FNLIST:                 ; list of procedures (DOSCALLS ordinals).
  59. OFNLIST EQU $-CODESTART ; offset used for finding FNLIST in memory.
  60. ; these decimal number WORDs are in the same order
  61. ; as their corresponding DD targets in P_ STRUC
  62.         ;                      decimal ordinals
  63. DW 282  ;   DOS32WRITE          (DOSCALLS.282)
  64. DW 257  ;   DOS32CLOSE          (DOSCALLS.257)
  65. DW 273  ;   DOS32OPEN           (DOSCALLS.273)
  66. NFNLIST EQU ($-FNLIST)/2 ; number of items in FNLIST
  67.  
  68. L0:                       ; target for JMP from entry point
  69.  
  70. PUSH EBX                  ; save EBX value
  71. MOV EBP,ESP               ; save ESP value in EBP
  72. REP MOVSD                 ; load EBX:P_ STRUC
  73.  
  74. MOV ESI,[EBX].P_LOADEDAT  ; calculate position of start of FNLIST
  75. ADD ESI,OFNLIST           ;   procedure list
  76. LEA EDI,[EBX].P_WRITE     ; point EDI at address array
  77. MOV EAX,02                ; FNLIST list contains 2_byte ordinals
  78. MOV ECX,NFNLIST           ; number of items in list
  79. MOV EDX,[EBX].P_HDOSCALLS ; use handle for DOSCALLS module,
  80. CALL [EBX].P_GETFNLIST    ; get addresses for procedures in list
  81.  
  82. MOV ESI,[EBX].P_PCOMTAIL  ; search command tail for /W
  83. MOV EDI,ESI
  84. MOV ECX,0200H
  85. XOR EAX,EAX               ; find terminal 00
  86. REPNE SCASB               ;
  87. MOV ECX,EDI
  88. DEC EDI                   ;
  89. MOV AL,'/'
  90. SUB ECX,ESI
  91. STD
  92. REPNE SCASB
  93. CLD
  94. JNE >L2                   ; if no '/', then jmp to SHOW
  95.  
  96. INC EDI
  97. MOV B[EDI],00             ; terminate ASCIIZ string
  98.  
  99. PUSH ESI
  100. MOV ESI,EDI
  101. INC ESI
  102. CALL [EBX].P_USWORDCAPS   ; capitalize
  103. CMP B[ESI],'W'
  104. POP ESI
  105. JNE >L2                   ; if not /W, then skip to use SHOW
  106.  
  107. MOV ECX,EDI
  108. SUB ECX,ESI
  109. MOV EDI,LSTORAGE
  110. CMP ECX,EDI
  111. JNA >L0
  112. MOV ECX,EDI
  113. L0:
  114.  
  115. MOV EDI,[EBX].P_LOADEDAT ; point to STORAGE
  116. ADD EDI,OSTORAGE         ;
  117. PUSHAD                   ; save values
  118. MOV ECX,LSTORAGE         ; clear STORAGE
  119. XOR EAX,EAX              ;
  120. REP STOSB                ;
  121. POPAD                    ; restore values
  122.  
  123. REP MOVSB                ; copy into STORAGE
  124.  
  125. PUSHD 0                  ; for opening an existing file
  126. PUSHD 042H               ; bits 6-4  = 100 = 4h OPEN_SHARE_DENYNONE
  127.                          ; bits 2-0  = 010 = 2h OPEN_ACCESS_READWRITE
  128. PUSHD 1H                 ; OPEN_ACTION_OPEN_IF_EXISTS
  129. PUSHD 7H                 ; FILE_SYSTEM | FILE_HIDDEN | FILE_READONLY
  130. PUSHD 0                  ; for opening an existing file
  131. LEA EAX,[EBX].P_WROTE    ; pDWORD for report
  132. PUSHD EAX
  133. LEA EAX,[EBX].P_HNL      ; where to save file handle
  134. PUSHD EAX
  135. PUSHD [EBX].P_PWHENCE    ; ASCIIZ d:\path\filename.ext
  136. CALL [EBX].P_OPEN        ; open
  137. TEST EAX,EAX             ; test
  138. JNZ BADEXIT              ; leave if bad
  139.  
  140. MOV EBX,[EBP]
  141.                          ; overwrite program file
  142. LEA EAX,[EBX].P_WROTE    ; pDWORD for amount written
  143. PUSHD EAX                ;
  144. PUSHD CODE_END-CODESTART ; amount to write
  145. PUSHD [EBX].P_LOADEDAT   ; push address of beginning of program
  146. PUSHD [EBX].P_HNL        ; use file handle
  147. CALL [EBX].P_WRITE       ; indirect call to DOS32WRITE to write message
  148.  
  149. MOV EBX,[EBP]            ;
  150.  
  151. PUSHD [EBX].P_HNL        ; close file handle
  152. CALL [EBX].P_CLOSE       ;
  153.  
  154. JMP SHORT EXIT
  155.  
  156. L2:
  157. MOV ESI,[EBX].P_LOADEDAT  ; display existing ASCIIZ string
  158. ADD ESI,OSTORAGE
  159. CALL [EBX].P_SHOW
  160.  
  161. EXIT:
  162. XOR EAX,EAX               ; set exit errorlevel = 0
  163.  
  164. BADEXIT:
  165. MOV ESP,EBP               ; clear STACK
  166. POP EBX                   ;
  167. RET                       ; return to FWKTL
  168. ;---------------------------
  169. CODE_END EQU $
  170.