Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .model tiny
  2.     .386
  3.     locals
  4.     .code
  5.     org 100h
  6.  
  7. include macro.asm
  8.  
  9. Start:
  10.  
  11.     mov dl, 0
  12.     jmp Main
  13.  
  14. table1  db 32 dup (13), 0, 12 dup (13), 1, 26 dup (13), 2, 3, 13, 4, 7 dup (13), 5, 13, 6, 6 dup (13), 7, 11 dup (13), 8, 9, 13, 10, 7 dup (13), 11, 13, 12, 138 dup (13)
  15. table2  db 1, 14 dup (8), 2, 5 dup (8), 2, 8 dup (8), 3, 4, 5, 6, 7, 8, 3, 4, 5, 6, 7, 8, 1, 13 dup (8), 1, 13 dup (8), 1, 13 dup (8), 1, 13 dup (8), 1, 13 dup (8)
  16.  
  17. usageMess   db 'r1 [\h] [\i] [\k] [\s] [\u]', 24h
  18. helpMess    db 'This program is for interrupt handler installation for int 2Fh', 24h
  19. installed   db 'Installed', 24h
  20. notInstall  db 'Not installed', 24h
  21. intHandled  db 'Interrupt handled', 24h
  22. notAuthorized   db 'Not authorized', 24h
  23. authorCode  db 'SM', 24h
  24. oldHandler  dd ?
  25.  
  26. HandleInterrupt proc
  27.  
  28. ;   +-------------------------------------------
  29. ;   | The main interruption handler procedure
  30. ;   |
  31. ;   | On entry:
  32. ;   |   dx - shold contain auth-code
  33. ;   |
  34. ;   | Returns:
  35. ;   |   bx - a place where is the resident
  36. ;   +-------------------------------------------
  37.  
  38.     pushf
  39.     push ds
  40.     push cs
  41.     pop ds
  42.  
  43.     cmp dx, offset authorCode
  44.     jne @@1
  45.  
  46.     mov bx, cs
  47.  
  48. @@1:
  49.  
  50.     pop ds
  51.     jmp oldHandler
  52.     iret
  53.  
  54. HandleInterrupt endp
  55.  
  56. Main:
  57.  
  58.     mov si, 80h
  59.     lodsb
  60.     mov cl, al
  61.  
  62. Automata:
  63.  
  64.     lodsb
  65.     dec cl
  66.     cmp cl, 0
  67.     jl Usage
  68.  
  69.     lea bx, table1
  70.     xlat
  71.     mov ch, al
  72.     mov al, dl
  73.     mov bl, 14
  74.     mul bl
  75.     mov bl, ch
  76.     add al, bl
  77.  
  78.     lea bx, table2
  79.     xlat
  80.  
  81.     cmp al, 8
  82.     je Usage
  83.     cmp al, 3
  84.     je PrintHelp
  85.     cmp al, 4
  86.     je InstallRes
  87.     cmp al, 5
  88.     je KillRes
  89.     cmp al, 6
  90.     je Stat
  91.     cmp al, 7
  92.     je UninstallRes
  93.     mov dl, al
  94.  
  95.     jmp Automata
  96.     ret
  97.  
  98. Usage:
  99.  
  100.     printf usageMess
  101.     ret
  102.  
  103. PrintHelp:
  104.  
  105.     printf helpMess
  106.     ret
  107.  
  108. InMemory:
  109.  
  110.     printf installed
  111.     ret
  112.  
  113. NotInMemory:
  114.  
  115.     printf notInstall
  116.     ret
  117.  
  118. InstallRes:
  119.  
  120.     xor bx, bx
  121.     mov ax, bx
  122.     lea dx, authorCode
  123.     int 2Fh
  124.     cmp ax, bx
  125.     jne InMemory
  126.  
  127.     mov ah, 35h
  128.     mov al, 2Fh
  129.     int 21h
  130.     mov word ptr oldHandler, bx
  131.     mov word ptr oldHandler+2, es
  132.  
  133.     mov ah, 25h
  134.     mov al, 2Fh
  135.     mov dx, offset HandleInterrupt
  136.     int 21h
  137.  
  138.     mov ah, 31h
  139.     mov al, 0
  140.     mov dx, 17
  141.     int 21h
  142.     ret
  143.  
  144. KillRes:
  145.  
  146.     xor bx, bx
  147.     mov ax, bx
  148.     lea dx, authorCode
  149.     int 2Fh
  150.  
  151.     mov ah, 25h
  152.     mov al, 2Fh
  153.     mov dx, word ptr oldHandler
  154.     mov ds, [word ptr oldHandler+2]
  155.     int 21h
  156.  
  157.     cmp ax, bx
  158.     jne CleanMemory
  159.     ret
  160.  
  161. CleanMemory:
  162.  
  163. ;   +------------------------------------------------
  164. ;   | Releases 17 paragraphs from a set segment
  165. ;   |
  166. ;   | On entry:
  167. ;   | bx - segment address of memory to be released
  168. ;   +------------------------------------------------
  169.  
  170.     mov ds, bx
  171.  
  172.     mov ah, 49h
  173.     mov ds, ds:110h
  174.     int 21h
  175.     ret
  176.  
  177. Stat:
  178.  
  179.     xor bx, bx
  180.     mov ax, bx
  181.     lea dx, authorCode
  182.     int 2Fh
  183.     cmp ax, bx
  184.     jne InMemory
  185.     je NotInMemory
  186.     ret
  187.  
  188. UninstallRes:
  189.  
  190.     xor bx, bx
  191.     mov ax, bx
  192.     lea dx, authorCode
  193.     int 2Fh
  194.     cmp ax, bx
  195.     je NotInMemory
  196.  
  197.     mov ah, 25h
  198.     mov al, 2Fh
  199.     mov dx, word ptr oldHandler
  200.     mov ds, [word ptr oldHandler+2]
  201.     int 21h
  202.  
  203.     jmp CleanMemory
  204.     ret
  205.  
  206. end Start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement