Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  1. .686p
  2. .model flat, stdcall
  3. .stack 4096
  4. ExitProcess PROTO, dwExitCode : DWORD
  5. include Irvine32.inc
  6. .data
  7. passPrompt BYTE "Please Enter Your Passcode: ", 0
  8. successPrompt BYTE "Door is now open", 0
  9. failPrompt BYTE "Intruder or new resident", 0
  10. useNewPrompt BYTE "Would you like to use this code for another apartment? (Y/N) ", 0
  11. dontSetPrompt BYTE "Well then get off my lawn!", 0
  12. apartmentPrompt BYTE "Please Enter the Apartment Number: ", 0
  13. apartErrorPrompt BYTE "ERROR: Invalid apartment number entered. ", 0
  14. apartSuccessPrompt BYTE "Successfully updated passcode: ", 0
  15. currentCodesPrompt BYTE "Current Codes: ", 0
  16. err_msg BYTE "ERROR: Invalid input!", 0
  17. comma BYTE ", ", 0
  18.  
  19. numOfApts = 17
  20. codeArr WORD numOfApts DUP(?) ; will be filled later
  21. .code
  22. FindCode PROTO inkey:WORD
  23.  
  24. main PROC
  25. ; fill array with default values
  26. push OFFSET codeArr
  27. push numOfApts
  28. call FillPasscodes
  29. mov edx, OFFSET currentCodesPrompt
  30. call WriteString
  31. call CRLF
  32. call PrintArray ; Show the array so people can
  33.  
  34. mov edx, OFFSET passPrompt
  35. call WriteString ; prompt the user for passcode
  36.  
  37. call ReadDec
  38. call CRLF
  39. jc INPUT_ERROR ; If CF = 1, error in input
  40.  
  41. .IF ax > 999 && ax < 9999
  42. INVOKE FindCode, ax
  43. .ELSE
  44. jmp INPUT_ERROR
  45. .ENDIF
  46.  
  47. .IF edx == 1
  48. mov edx, OFFSET successPrompt
  49. call WriteString
  50. call CRLF
  51. INVOKE ExitProcess, 0
  52. .ELSE
  53. mov edx, OFFSET failPrompt
  54. call WriteString
  55. call CRLF
  56. push ax ; Push their entered passcode for later use
  57. jmp AskNewCode
  58. .ENDIF
  59.  
  60. INPUT_ERROR: ; The program has experienced an error
  61. mov edx, OFFSET err_msg
  62. call WriteString
  63. call CRLF
  64. INVOKE ExitProcess, 1
  65.  
  66. AskNewCode:
  67. ; This only works before Windows XP...
  68. mov eax, 10000
  69. INVOKE Delay ; Pause for 10 seconds
  70. mov edx, OFFSET useNewPrompt
  71. call WriteString
  72. call ReadChar
  73. call CRLF
  74.  
  75. .IF al == 89 || al == 121 ; 'y' or 'Y'
  76. jmp SetNewCode
  77. .ELSE
  78. mov edx, OFFSET dontSetPrompt
  79. call WriteString
  80. call CRLF
  81. INVOKE ExitProcess, 0
  82. .ENDIF
  83.  
  84. SetNewCode:
  85. mov edx, OFFSET apartmentPrompt
  86. call WriteString
  87. call ReadDec
  88. call CRLF
  89. jc INPUT_ERROR
  90.  
  91. .IF ax < 1 || ax > 17
  92. mov edx, OFFSET apartErrorPrompt
  93. call WriteString
  94. call CRLF
  95. INVOKE ExitProcess, 1
  96. .ELSE
  97. pop bx
  98. call SetCode
  99. mov edx, OFFSET apartSuccessPrompt
  100. call WriteString
  101. call PrintArray
  102. .ENDIF
  103.  
  104. INVOKE ExitProcess, 0
  105. main ENDP
  106.  
  107. SetCode PROC
  108.  
  109. mov esi, OFFSET codeArr
  110. mov ecx, 2
  111. mul ecx ; EAX = EAX * the size of a word (2)
  112.  
  113. add esi, eax ; go to the appropriate array index
  114. mov [esi], bx ; set the code entered into the appropriate place
  115.  
  116. ret
  117.  
  118. SetCode ENDP
  119.  
  120. ;----------------------------------------
  121. ; Find the given key in the codeArr
  122. ; RETURNS: 1 if found, 0 if not found
  123. ;----------------------------------------
  124. FindCode PROC, inkey:WORD
  125.  
  126. mov esi, OFFSET codeArr
  127. mov ecx, LENGTHOF codeArr
  128. mov ax, inkey
  129.  
  130. Search:
  131. cmp ax, [esi]
  132. JZ Found
  133. add esi, TYPE codeArr
  134. LOOP Search
  135. mov edx, 0 ; Not found (0)
  136. ret
  137.  
  138. Found:
  139. mov edx, 1 ; Found (1)
  140. ret
  141. FindCode ENDP
  142.  
  143. ;--------------------------------------------------------
  144. ; Fills the codeArr array with random 4-digit integers
  145. ; to be used as the default passcodes
  146. ;--------------------------------------------------------
  147. FillPasscodes PROC
  148.  
  149. push ebp
  150. mov ebp, esp
  151. mov esi, [ebp+12] ; get the array offset
  152. mov ecx, [ebp+8] ; get the size of the array
  153. call Randomize
  154.  
  155. FillLoop:
  156. mov eax, 4000 ; Top range or random number generation
  157. call RandomRange
  158. mov ebx, eax
  159. mov eax, 4000
  160. call RandomRange
  161. add ebx, eax
  162. add ebx, 1000 ; make sure numbers are at least above 1000
  163. mov [esi], ebx
  164. add esi, TYPE codeArr
  165. loop FillLoop
  166.  
  167. pop ebp
  168. ret
  169. FillPasscodes ENDP
  170.  
  171. ;---------------------------
  172. ; Print the codeArr array
  173. ;---------------------------
  174. PrintArray PROC
  175.  
  176. mov esi, OFFSET codeArr
  177. mov ecx, LENGTHOF codeArr
  178. mov edx, OFFSET comma
  179. mov eax, 0
  180.  
  181. L1:
  182. mov ax, [esi]
  183. call WriteDec
  184. call WriteString
  185. add esi, TYPE codeArr
  186. loop L1
  187. call CRLF
  188. ret
  189. PrintArray ENDP
  190.  
  191. END main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement