I'm trying to make something similar to the grep tool, loop through a file trying to get the line(word) that matches my string. I have this code so far:
format PE GUI
entry start
include 'win32ax.inc'
.data
fileName db 'file.txt',0
fHandle dd 0
fSize dd 0
fSpace dd 0
asBytesRead dd 0
.code
start:
;Open File
invoke CreateFile, fileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
cmp eax, INVALID_HANDLE_VALUE
je show_error
mov [fHandle], eax
invoke GetFileSize, [fHandle], 0
cmp eax, 0ffffffffh
je show_error
mov [fSize], eax
invoke GlobalAlloc, GMEM_FIXED, [fSize]
test eax, eax
jz show_error
mov [fSpace], eax
invoke ReadFile, [fHandle], [fSpace], [fSize], asBytesRead, 0 ;needs lpNumberOfBytesRead
test eax, eax
jz show_error
invoke MessageBox, 0, [fSpace], 0, 0 ;show contents of file
jmp finish
show_error:
invoke MessageBox, 0, "Error!", "Error!", MB_OK
finish:
invoke CloseHandle, [fHandle] ;Close File
invoke ExitProcess, 0
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL', user32,'USER32.DLL'
include 'api/kernel32.inc'
include 'api/user32.inc'
My problem is that I dont know how to loop through the file line by line to get the ones that match.
I've written a DOS version too, but, I have the same problem (I dont know how to loop through the lines) and also when the file is big it doesnt open it (maybe cause its running on 16 bits mode).
Thanks a lot for your help!