Guest User

Untitled

a guest
Jul 20th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. bits 16
  2. cpu 8086
  3.  
  4. org 0100h
  5.  
  6. section .data
  7. SInstalled: db "DOSVER is allready installed.",0ah,0dh
  8.  
  9. section .text
  10.  
  11. ; Jump to main program entry
  12. jmp Main
  13.  
  14.  
  15. ; ------------------------------------
  16. ; The actual interrupt handler routine
  17. ; It's at the very beginning to save memory
  18. ; -------------------------------------
  19.  
  20. Int21Handler:
  21. ; Is it GetVersion?
  22. cmp ah,30h
  23. jne GoInt21
  24.  
  25. ; Yes, is it installation check?
  26. cmp bx,'DO'
  27. jne NotCheck
  28. cmp cx,'SV'
  29. jne NoCheck
  30. cmp dx,'ER'
  31. jne NotCheck
  32.  
  33. ; Installation check, report that we're here
  34. mov ax,0200h ; DOSVER version 2.0
  35. mov bx,'IS'
  36. mov cx,'HE'
  37. mov dx,'RE'
  38.  
  39. NotCheck:
  40. int 21h ; Preserve all other info
  41. mov ax,0800h ; Version 8.0
  42. iret
  43.  
  44. ; Here's some self modifying code magic
  45. GoInt21:
  46. db 0eah ; JMP instruction
  47. OldIntOfs:
  48. dw 0 ; Patched at runtime
  49. OldIntSeg:
  50. dw 0 ; Patched at runtime
  51. FirstUnused:
  52.  
  53. ; ------------------------------------
  54. ; Type the string at DS:SI to the screen
  55. ; -------------------------------------
  56.  
  57. TypeStr:
  58. mov al,[si]
  59. cmp al,0dh
  60. je Return
  61. mov ah,0eh
  62. mov bh,0
  63. mov bl,7
  64. int 10h
  65. inc si
  66. jmp TypeStr
  67. Return:
  68. retn
  69.  
  70. ; ------------------------------------
  71. ; Main entry point
  72. ; -------------------------------------
  73.  
  74. Main:
  75. ; Release environment block
  76. mov ax,[002ch]
  77. jz noenv
  78. mov es,ax
  79. mov ah,49h
  80. int 21h
  81.  
  82. noenv:
  83. ; Installation check
  84. mov ah,30h
  85. mov bx,'DO'
  86. mov cx,'SV'
  87. mov dx,'ER'
  88. int 21h
  89. cmp bx,'IS'
  90. jne NotInstalled
  91. cmp cx,'HE'
  92. jne NotInstalled
  93. cmp dx,'RE'
  94. jne NotInstalled
  95.  
  96. ; Allready installed, type the message and exit
  97. mov si,SInstalled
  98. jmp TypeStr
  99.  
  100. ; ------------------------------------
  101. ; Not installed, so install our handler and terminate (but stay resident)
  102. ; -------------------------------------
  103.  
  104. NotInstalled:
  105. ; Save old int 21h vector
  106. mov ax,3521h ; get interrupt vector 21h
  107. int 21h
  108. mov [OldIntOfs],bx ; store offset
  109. push es
  110. pop ax
  111. mov [OldIntSeg],ax ; store segment
  112.  
  113. ; Install new vector
  114. mov ax,2521h ; set interrupt vector 21h
  115. mov dx,Int21Handler
  116. int 21h
  117.  
  118. ; Terminate and stay resident
  119. mov dx,FirstUnused ; We can release the memory after this part
  120. int 27h
Add Comment
Please, Sign In to add comment