home *** CD-ROM | disk | FTP | other *** search
- .286
-
- Code SEGMENT para PUBLIC 'CODE'
-
- Assume CS:Code, DS:Code
- ORG 100h
-
- ;====================================================================
- cr equ 10
- lf equ 13
-
- ;====================================================================
- Start:
- Call Header
- Call CmdLine
- cmp al,-1
- je _usage
- Call OpenRFile
- cmp al,-1
- je _norfile
- Call CheckExe
- cmp al,-1
- je _closerfile
- Call OpenWFile
- cmp al,-1
- je _nowfile
- Call HeadOff
- _closewfile: Call CloseWFile
- jmp _closerfile
- _nowfile: Call NoFile
- _closerfile: Call CloseRFile
- jmp _ende
- _norfile: Call NoFile
- jmp _ende
- _usage: Call Usage
- _ende: Call Footer
- mov ax,4c00h
- int 21h
-
- ;====================================================================
- HeadOff PROC near
- pusha
- xor cx,cx
- mov dx,8 ;where at (cx:dx)
- mov ax,4200h ;move filepointer to (from files begin)
- mov bx,RFileHandle ;handle
- int 21h
- mov ah,3fh ;read
- mov bx,RFileHandle ;handle
- mov cx,2 ;bytes
- lea dx,loadword ;where at
- int 21h
- xor cx,cx
- mov dx,loadword ;counter
- shl dx,4 ;*16
- mov ax,4200h ;move filepointer to (from files begin)
- mov bx,RFileHandle ;handle
- int 21h
- headoff_lop:
- mov ah,3fh ;read
- mov bx,RFileHandle ;handle
- mov cx,63000 ;bytes
- lea dx,loadword ;where at
- int 21h
- cmp ax,0 ;0 bytes ?
- je headoff_end
- mov cx,ax ;bytes
- mov ah,40h ;write
- mov bx,WFileHandle ;handle
- lea dx,loadword ;where at
- int 21h
- jc headoff_fail
- jmp headoff_lop
- headoff_end:
- lea dx,headoff_
- Call Print
- popa
- ret
- headoff_fail:
- lea dx,headoff_fail_
- Call Print
- CALL FileName
- popa
- mov al,-1
- ret
- headoff_ db 'CUT HEAD OFF',cr,lf,'$'
- headoff_fail_ db 'CANNOT WRITE TO $'
- HeadOff ENDP
- ;====================================================================
- CheckExe PROC near
- pusha
- mov di,offset checklist
- checkexe_lop:
- mov al,ds:di
- cmp al,-1 ;last check ?
- je checkexe_passed
- xor cx,cx
- xor dx,dx
- mov dl,al ;where at (cx:dx)
- mov ax,4200h ;move filepointer to (from files begin)
- mov bx,RFileHandle ;handle
- int 21h
- jc checkexe_fail
- mov ah,3fh ;read
- mov bx,RFileHandle ;handle
- mov cx,2 ;bytes
- lea dx,loadword ;where at
- int 21h
- jc checkexe_fail
- mov ax,ds:di+1 ;value
- cmp loadword,ax ;read value
- jne checkexe_fail ;not equal -> not convertable
- mov al,'$'
- checkexe_scan:
- inc di
- cmp al,ds:[di+2]
- jne checkexe_scan
- add di,3
- jmp checkexe_lop
- checkexe_passed:
- popa
- ret
- checkexe_fail:
- add di,3
- mov dx,di
- Call Print
- Call Return
- popa
- mov al,-1
- ret
- checklist db 0 ;offset 0
- db 'MZ' ;value 'MZ'
- db 'NO MZ-SIGNATURE$' ;error-message
- db 20 ;offset 20
- dw 0100h ;value
- db 'INCORRECT IP$' ;msg
- db 22 ;.......
- dw 0fff0h
- db 'INCORRECT CS$'
- db 6
- dw 0
- db 'RELOCS PRESENT$'
- db 14
- dw 0fff0h
- db 'SS MESSED UP$'
- db 16
- dw 0fffeh
- db 'SP MESSED UP$'
- db 26
- dw 0
- db 'OVERLAYS PRESENT$'
- db -1
- CheckExe ENDP
-
- ;====================================================================
- CloseRFile PROC near
- pusha
- mov bx,RFileHandle
- mov ah,3eh
- int 21h
- popa
- ret
- CloseRFile ENDP
-
- ;====================================================================
- CloseWFile PROC near
- pusha
- mov bx,WFileHandle
- mov ah,3eh
- int 21h
- popa
- ret
- CloseWFile ENDP
-
- ;====================================================================
- NoFile PROC near
- pusha
- lea dx,nofile_
- Call Print
- Call FileName
- popa
- ret
- nofile_ db 'CANNOT OPEN FILE $'
- NoFile ENDP
-
- ;====================================================================
- OpenRFile PROC near
- pusha
- mov dx,82h ;asciiz = cmdline
- mov ax,3d00h ;open it for read
- int 21h
- jc openrfile_fail
- mov RFileHandle,ax
- lea dx,openrfile_
- Call Print
- Call FileName
- popa
- ret
- openrfile_fail:
- popa
- mov al,-1
- ret
- openrfile_ db 'OPENED FILE $'
- OpenRFile ENDP
-
- ;====================================================================
- OpenWFile PROC near
- pusha
- xor ah,ah
- mov al,ds:80h
- mov di,ax
- mov ds:[di+80h-2],'OC'
- mov byte ptr ds:[di+80h],'M'
- mov dx,82h ;asciiz = cmdline
- mov ah,3ch ;open it for write
- mov cx,0 ;attribute
- int 21h
- cmp ax,0
- je openwfile_fail
- mov WFileHandle,ax
- lea dx,openwfile_
- Call Print
- Call FileName
- popa
- ret
- openwfile_fail:
- popa
- mov al,-1
- ret
- openwfile_ db 'OPENED FILE $'
- OpenWFile ENDP
-
- ;====================================================================
- CmdLine PROC near
- pusha
- xor ah,ah
- mov al,ds:80h
- cmp ax,6 ;less than 6 chars (cmd-LINE) incl. ret?
- jl cmdline_fail
- mov di,ax
- mov word ptr ds:[di+81h],'$'*256
- popa
- ret
- cmdline_fail:
- popa
- mov al,-1
- ret
- CmdLine ENDP
-
- ;====================================================================
- Header PROC near
- pusha
- lea dx,header_
- Call Print
- popa
- ret
- header_ db cr,lf
- db '∙∙--==--∙∙ EXE2COM ∙∙--==--∙∙ by HENDR¡X of OBSESSION',cr,lf,'$'
- Header ENDP
-
- ;====================================================================
- Footer PROC near
- pusha
- lea dx,footer_
- Call Print
- popa
- ret
- footer_ db '--==**==-- EXE2COM --==**==--',cr,lf,'$'
- Footer ENDP
-
- ;====================================================================
- Usage PROC near
- pusha
- lea dx,usage_
- Call Print
- popa
- ret
- usage_ db 'USAGE: E2C PROGRAM.EXE',cr,lf,'$'
- Usage ENDP
-
- ;====================================================================
- Print PROC near
- mov ah,09h
- int 21h
- ret
- Print ENDP
-
- ;====================================================================
- Return PROC near
- pusha
- lea dx,return_
- Call Print
- popa
- ret
- return_ db cr,lf,'$'
- Return ENDP
-
- ;====================================================================
- FileName PROC near
- pusha
- mov dx,82h
- Call Print
- Call Return
- popa
- ret
- FileName ENDP
-
- ;====================================================================
- RFileHandle dw ?
- WFileHandle dw ?
- loadword dw ?
-
- ;====================================================================
- Code ENDS
- END Start
-