Guest User

Untitled

a guest
Sep 3rd, 2015
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. ; COM2EXE v0.1 by Strength (316 bytes)
  2. ;
  3. ; tasm com2exe.asm
  4. ; tlink com2exe.obj /t
  5. ;
  6. ; C:\>com2exe
  7. ; COM2EXE v1.0 by Strength
  8. ; Usage: COM2EXE source target
  9. ;
  10. ; C:\>com2exe source.com target.exe
  11. ; COM2EXE v1.0 by Strength
  12. ; OK!
  13. ;
  14. ; C:\>com2exe source.com c:
  15. ; COM2EXE v1.0 by Strength
  16. ; Access denied!
  17. ;
  18. ; C:\>com2exe filenotfound.com target.exe
  19. ; COM2EXE v1.0 by Strength
  20. ; File not found!
  21.  
  22.  
  23. .model tiny
  24. .code
  25.  
  26. org 100h
  27.  
  28. start:
  29.  
  30. mov ah, 09h ; Print String
  31. lea dx, Logo
  32. int 21h
  33.  
  34. mov si, 80h
  35. lodsb
  36. test al, al
  37. jz DisplayUsage
  38.  
  39. inc si
  40.  
  41. xor bx, bx
  42.  
  43. Get1Param:
  44. lodsb
  45. cmp al, 0dh
  46. jz DisplayUsage
  47. cmp al, 20h
  48. jz Get2Param
  49. jmp Get1Param
  50.  
  51. Get2Param:
  52. test bl, bl
  53. jnz DisplayUsage
  54. mov byte ptr[si-1], 0
  55. mov di, si
  56. inc bx
  57. jmp Get1Param
  58.  
  59. DisplayUsage:
  60. test bl, bl
  61. jnz done
  62.  
  63. lea dx, Usage
  64. jmp short PrintAndEnd
  65.  
  66. done:
  67. mov byte ptr[si-1], 0
  68.  
  69. mov ax, 3d00h ; Open a File
  70. mov dx, 82h
  71. int 21h
  72. jc error
  73.  
  74. mov word ptr[SourceHandle], ax
  75. xchg ax, bx
  76.  
  77. xor cx, cx
  78. xor dx, dx
  79. mov ax, 4202h ; Move File Pointer (LSEEK)
  80. int 21h
  81.  
  82. mov word ptr[LengthSource], ax
  83.  
  84. add ax, 32
  85. and ax, 511
  86. mov word ptr[ExeHeaderByte2and3], ax
  87.  
  88. mov ax, 4200h ; Move File Pointer (LSEEK)
  89. int 21h
  90.  
  91. mov ax, word ptr[LengthSource]
  92.  
  93. mov cl, 9
  94. shr ax, cl
  95. inc ax
  96.  
  97. mov word ptr[ExeHeaderByte4and5], ax
  98.  
  99. mov ah, 3ch ; Create a File (CREAT)
  100. xor cx, cx
  101. mov dx, di
  102. int 21h
  103. jc error
  104.  
  105. mov si, ax
  106.  
  107. xchg ax, bx
  108.  
  109. mov ah, 40h ; Write to File or Device, Using a Handle
  110. mov cx, 20h ; dlugosc naglowka
  111. lea dx, Header
  112. int 21h
  113.  
  114. mov cx, word ptr[LengthSource]
  115. lea dx, Logo
  116. Write:
  117. push cx
  118.  
  119. mov ah, 3fh ; Read from File or Device, Using a Handle
  120. mov bx, word ptr[SourceHandle]
  121.  
  122. xor cx, cx
  123. inc cx
  124.  
  125. int 21h
  126.  
  127. mov ah, 40h ; Write to File or Device, Using a Handle
  128. mov bx, si
  129. int 21h
  130.  
  131. pop cx
  132. loop Write
  133.  
  134. mov ah, 3eh ; Close a File Handle
  135. int 21h
  136. mov bx, word ptr[SourceHandle]
  137. int 21h
  138.  
  139. lea dx, OK
  140.  
  141. PrintAndEnd:
  142. mov ah, 09h
  143. int 21h
  144.  
  145. TheEnd:
  146.  
  147. int 20h ; mozna tutaj wstawic 'ret', ale
  148. ; wtedy po przekonwertowaniu proga
  149. ; na exe by sie nie zamykal
  150.  
  151. error:
  152. lea dx, FileNotFound
  153. cmp ax, 2
  154. jz PrintAndEnd
  155. lea dx, AccessDenied
  156. jmp PrintAndEnd
  157.  
  158. Logo db 'COM2EXE v1.0 by Strength', 13, 10, '$'
  159. Usage db 'Usage: COM2EXE source target$'
  160. FileNotFound db 'File not found!$'
  161. AccessDenied db 'Access denied!$'
  162. OK db 'OK!$'
  163. SourceHandle dw ?
  164. LengthSource dw ?
  165. Header db 4dh, 5ah
  166. ExeHeaderByte2and3 dw ?
  167. ExeHeaderByte4and5 dw ?
  168. Header2 dw 0
  169. dw 2
  170. dw 1000h, 0ffffh
  171. dw 0fff0h, 0fffeh
  172. dw 0
  173. dw 100h, 0fff0h
  174. dw 1ch
  175. dw 0, 0, 0
  176. end start
Advertisement
Add Comment
Please, Sign In to add comment