Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- format PE console
- entry start
- include 'includes\win32ax.inc'
- section '.data' data readable writeable
- fileName db 20 dup(0)
- lfileName dd ?
- flength dd ?
- fbuf dd ?
- hHeap dd ?
- _hFile dd ?
- _r dd 00
- Msg db 'Input string : '
- lenMsg = $ - Msg
- MsgOK db 'Correct string '
- lenMsgOK = $ - MsgOK
- MsgNO db 'Incorrect string '
- lenMsgNO = $ - MsgNO
- stdin dd ?
- stdout dd ?
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- section '.code' code readable executable
- start:
- invoke SetConsoleOutputCP,CP_UTF8
- invoke SetConsoleCP,CP_UTF8
- invoke GetStdHandle, STD_OUTPUT_HANDLE
- mov [stdout],eax
- invoke GetStdHandle, STD_INPUT_HANDLE
- mov [stdin],eax
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;запрашиваем имя файла
- cinvoke printf,'%s',<'Имя файла: ',0>
- invoke ReadConsole,[stdin],fileName,20,lfileName,NULL
- mov ebx,lfileName
- sub [lfileName],2
- mov ebx,[lfileName]
- mov [fileName + ebx],0
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;открываем файл для чтения
- invoke CreateFile,fileName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
- mov [_hFile],eax
- cmp eax,0
- je ErrRead
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;длина файла
- invoke GetFileSize,[_hFile],flength
- cmp eax,0
- je ErrRead
- mov [flength],eax
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;выделение памяти
- invoke GetProcessHeap
- cmp eax,NULL
- jne GoodHeap
- cinvoke printf,"Ошибка выделения памяти"
- jmp _closef
- GoodHeap:
- mov [hHeap],eax
- mov ebx,[flength]
- add ebx,2
- invoke HeapAlloc,[hHeap],HEAP_ZERO_MEMORY,ebx
- test eax,eax
- jz _closef
- mov [fbuf],eax
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;Чтение файла
- invoke ReadFile,[_hFile],[fbuf],[flength],_r,NULL
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;Вывод на консоль
- cinvoke puts,[fbuf]
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;работа автомата
- mov esi,[fbuf]
- mov edi,[flength]
- mov byte [esi + edi],'$'
- cinvoke puts,[fbuf]
- S:
- cmp byte[esi],'a'
- je A
- jmp Error1
- A:
- inc esi
- cmp byte[esi],'b'
- je B
- jmp Error1
- B:
- inc esi
- cmp byte[esi],'a'
- je BC
- cmp byte[esi],'b'
- je BC
- jmp Error1
- C:
- inc esi
- cmp byte[esi],'$'
- je K
- jmp Error1
- BC:
- inc esi
- cmp byte[esi],'a'
- je BC
- cmp byte[esi],'b'
- je BC
- cmp byte[esi],'$'
- je K
- jmp Error1
- K: invoke WriteConsole,[stdout],MsgOK,lenMsgOK,NULL,NULL
- jmp exit
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;закрытие файла
- _closef:
- invoke CloseHandle,[_hFile]
- mov [_hFile],0
- jmp exit
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ;ошибки
- ErrRead:
- cinvoke printf,"Ошибка прочтения файла",10,13
- jmp exit
- Error1:
- invoke WriteConsole,[stdout],MsgNO,lenMsgNO,NULL,NULL
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- exit:
- cinvoke getchar
- cinvoke getchar
- invoke ExitProcess,0
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- section '.idata' import data readable writeable
- library kernel32,'KERNEL32.DLL',msvcrt,'msvcrt.dll'
- import kernel32,\
- GetStdHandle,'GetStdHandle',\
- SetConsoleOutputCP,'SetConsoleOutputCP',\
- SetConsoleCP,'SetConsoleCP',\
- CreateFile,'CreateFileA',\
- GetFileSize,'GetFileSize',\
- ReadFile,'ReadFile',\
- WriteFile,'WriteFile',\
- CloseHandle,'CloseHandle',\
- SetFilePointer,'SetFilePointer',\
- WriteConsole,'WriteConsoleA',\
- ReadConsole,'ReadConsoleA',\
- ExitProcess,'ExitProcess',\
- GetProcessHeap,'GetProcessHeap',\
- HeapCreate,'HeapCreate',\
- HeapDestroy,'HeapDestroy',\
- HeapAlloc,'HeapAlloc',\
- HeapFree,'HeapFree'
- import msvcrt,\
- printf,'printf',\
- scanf,'scanf',\
- getchar,'getchar',\
- puts,'puts',\
- fscanf,'fscanf',\
- getch,'_getch'
- ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement