Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. segment code code
  2. CodeSegment:
  3. ..start:
  4. mov eax, cr0
  5. xor eax, 01h
  6. mov cr0, eax
  7. jmp ExitProgram
  8.  
  9. mov ecx, 07h
  10. mov edi, GDTTables
  11. mov esi, GDTScratch
  12. rep movsd
  13.  
  14. mov ax, 37h
  15. rol ax, 08h
  16. mov [GDTTLim], ax
  17. mov eax, GDTScratch
  18. bswap eax
  19. mov [GDTTLinear], eax
  20. lgdt [GDTRam]
  21.  
  22. mov eax, cr0
  23. or eax, 01h
  24. mov cr0, eax
  25.  
  26. xor edx, edx
  27. mov edi, IDTTables
  28. mov esi, edx
  29. SaveInts:
  30. cmp edx, 0100h
  31. je LoadIDT
  32.  
  33. cmp dword [esi], 00h
  34. je InvalidISR
  35.  
  36. lea ax, [esi + 02h]
  37. lea bx, [esi + 00h]
  38. mov cx, 0010h
  39. xor edx, edx
  40. mul cx
  41. add ax, bx
  42. rol ax, 08h
  43.  
  44. mov bl, 8eh
  45.  
  46. jmp ConvertISR
  47. InvalidISR:
  48. mov ax, 00h
  49. mov bl, 0eh
  50. ConvertISR:
  51. mov [edi + 00h], ax
  52. mov word [edi + 02h], 0100h
  53. mov byte [edi + 04h], 00h
  54. mov byte [edi + 05h], bl
  55. mov word [edi + 06h], 00h
  56.  
  57. inc edx
  58. add edi, 08h
  59. add esi, 04h
  60. jmp SaveInts
  61. LoadIDT:
  62. mov ax, 0800h
  63. rol ax, 08h
  64. mov [IDTLim], ax
  65. mov eax, IDTTables
  66. bswap eax
  67. mov [IDTLinear], eax
  68. lidt [IDTRam]
  69.  
  70. jmp SafeJump
  71. SafeJump:
  72. mov ax, 0003h
  73. mov cs, ax
  74. mov ax, 0002h
  75. mov ds, ax
  76. mov es, ax
  77. mov ax, 0001h
  78. mov ss, ax
  79. mov eax, StackTop
  80. mov esp, eax
  81. HackElection:
  82. mov ecx, 0fh
  83. mov edi, Winner
  84. mov esi, NewWinner
  85. movsb
  86. ExitProgram:
  87. mov ax, 4c00h ; return code
  88. int 21h ; EXIT
  89. CodeTop:
  90.  
  91. segment data data
  92. DataSegment:
  93. GDTScratch: dw 00h ; lim_0_15
  94. dw 00h ; bas_0_15
  95. db 00h ; bas_16_23
  96. db 00h ; access
  97. db 00h ; gran
  98. db 00h ; bas_24_31
  99. ; - GDT Code Entry (Ring Zero) ----------
  100. dw 0ffffh
  101. dw 00h
  102. db 00h
  103. db 9eh
  104. db 0c0h
  105. db 00h
  106. ; - GDT Data Entry (Ring Zero) ----------
  107. dw 0ffffh
  108. dw DataSegment
  109. db 00h
  110. db 8eh
  111. db 0c0h
  112. db 00h
  113. ; - GDT Stack Entry (Ring Zero) ---------
  114. dw 0ffffh
  115. dw StackSegment
  116. db 00h
  117. db 8eh
  118. db 0c0h
  119. db 00h
  120. ; - GDT Code Entry (Ring Three) ---------
  121. dw 5555h
  122. dw 00h
  123. db 0ffh
  124. db 0deh
  125. db 0c0h
  126. db 0ffh
  127. ; - GDT Data Entry (Ring Three) ---------
  128. dw 5555h
  129. dw 5555h
  130. db 0ffh
  131. db 0ceh
  132. db 0c0h
  133. db 0ffh
  134. ; - GDT Stack Entry (Ring Three) --------
  135. dw 5555h
  136. dw 0aaaah
  137. db 0ffh
  138. db 0ceh
  139. db 0c0h
  140. db 0ffh
  141. NewWinner: db 'Sergove Trotsky', 00h
  142. DataTop:
  143.  
  144. segment stack stack
  145. StackSegment:
  146. ElectionResults:
  147. Loser: resq 0ffh
  148. Winner: resq 0ffh
  149. ; -------------------------------------------------------
  150. ; - Global Descriptor Tables ----------------------------
  151. GDTTables:
  152. GND: resq 01h
  153. GCD0: resq 01h
  154. GDD0: resq 01h
  155. GSD0: resq 01h
  156. GCD3: resq 01h
  157. GDD3: resq 01h
  158. GSD3: resq 01h
  159. ; -------------------------------------------------------
  160. IDTTables: resq 0100h
  161. ; - LGDT/LIDT Structure ---------------------------------
  162. GDTRam:
  163. GDTTLim: resw 01h
  164. GDTTLinear: resd 01h
  165. IDTRam:
  166. IDTLim: resw 01h
  167. IDTLinear: resd 01h
  168. ; -------------------------------------------------------
  169. StackTop:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement