The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: remus2k on December 06, 2006, 07:53:01 PM

Title: help with bypass chars in file
Post by: remus2k on December 06, 2006, 07:53:01 PM
hello peoples

can your help me with bypass chars in file?

my source is added

thanks

remus

[attachment deleted by admin]
Title: Re: help with bypass chars in file
Post by: PBrennick on December 06, 2006, 10:54:03 PM
remus2k,
It looks like you need to set up a loop so that you can fill the display buffer. If I add a sentence to the beginning of test.txt  a messagebox will pop up showing the first character just as it should. Then the empty dialog box appears.... what's up with that? Just what do you want to do? Do you want to display what is in text.txt except for commented lines?

Paul
Title: Re: help with bypass chars in file
Post by: Tedd on December 07, 2006, 12:55:44 PM
What your code currently does is read ONE character from the file and then show a messagebox if it's not '-'
We can guess at what you're trying to do, but whatever it is, you'll probably need to read more characters than just the first one :wink

Change the call to ReadFile to:
invoke ReadFile, hFile,addr hBuffer,SIZEOF hBuffer,addr NumberOfBytes,NULL
and that will read up to 255 characters from the file (all of the file if it is smaller.)

Then what you need to do is increase the pointer (edi) to move onto the next character, so you can check what it is.
If you want to remove '-' characters, then you'll need to copy the characters that don't match into a new buffer, so you can print them when you've got them all.
Title: Re: help with bypass chars in file
Post by: remus2k on December 07, 2006, 05:27:55 PM
thanks for your help first times :U

I do not want that it am in such a way indicated each stringer in messagesbox am indicated
I have much try out I do not understand that!

can help their me still times please?

           invoke CreateFile,offset szFile,GENERIC_READ or GENERIC_WRITE,\
                                             FILE_SHARE_READ or FILE_SHARE_WRITE,0,\
                                               OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0                   
              mov hFile,eax
           invoke GetFileSize,eax,NULL
           invoke ReadFile, hFile,addr hReadBuffer,SIZEOF hReadBuffer,addr NumberOfBytes,NULL
              mov esi, offset hReadBuffer ; esi = beginning of the string
               xor ecx, ecx                ; ecx = 0
     
@read:   
         cmp BYTE PTR [esi], '-'     ; [esi] == [-]
          jne @1                           ; TRUE: jump to @1
         jmp @ret
@1:     
          inc esi
        mov edi,esi
        cmp BYTE PTR [esi], '-'     ; [esi] == [-]
           je @Print
@Print:
          invoke MessageBox,hWnd,edi,NULL,MB_OK
         jmp @read
@ret:

greets
remus2k
Title: Re: help with bypass chars in file
Post by: Tedd on December 07, 2006, 06:29:06 PM
You want..

"-test1-test2-test3-" ==>

    MessageBox("test1")
    MessageBox("test2")
    MessageBox("test3")

??
Title: Re: help with bypass chars in file
Post by: ragdog on December 07, 2006, 06:39:52 PM
I become times example search
Title: Re: help with bypass chars in file
Post by: remus2k on December 07, 2006, 06:45:07 PM
yes Tedd that is this what i want
Title: Re: help with bypass chars in file
Post by: Tedd on December 07, 2006, 09:59:33 PM
So, you need TWO buffers - one to read the file into, and the other to copy the string characters into (so you can show them in the messageox)

Steps:
  - open file; read file (into buffer1); close file
  *loop:
  - parse string, looking for '-' (from buffer1)
  - when found, copy characters from buffer1 into buffer2, until you find another '-' (or end of file data)
  - show messagebox for buffer2
  - get character at current position in buffer1, if '-' then loop, else finish
Title: Re: help with bypass chars in file
Post by: ragdog on December 07, 2006, 10:19:39 PM
thanks :wink

i hope that“s works

ragdog
Title: Re: help with bypass chars in file
Post by: PBrennick on December 07, 2006, 10:48:41 PM
Make sure you terminate buffer2 with a 0 before you display the text. You should clear the buffer between writes, also. It does not matter in this example as the 3 strings are the same size but it is good to develop certain habits.

Paul
Title: Re: help with bypass chars in file
Post by: Relvinian on December 08, 2006, 03:11:20 AM
Another option besides what Tedd wrote (which is a better choice) is to just NULL terminate the chars you don't want to be displayed. Then you already have a NULL terminated string to display and can just advance a pointer to the start of the next display string.

Relvinian
Title: Re: help with bypass chars in file
Post by: Tedd on December 08, 2006, 01:39:28 PM
Quote from: Relvinian on December 08, 2006, 03:11:20 AM
Another option besides what Tedd wrote (which is a better choice) is to just NULL terminate the chars you don't want to be displayed. Then you already have a NULL terminated string to display and can just advance a pointer to the start of the next display string.
This is true, though it is destructive. In this instance it doesn't really matter, but it's not generally a good practice.
Title: Re: help with bypass chars in file
Post by: ragdog on December 08, 2006, 03:50:21 PM
hi remus

here is your workig code :U

[attachment deleted by admin]
Title: Re: help with bypass chars in file
Post by: Relvinian on December 09, 2006, 12:17:37 AM
Quote from: Tedd on December 08, 2006, 01:39:28 PM
Quote from: Relvinian on December 08, 2006, 03:11:20 AM
Another option besides what Tedd wrote (which is a better choice) is to just NULL terminate the chars you don't want to be displayed. Then you already have a NULL terminated string to display and can just advance a pointer to the start of the next display string.
This is true, though it is destructive. In this instance it doesn't really matter, but it's not generally a good practice.


You are correct...It all depends on the situation you are designing for. Some buffers can be used as destructive while others can't. That's left up to the programmer of said functions.

Relvinian
Title: Re: help with bypass chars in file
Post by: ragdog on December 17, 2006, 07:31:17 PM
i have drouble with copy string in register

i will not use lstrcat algo
can your help me thats the string copy in the register“s

my source is posted

greetz ragdog

[attachment deleted by admin]
Title: Re: help with bypass chars in file
Post by: ragdog on December 17, 2006, 09:34:41 PM
I created it so far
as I delete the last character ( - ) into my string

           invoke CreateFile,offset szFile,GENERIC_READ or GENERIC_WRITE,\
                                             FILE_SHARE_READ or FILE_SHARE_WRITE,0,\
                                               OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0                   
              mov hFile,eax
     invoke ReadFile, hFile,addr hRead,sizeof hRead,addr NumberOfBytes,0       
        mov edi, offset hData
        mov esi, offset hRead         
        mov ebx,0
     @@:   
        mov al, byte ptr [esi]  ; read byte
        mov byte ptr [edi], al  ; write byte
        cmp al,"-"              ; did we copy a null?
         je @print              ; done
        inc esi                 ; else increment pointers using INC
        inc edi
        jmp @B
@print:
        mov edi,offset hData
     invoke MessageBox,hWnd,offset hData,0,MB_OK
        inc esi               
        inc ebx               
        cmp ebx,3
        jne @B

ragdog
Title: Re: help with bypass chars in file
Post by: Tedd on December 18, 2006, 12:35:04 PM
            jmp @B
    @print:
            mov BYTE PTR [edi],0    ; <------- ADD ME!!!
            mov edi,offset hData


:U
Title: Re: help with bypass chars in file
Post by: PBrennick on December 18, 2006, 02:03:17 PM
RagDog,
As Tedd has said (without saying it), you did not zero terminate the buffer. You need to do this before you can use the buffer in , for example, a MessageBox.

BTW: That is an interesting choice of an avatar...

Paul
Title: Re: help with bypass chars in file
Post by: ragdog on December 18, 2006, 04:29:25 PM
thank tedd this works :U
and paul for the info


regards
ragdog