home *** CD-ROM | disk | FTP | other *** search
/ Computer Installation Guide - Dragon Clan Series / CD2.iso / DOSTOOLS / EXE2COM / E2C.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-08-18  |  7.6 KB  |  316 lines

  1.     .286
  2.  
  3. Code    SEGMENT para PUBLIC 'CODE'
  4.  
  5.         Assume  CS:Code, DS:Code
  6.         ORG     100h
  7.  
  8. ;====================================================================
  9. cr    equ    10
  10. lf    equ    13
  11.  
  12. ;====================================================================
  13. Start:
  14.     Call    Header
  15.     Call    CmdLine
  16.     cmp    al,-1
  17.     je    _usage             
  18.     Call    OpenRFile          
  19.     cmp    al,-1
  20.     je    _norfile       
  21.     Call    CheckExe           
  22.      cmp    al,-1
  23.         je    _closerfile        
  24.     Call    OpenWFile
  25.     cmp    al,-1
  26.     je    _nowfile
  27.     Call    HeadOff
  28. _closewfile: Call CloseWFile
  29.     jmp    _closerfile
  30. _nowfile: Call    NoFile
  31. _closerfile: Call CloseRFile       
  32.            jmp    _ende              
  33. _norfile: Call    NoFile
  34.     jmp    _ende                       
  35. _usage:    Call    Usage              
  36. _ende:    Call    Footer             
  37.         mov     ax,4c00h           
  38.         int     21h                
  39.                 
  40. ;====================================================================
  41. HeadOff PROC near
  42.     pusha
  43.     xor    cx,cx
  44.     mov    dx,8        ;where at (cx:dx)
  45.     mov    ax,4200h    ;move filepointer to (from files begin)
  46.     mov    bx,RFileHandle    ;handle
  47.     int    21h                      
  48.     mov    ah,3fh        ;read    
  49.     mov    bx,RFileHandle    ;handle  
  50.     mov    cx,2        ;bytes   
  51.     lea    dx,loadword    ;where at
  52.     int    21h                      
  53.     xor    cx,cx
  54.     mov    dx,loadword    ;counter
  55.     shl    dx,4        ;*16    
  56.     mov    ax,4200h    ;move filepointer to (from files begin)
  57.     mov    bx,RFileHandle    ;handle
  58.     int    21h                      
  59. headoff_lop:
  60.     mov    ah,3fh        ;read    
  61.     mov    bx,RFileHandle    ;handle  
  62.     mov    cx,63000    ;bytes
  63.     lea    dx,loadword    ;where at
  64.     int    21h                      
  65.     cmp    ax,0        ;0 bytes ?
  66.     je    headoff_end
  67.     mov    cx,ax        ;bytes
  68.     mov    ah,40h        ;write
  69.     mov    bx,WFileHandle    ;handle
  70.     lea    dx,loadword    ;where at
  71.     int    21h
  72.     jc    headoff_fail
  73.     jmp    headoff_lop
  74. headoff_end:         
  75.     lea    dx,headoff_
  76.     Call     Print
  77.     popa 
  78.     ret  
  79. headoff_fail:
  80.     lea    dx,headoff_fail_
  81.     Call    Print                   
  82.     CALL    FileName
  83.     popa                            
  84.     mov    al,-1
  85.     ret                             
  86. headoff_ db      'CUT HEAD OFF',cr,lf,'$'
  87. headoff_fail_ db 'CANNOT WRITE TO $'
  88. HeadOff    ENDP
  89. ;====================================================================
  90. CheckExe PROC    near
  91.     pusha
  92.     mov    di,offset checklist
  93. checkexe_lop:      
  94.     mov    al,ds:di    
  95.     cmp    al,-1        ;last check ?
  96.     je    checkexe_passed
  97.     xor    cx,cx
  98.     xor    dx,dx
  99.     mov    dl,al        ;where at (cx:dx)
  100.     mov    ax,4200h    ;move filepointer to (from files begin)
  101.     mov    bx,RFileHandle    ;handle
  102.     int    21h                      
  103.     jc    checkexe_fail            
  104.     mov    ah,3fh        ;read    
  105.     mov    bx,RFileHandle    ;handle  
  106.     mov    cx,2        ;bytes   
  107.     lea    dx,loadword    ;where at
  108.     int    21h                      
  109.     jc    checkexe_fail                                     
  110.     mov    ax,ds:di+1    ;value
  111.     cmp    loadword,ax    ;read value
  112.     jne    checkexe_fail    ;not equal -> not convertable
  113.     mov    al,'$'
  114. checkexe_scan:    
  115.     inc    di 
  116.     cmp    al,ds:[di+2]
  117.     jne    checkexe_scan
  118.     add    di,3
  119.     jmp    checkexe_lop
  120. checkexe_passed:
  121.     popa
  122.     ret      
  123. checkexe_fail:
  124.     add    di,3
  125.     mov    dx,di
  126.     Call    Print
  127.     Call    Return
  128.     popa
  129.     mov    al,-1
  130.     ret
  131. checklist db    0            ;offset 0
  132.     db    'MZ'             ;value 'MZ'
  133.     db    'NO MZ-SIGNATURE$'    ;error-message
  134.     db    20            ;offset 20
  135.     dw    0100h                 ;value
  136.     db    'INCORRECT IP$'        ;msg
  137.     db    22                   ;.......
  138.     dw    0fff0h       
  139.     db    'INCORRECT CS$'
  140.     db    6   
  141.     dw    0   
  142.     db    'RELOCS PRESENT$'
  143.     db    14             
  144.     dw    0fff0h         
  145.     db    'SS MESSED UP$'
  146.     db    16           
  147.     dw    0fffeh       
  148.     db    'SP MESSED UP$'
  149.     db    26
  150.     dw    0
  151.       db    'OVERLAYS PRESENT$'
  152.     db    -1   
  153. CheckExe ENDP
  154.  
  155. ;====================================================================
  156. CloseRFile PROC    near
  157.           pusha      
  158.     mov       bx,RFileHandle
  159.     mov    ah,3eh
  160.     int    21h 
  161.     popa         
  162.     ret          
  163. CloseRFile ENDP       
  164.  
  165. ;====================================================================
  166. CloseWFile PROC    near
  167.           pusha      
  168.           mov       bx,WFileHandle
  169.     mov    ah,3eh        
  170.     int    21h           
  171.     popa                  
  172.           ret                   
  173. CloseWFile ENDP
  174.  
  175. ;====================================================================
  176. NoFile    PROC    near
  177.        pusha
  178.     lea      dx,nofile_
  179.     Call    Print     
  180.     Call    FileName  
  181.     popa              
  182.     ret               
  183. nofile_    db    'CANNOT OPEN FILE $'
  184. NoFile    ENDP              
  185.                           
  186. ;====================================================================
  187. OpenRFile PROC    near 
  188.          pusha        
  189.     mov    dx,82h        ;asciiz = cmdline
  190.     mov    ax,3d00h    ;open it for read
  191.     int    21h  
  192.     jc       openrfile_fail
  193.     mov    RFileHandle,ax    
  194.     lea    dx,openrfile_
  195.     Call    Print   
  196.     Call    FileName
  197.     popa              
  198.     ret               
  199. openrfile_fail:
  200.     popa
  201.     mov    al,-1
  202.     ret
  203. openrfile_ db    'OPENED FILE $'
  204. OpenRFile ENDP
  205.  
  206. ;====================================================================
  207. OpenWFile PROC    near
  208.          pusha
  209.          xor      ah,ah
  210.          mov    al,ds:80h
  211.          mov    di,ax
  212.     mov    ds:[di+80h-2],'OC'
  213.     mov    byte ptr ds:[di+80h],'M'
  214.          mov    dx,82h        ;asciiz = cmdline
  215.     mov    ah,3ch        ;open it for write
  216.     mov    cx,0        ;attribute
  217.     int    21h  
  218.     cmp    ax,0
  219.     je       openwfile_fail
  220.     mov    WFileHandle,ax    
  221.     lea    dx,openwfile_
  222.     Call    Print   
  223.     Call    FileName
  224.     popa              
  225.     ret               
  226. openwfile_fail:      
  227.          popa         
  228.     mov     al,-1
  229.     ret          
  230. openwfile_ db    'OPENED FILE $'
  231. OpenWFile ENDP       
  232.                      
  233. ;====================================================================
  234. CmdLine    PROC    near 
  235.     pusha        
  236.     xor      ah,ah
  237.     mov    al,ds:80h
  238.     cmp    ax,6         ;less than 6 chars (cmd-LINE) incl. ret?
  239.       jl    cmdline_fail
  240.     mov    di,ax                                                        
  241.     mov    word ptr ds:[di+81h],'$'*256
  242.     popa
  243.     ret
  244. cmdline_fail:
  245.     popa
  246.     mov    al,-1
  247.     ret           
  248. CmdLine    ENDP
  249.  
  250. ;====================================================================
  251. Header    PROC    near
  252.     pusha             
  253.     lea    dx,header_
  254.     Call    Print
  255.     popa         
  256.     ret          
  257. header_    db    cr,lf
  258.     db    '∙∙--==--∙∙ EXE2COM ∙∙--==--∙∙ by HENDR¡X of OBSESSION',cr,lf,'$'
  259. Header    ENDP                            
  260.                                               
  261. ;====================================================================
  262. Footer    PROC    near                          
  263.           pusha                                 
  264.     lea      dx,footer_
  265.     Call    Print                         
  266.     popa                                  
  267.     ret                                   
  268. footer_    db        '--==**==-- EXE2COM --==**==--',cr,lf,'$'
  269. Footer    ENDP                                  
  270.                                                   
  271. ;====================================================================
  272. Usage    PROC    near                              
  273.           pusha                                     
  274.     lea      dx,usage_
  275.     Call    Print                             
  276.     popa                                      
  277.          ret                                       
  278. usage_     db    'USAGE: E2C PROGRAM.EXE',cr,lf,'$'
  279. Usage    ENDP                                      
  280.                    
  281. ;====================================================================
  282. Print    PROC    near
  283.     mov    ah,09h
  284.     int    21h
  285.     ret        
  286. Print    ENDP       
  287.  
  288. ;====================================================================
  289. Return    PROC    near
  290.     pusha
  291.     lea    dx,return_
  292.     Call    Print
  293.     popa
  294.     ret 
  295. return_    db    cr,lf,'$'
  296. Return    ENDP
  297.  
  298. ;====================================================================
  299. FileName PROC    near
  300.      pusha
  301.     mov      dx,82h
  302.     Call    Print 
  303.     Call    Return
  304.     popa
  305.     ret
  306. FileName ENDP
  307.  
  308. ;====================================================================
  309. RFileHandle    dw    ?
  310. WFileHandle    dw    ?
  311. loadword    dw    ?
  312.                      
  313. ;====================================================================
  314. Code    ENDS
  315. END     Start      
  316.