home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / ASSEMBLE / EXLITE2 / EXLITE2.ASM < prev    next >
Assembly Source File  |  1992-04-08  |  6KB  |  195 lines

  1. ; ExLite, by Inbar Raz, Jan. 12th, 1992.
  2. ; From the FIDO PC Assembly Language Echo
  3. ; Origin: Inbar's Point, Yavne, ISRAEL. True ZMailH Point. (2:403/123.5)
  4. ;
  5. ; Run: ExLite <filename>.
  6. ; Produces a decompressed program EXLITED.COM (which you can rename
  7. ; as desired).
  8. ;
  9. ; This program is hard-coded to uncompress PKLITE'ed .COM files.
  10. ; It scans the PKLITE decompressor code for a 'MOV DI,AX' and replaces it
  11. ; with INT3. Before that instruction is executed, DI holds
  12. ; the filesize+100, so that gives us the file size.
  13. ; The new int3 service code imply writes the uncompressed program to disk.
  14. ; This will NOT work with .EXE files (which require relocation tables).
  15.  
  16. ;v1.2    Toad Hall, 8 Apr 92
  17. ; - Got approval from author to release to public domain.
  18. ; - Added slight documentation.
  19. ; - Minor tweaks.
  20. ;v1.1    Toad Hall Tweak, 25 Mar 92
  21. ; - Insured CS: overrides where required (just to keep the assembler
  22. ;   and programmers informed).
  23. ; - Significant tightening
  24. ; - Per EMail messages with the author, Inbar Raz,
  25. ;   this program is released to the public domain.
  26. ;   Please do not remove the author's credits.
  27. ;
  28. ; David Kirschbaum
  29. ; Toad Hall
  30. ; kirsch@usasoc.soc.mil
  31.  
  32. CSEG    SEGMENT
  33.     ASSUME    cs:CSEG, ds:CSEG
  34.     ORG    0
  35. progstart equ    $            ;for computing program length    v1.1
  36.     ORG    100h
  37.  
  38. ExLite:  jmp    Begin            ;v1.1
  39.  
  40. oldInt3 dd    0
  41. NewName db    'EXLITED.COM', 0
  42. NoFile_ db    'No file specified$'                    ;v1.1
  43. BadName_ db     'Bad file name, or file name can not be opened$'    ;v1.1
  44. NotLite_ db     'File is not compressed under PKLite or is of '
  45.     db    'unknown version of PKlite$'                ;v1.1
  46. ReadErr_ db    'Error reading source file$'                ;v1.1
  47. CantCreat_ db    'Error creating destination file'            ;v1.1
  48. Abort_    db    '.',0DH,0AH,'Program aborting.$'            ;v1.2
  49.  
  50. ;New INT 3 server writes decompressed program code out to file.
  51. NewInt3:
  52.     mov    ax,cs
  53.     mov    ds,ax
  54.     ASSUME    DS:CSEG            ;v1.1
  55.  
  56.     mov    ax,3C00h        ; Create file
  57.     mov    cx,20H            ;file attribute            v1.1
  58.     mov    dx,offset NewName    ;'EXLITED.COM'
  59.     int    21h
  60.     jb    CantCreat        ;create failed
  61.     mov    bx,ax            ;into BX for upcoming write    v1.1
  62.     mov    ax,es
  63.     mov    ds,ax
  64.     ASSUME    DS:NOTHING        ;Actually, the seg of the    v1.1
  65.                     ;decompressed file
  66.     mov    ah,40h            ; Write file
  67.     mov    cx,di            ;program length
  68.     mov    dx,100h            ;write from .COM program onward
  69.     sub    cx,dx        ;100H    ;minus PSP length        v1.1
  70.     int    21h
  71.     jb    CantCreat        ;write error            v1.2
  72.     mov    ah,3Eh            ; Close file
  73.     int    21h
  74.     mov    ax,2503h        ; Restore old Int 3 vector
  75.     lds    dx,cs:oldInt3
  76.     int    21h
  77.     xor    ax,ax            ;ERRORLEVEL 0            v1.2
  78.     jmp    short Exit1
  79.  
  80. CantCreat:
  81.     push    ax            ;save file create error        v1.2
  82.     mov    ax,cs
  83.     mov    ds,ax
  84.     ASSUME    DS:CSEG            ;v1.1
  85.     mov    dx,offset CantCreat_    ;'Error creating destination file'
  86.     mov    ah,9            ; Display string
  87.     int    21h
  88.     pop    ax            ;restore ERRORLEVEL        v1.2
  89. Exit1:  mov    ah,4CH            ;terminate, AL=ERRORLEVEL    v1.2 
  90.     int    21h
  91.  
  92. ;-!!!!!!!!! Installation Code !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!-
  93.  
  94. NEWSTACK = progend+4DH            ;v1.2
  95. Begin:    mov    sp,offset NEWSTACK    ;new stack pointer        v1.2
  96.  
  97.     mov    si,80h            ;PSP cmdline
  98.     cld                ;insure fwd            v1.1
  99.     lodsb                ;snarf cmdline length, bump SI    v1.1
  100.     or    al,al            ;any cmdline chars?        v1.1
  101.     jz    NoFile            ;nope                v1.1
  102.  
  103.     mov    ax,3503h        ; Get old Int 3 vector
  104.     int    21h            ;(breakpoint)
  105.     mov    word ptr [oldInt3],bx    ;save it
  106.     mov    word ptr [oldInt3+2],es
  107.     mov    ax,2503h        ; Set new Int 3 vector
  108.     mov    dx,offset NewInt3    ;to our code
  109.     int    21h
  110. Spc:    lodsb
  111.     cmp    al,20h            ; Space - 20h, 32d
  112.     jz    Spc            ;gobble leading spaces
  113.     dec    si            ;back up from last LODSB
  114.     mov    dx,si            ; Save name pointer in DX    v1.2
  115. Loop1:  lodsb                ; Search for end of line
  116.     cmp    al,0DH            ;terminating CR?        v1.2
  117.     jnz    Loop1            ;nope
  118.     dec    si            ;back up to terminating CR
  119.     mov    byte ptr [si],0h    ; Set it to ASCIIZ string
  120.     mov    ax,3D00h        ; Open for read only
  121.     int    21h            ;DX -> filename            v1.2
  122.     jb    BadName            ;open failed            v1.1
  123.  
  124.     mov    bx,ax            ;handle for upcoming read    v1.1
  125. CODELEN    =    (progend-progstart+0Fh) SHR 4    ;program length in paras v1.1
  126.     mov    ax,CS            ;v1.1
  127.     add    ax,CODELEN+5        ;v1.1
  128.     mov    ES,ax            ;into ES            v1.1
  129.     mov    cx,100h /2        ;PSP length in words        v1.1
  130.     xor    si,si        ;0    ;v1.1
  131.     xor    di,di        ;0    ;v1.1
  132.     rep    movsw            ;copy PSP (words are faster)    v1.1
  133.  
  134.     mov    ax,es
  135.     mov    ds,ax
  136.     ASSUME    DS:NOTHING,ES:NOTHING    ;v1.1
  137.     mov    ah,3Fh            ; Read from file
  138.     mov    cx,0FFFFh        ; Can't be more than that...
  139.     mov    dx,100h            ;  (it's a COM file...)
  140.     int    21h
  141.     jb    ReadErr            ;Read failed
  142.     mov    cx,ax            ;save real file size for later    v1.1
  143.     mov    ah,3Eh            ; Close file
  144.     int    21h            ;(BX still unchanged)        v1.1
  145.     jmp    short Label1
  146.  
  147. NoFile:    mov    dx,offset NoFile_    ;'No file specified'        v1.1
  148.     jmp    short Print
  149. BadName:
  150.     mov    dx,offset BadName_    ;'Bad file name'        v1.1
  151.     jmp    short Print
  152.  
  153. ;v1.1    CX has bytes read (file size).
  154. Label1:    mov    al,8Bh            ; ( equ MOV DI )        v1.1
  155.     mov    di,100h            ;search from prog start onward
  156.  
  157. Scan:    repnz    scasb            ; Search for it
  158.     jcxz    NotLite            ;didn't find it
  159.     cmp    word ptr [di],0CBF8h    ; ( equ ,AX RETF )
  160.     jnz    Scan            ;wrong MOV DI, keep scanning
  161.  
  162.     dec    di            ;back up to that MOV DI
  163.     mov    byte ptr [di],0CCh    ; ( equ INT 3 )
  164. ;Set up stack for the decompressing .COM program
  165. ;(Just like MS-DOS would do it)
  166.     mov    ax,ds
  167.     mov    ss,ax
  168.     mov    sp,0FFFEh
  169.     push    ax            ;.COM program's CSEG
  170.     mov    ax,100h            ;first line of code
  171.     push    ax            ;fake a FAR's return address
  172.     retf                ; Jump to original program
  173.                     ;where our breakpoint will    v1.1
  174.                     ;handle the file write        v1.1
  175. NotLite:mov    al,0FFH            ;-1 error            v1.1
  176.     mov    dx,offset NotLite_    ;'Not compressed under PkLite...'
  177.     jmp    short Print
  178. ReadErr:mov    dx,offset ReadErr_    ;'Error reading source file...'
  179. Print:    push    ax            ;save ERRORLEVEL in AL        v1.1
  180.     mov    ax,cs
  181.     mov    ds,ax
  182.     ASSUME    DS:CSEG            ;v1.1
  183.     mov    ah,9h            ; Display string
  184.     int    21h
  185.     mov    dx,offset Abort_    ;'Program aborting.'        v1.1
  186.     mov    ah,9            ;v1.1
  187.     int    21H            ;v1.1
  188.     pop    ax            ;restore ERRORLEVEL in AL    v1.1
  189.     EVEN                ;To insure stack alignment    v1.1
  190. progend    EQU    $            ;v1.1
  191.     mov    ah,4Ch            ; Terminate process
  192.     int    21h
  193. CSEG    ENDS
  194.     END    ExLite            ;v1.1
  195.