Advertisement
StreetKatya

Автомат(3)

Sep 15th, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. format PE console
  3. entry start
  4. include 'includes\win32ax.inc'
  5.  
  6. section '.data' data readable writeable
  7. fileName db 20 dup(0)
  8. lfileName dd ?
  9. flength dd ?
  10. fbuf dd ?
  11. hHeap dd ?
  12. _hFile dd ?
  13. _r dd 00
  14. Msg db 'Input string : '
  15. lenMsg = $ - Msg
  16. MsgOK db 'Correct string '
  17. lenMsgOK = $ - MsgOK
  18. MsgNO db 'Incorrect string '
  19. lenMsgNO = $ - MsgNO
  20. stdin dd ?
  21. stdout dd ?
  22. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23.  
  24. section '.code' code readable executable
  25. start:
  26. invoke SetConsoleOutputCP,CP_UTF8
  27. invoke SetConsoleCP,CP_UTF8
  28.  
  29. invoke GetStdHandle, STD_OUTPUT_HANDLE
  30. mov [stdout],eax
  31. invoke GetStdHandle, STD_INPUT_HANDLE
  32. mov [stdin],eax
  33. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. ;запрашиваем имя файла
  35. cinvoke printf,'%s',<'Имя файла: ',0>
  36. invoke ReadConsole,[stdin],fileName,20,lfileName,NULL
  37. mov ebx,lfileName
  38. sub [lfileName],2
  39. mov ebx,[lfileName]
  40. mov [fileName + ebx],0
  41. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. ;открываем файл для чтения
  43. invoke CreateFile,fileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
  44. mov [_hFile],eax
  45. cmp eax,0
  46. je ErrRead
  47. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  48. ;длина файла
  49. invoke GetFileSize,[_hFile],flength
  50. cmp eax,0
  51. je ErrRead
  52. mov [flength],eax
  53. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. ;выделение памяти
  55. invoke GetProcessHeap
  56. cmp eax,NULL
  57. jne GoodHeap
  58. cinvoke printf,"Ошибка выделения памяти"
  59. jmp _closef
  60.  
  61. GoodHeap:
  62. mov [hHeap],eax
  63. mov ebx,[flength]
  64. add ebx,2
  65. invoke HeapAlloc,[hHeap],HEAP_ZERO_MEMORY,ebx
  66. test eax,eax
  67. jz _closef
  68. mov [fbuf],eax
  69. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70. ;Чтение файла
  71. invoke ReadFile,[_hFile],[fbuf],[flength],_r,NULL
  72. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. ;Вывод на консоль
  74. cinvoke puts,[fbuf]
  75. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. ;работа автомата
  77. mov esi,[fbuf]
  78. mov edi,[flength]
  79. mov byte [esi + edi],'$'
  80. cinvoke puts,[fbuf]
  81. S:
  82. cmp byte[esi],'a'
  83. je A
  84.  
  85. jmp Error1
  86. A:
  87. inc esi
  88. cmp byte[esi],'b'
  89. je B
  90.  
  91. jmp Error1
  92. B:
  93. inc esi
  94. cmp byte[esi],'a'
  95. je BC
  96. cmp byte[esi],'b'
  97. je BC
  98.  
  99. jmp Error1
  100. C:
  101. inc esi
  102. cmp byte[esi],'$'
  103. je K
  104. jmp Error1
  105.  
  106.  
  107. BC:
  108. inc esi
  109. cmp byte[esi],'a'
  110. je BC
  111. cmp byte[esi],'b'
  112. je BC
  113.  
  114. cmp byte[esi],'$'
  115. je K
  116. jmp Error1
  117.  
  118. K: invoke WriteConsole,[stdout],MsgOK,lenMsgOK,NULL,NULL
  119. jmp exit
  120. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  121. ;закрытие файла
  122. _closef:
  123. invoke CloseHandle,[_hFile]
  124. mov [_hFile],0
  125. jmp exit
  126. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. ;ошибки
  128. ErrRead:
  129. cinvoke printf,"Ошибка прочтения файла",10,13
  130. jmp exit
  131.  
  132. Error1:
  133. invoke WriteConsole,[stdout],MsgNO,lenMsgNO,NULL,NULL
  134. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. exit:
  136. cinvoke getchar
  137. cinvoke getchar
  138. invoke ExitProcess,0
  139. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140. section '.idata' import data readable writeable
  141. library kernel32,'KERNEL32.DLL',msvcrt,'msvcrt.dll'
  142. import kernel32,\
  143. GetStdHandle,'GetStdHandle',\
  144. SetConsoleOutputCP,'SetConsoleOutputCP',\
  145. SetConsoleCP,'SetConsoleCP',\
  146. CreateFile,'CreateFileA',\
  147. GetFileSize,'GetFileSize',\
  148. ReadFile,'ReadFile',\
  149. WriteFile,'WriteFile',\
  150. CloseHandle,'CloseHandle',\
  151. SetFilePointer,'SetFilePointer',\
  152. WriteConsole,'WriteConsoleA',\
  153. ReadConsole,'ReadConsoleA',\
  154. ExitProcess,'ExitProcess',\
  155. GetProcessHeap,'GetProcessHeap',\
  156. HeapCreate,'HeapCreate',\
  157. HeapDestroy,'HeapDestroy',\
  158. HeapAlloc,'HeapAlloc',\
  159. HeapFree,'HeapFree'
  160. import msvcrt,\
  161. printf,'printf',\
  162. scanf,'scanf',\
  163. getchar,'getchar',\
  164. puts,'puts',\
  165. fscanf,'fscanf',\
  166. getch,'_getch'
  167. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement