flat assembler
Message board for the users of flat assembler.

Index > Windows > Search a string in a text file

Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 06 Aug 2011, 18:39
Can any one tell me Is there a way of search a sring in a text file using windows API?
or please show me any other way Embarassed
I tried to do as following but failed,(full code attached with this)
Code:
Textsearch:
        invoke  CreateFile,FileName, GENERIC_READ + GENERIC_WRITE, 0, 0,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
        mov     [hFile], eax
        cmp     [hFile],INVALID_HANDLE_VALUE
        je      .inValHandle

        invoke  GetFileSize,fileSize,0

        mov     [fileSize],eax
        invoke  GlobalAlloc,0,fileSize
        mov     [dwBufferSize],eax
        cmp     [dwBufferSize],0
        je      .fileNtAlloc
        invoke  ReadFile,[hFile],dwBufferSize,fileSize,dwTextLength,0
        mov     edi,[dwBufferSize]
        mov     ecx,[fileSize]
        mov     esi,stxt
        mov     al, byte[esi]
        call    sloop

.inValHandle:
        invoke  MessageBox,[hwnddlg],text2,caption,NULL+MB_OK
        call    endn
;.invalTxtLen:
        ;invoke  MessageBox,[hwnddlg],text5,caption,NULL+MB_OK
        ;call    endn
.fileNtAlloc:
        invoke  MessageBox,[hwnddlg],text4,caption,NULL+MB_OK
        call    endn
sloop:
        repnz   scasb
        cmp     ecx,0
        je      .notfound
        invoke  lstrlen,stxt
        mov     [strlenth],eax
        mov     ecx,strlenth
        repz    cmpsb
        cmp     ecx,0
        je      .success
        jmp     sloop
        invoke  GlobalFree,dwBufferSize
        invoke  CloseHandle,[hFile]
        call    endn
.notfound:
        invoke  MessageBox,[hwnddlg],text6,caption,NULL+MB_OK
        call    endn
.success:

        invoke  MessageBox,[hwnddlg],text7,caption,NULL+MB_OK
        call    endn
endn:
        retn    
Confused

[Edit by Loco]Added code tags


Description:
Download
Filename: experi13.zip
Filesize: 1.82 KB
Downloaded: 294 Time(s)

Post 06 Aug 2011, 18:39
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 06 Aug 2011, 22:05
You can make a procedure that you can pass a base string and the string to find.

Code:
proc search bString,szFind
ret
endp

proc main

ReadFile,data

stdcall search,data,"string to search"    
Post 06 Aug 2011, 22:05
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 07 Aug 2011, 05:15
sorry typedef I'm still in a early stages of learning assembly.
Embarassed Rolling Eyes
can you explain more?
or point to a tutorial on that may be
thanks
Post 07 Aug 2011, 05:15
View user's profile Send private message Send e-mail Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 07 Aug 2011, 07:41
The WinAPI provides a strstr function for searching strings - http://msdn.microsoft.com/en-us/library/bb773436(v=vs.85).aspx
Post 07 Aug 2011, 07:41
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 13 Aug 2011, 18:09
I tried to use StrStrI function (source attached with this) but no success.
Please someone help me


Description:
Download
Filename: exp14.ASM
Filesize: 4.5 KB
Downloaded: 1586 Time(s)

Description:
Download
Filename: edx.txt
Filesize: 43 Bytes
Downloaded: 1552 Time(s)

Post 13 Aug 2011, 18:09
View user's profile Send private message Send e-mail Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 13 Aug 2011, 20:09
sorry there was a mistake in added file exp14.asm of previous post now corrected.
Post 13 Aug 2011, 20:09
View user's profile Send private message Send e-mail Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 15 Aug 2011, 18:51
At last I'v managed to write a code for search a sring in a text file. Laughing Very Happy
I'v used old CMPSB.If you interrested please check the attached files(please dwnlod both file to same directory)
thanx every one for helping me Smile


Description:
Download
Filename: edx.txt
Filesize: 44 Bytes
Downloaded: 1577 Time(s)

Description:
Download
Filename: exp15.ASM
Filesize: 4.67 KB
Downloaded: 1059 Time(s)

Post 15 Aug 2011, 18:51
View user's profile Send private message Send e-mail 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.