home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / ms_dos / exetoexp / execnv.asm < prev    next >
Assembly Source File  |  1990-06-14  |  2KB  |  161 lines

  1. .286c
  2.  
  3.     page        60,130
  4.     title        Master
  5. ;
  6. ;
  7. ;
  8. ;
  9.  
  10. code    segment
  11.     assume        cs:code,ds:code,es:code,ss:code
  12. ;
  13. ;
  14. ;
  15.     org    80h
  16. argv    label byte
  17.  
  18.     org    100h
  19. ;
  20. ;
  21. ;
  22. entry:
  23. st1:    mov    dx,offset msg1    ;オープニングメッセージ
  24.     mov    ah,09h
  25.     int    21h
  26.  
  27.     cld                ;ファイルオープン
  28.     mov    bp,sp
  29.     mov    si,offset argv+1
  30. lp1:    lodsb
  31.     cmp    al,20h
  32.     je    lp1
  33.     cmp    al,09h
  34.     je    lp1
  35.     cmp    al,0dh
  36.     jne    ps1
  37.     mov    dx,offset msg2
  38.     mov    ah,09h
  39.     int    21h
  40.     mov    dx,offset inp
  41.     mov    ah,0ah
  42.     int    21h
  43.     mov    si,offset inp+3
  44. ps1:    dec    si
  45.     mov    dx,si
  46. lp2:    lodsb
  47.     cmp   al,'.'
  48.       je    short ps2
  49.       cmp    al,20h
  50.     ja    short lp2
  51. ps2:    mov    word ptr[si-1],'E.'
  52.     mov    word ptr[si+1],'EX'
  53.     mov    byte ptr[si+3],0
  54.     mov    ax,3d00h
  55.     int    21h
  56.     jc    short ps3
  57.     push    ax
  58.     mov    byte ptr[si+2],'P'
  59.     mov    cx,0
  60.     mov    ax,3c00h
  61.     int   21h
  62. ps3:    jc    short ps4
  63.     push    ax
  64.  
  65.     mov    bx,[bp-2]        ;ヘッダー読込
  66.     mov    dx,offset buf
  67.     mov    cx,400h
  68.     mov    ah,3fh
  69.     int    21h
  70. ps4:    jc    near ptr fal
  71.     push    ax
  72.  
  73.     mov    si,offset buf        ;ヘッダー書き換え    
  74.     mov    di,si
  75.     mov    byte ptr[si+1],50h    ;.exp
  76.     mov    ax,[si+0ah]        ; adjust page size(512byte=>4096byte)
  77.     add    ax,0ffh
  78.     shr    ax,8
  79.     mov    [si+0ah],ax
  80.     mov    word ptr[si+0ch],0ffffh
  81.     add    si,0eh            ;[ss:sp] => esp
  82.     xchg    ax,[si]
  83.     xchg    ax,[si+2]
  84.     xchg    ax,[si]
  85.     call    scnv
  86.     mov    si,di
  87.     mov    word ptr[si+12h],0cccdh ;check sum ?
  88.     add    si,14h            ;[cs:ip] => eip
  89.     call    scnv
  90.     mov    si,di
  91.     mov    word ptr[si+18h],001eh  ;relocofs ?
  92.     mov    word ptr[si+1ah],0    ;numover ?
  93.     mov    word ptr[si+1ch],1    ;dummy ?
  94.     add    di,1eh            ;clr relocate table
  95.     mov    cx,[si+8]
  96.      shl    cx,4
  97.     sub    cx,1eh
  98.     mov    al,0
  99.     rep    stosb
  100.  
  101. fbr:    mov    bx,[bp-4]        ;ファイル転送
  102.     mov    dx,offset buf
  103.     mov    cx,[bp-6]
  104.     mov    ah,40h
  105.     int    21h
  106.     cmp    ax,1
  107.     jb    short lend
  108.  
  109.     mov    bx,[bp-2]
  110.     mov    cx,400h
  111.     mov    ah,3fh
  112.     int    21h
  113.     jc    short fal
  114.     mov    [bp-6],ax
  115.     jmp    short fbr
  116.  
  117. fal:    mov    dx,offset msg3        ;エラー処理
  118.     mov    ah,09h
  119.     int    21h
  120.     mov    sp,bp
  121.     mov    ax,4c01h
  122.     int    21h
  123.  
  124. lend:    mov    bx,[bp-2]            ;後処理
  125.     mov    ah,3eh
  126.     int    21h
  127.     mov    bx,[bp-4]
  128.     mov    ah,3eh
  129.     int    21h
  130. ;
  131.     mov    sp,bp
  132.     mov    ax,4c00h
  133.     int    21h
  134.  
  135. scnv    proc            ;[セグメント:オフセット] => 32bit オフセット
  136.     mov    ax,[si+2]
  137.     shl    ax,4
  138.     xor    dh,dh
  139.     mov    dl,[si+3]
  140.     shr    dl,4
  141.     add    ax,[si]
  142.     adc    dx,0
  143.     mov    [si],ax
  144.     mov    [si+2],dx
  145.     ret
  146. scnv    endp
  147.  
  148. ;
  149. ;
  150. ;
  151. msg1    db    '.exe => .exp 変換ユーティリティー',0dh,0ah
  152.     db    '    programmed by N.YAMAZAKI',0dh,0ah,'$'
  153. msg2    db    '.exe file name[.exe]=','$'
  154. msg3    db    '失敗!',0dh,0ah,'$'
  155. inp    db    040h,?,040h dup(0)
  156. buf    db    400h dup(0)
  157.  
  158. code    ends
  159.     end    entry
  160.     
  161.