flat assembler
Message board for the users of flat assembler.

Index > Windows > working with files

Author
Thread Post new topic Reply to topic
superj_2004



Joined: 28 Dec 2006
Posts: 4
superj_2004 28 Dec 2006, 17:56
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:

Code:
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!
Post 28 Dec 2006, 17:56
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 244
Location: US
Yardman 28 Dec 2006, 20:46
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:07; edited 1 time in total
Post 28 Dec 2006, 20:46
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 28 Dec 2006, 23:30
AsmRegEx - regular expression engine (see its trgrep.asm example)
Post 28 Dec 2006, 23:30
View user's profile Send private message Visit poster's website Reply with quote
superj_2004



Joined: 28 Dec 2006
Posts: 4
superj_2004 28 Dec 2006, 23:57
Thanks a lot for your replies! my code is now working perfectly!.
Post 28 Dec 2006, 23:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.