flat assembler
Message board for the users of flat assembler.

Index > Windows > problem with proc...

Author
Thread Post new topic Reply to topic
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 14 Jan 2006, 21:24
I dont understand why it is showing up "szCatStr" in second messagebox... i converted most of m32lib to fasm and im having all procs in same file for testing if these kind of errors happen and these procs doesnt seem to get along together Sad
maybe szCatStr isnt pushing/popping everything it should?
Code:
format PE GUI 4.0
include '%fasminc%\WIN32AXP.INC'

.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
proc szLen stdcall,\
           src:DWORD

    mov eax, [src]
    sub eax, 4

  @@:
    add eax, 4
    cmp byte [eax], 0
    je lb1
    cmp byte [eax+1], 0
    je lb2
    cmp byte [eax+2], 0
    je lb3
    cmp byte [eax+3], 0
    jne @B

    sub eax, [src]
    add eax, 3
    ret
  lb3:
    sub eax, [src]
    add eax, 2
    ret
  lb2:
    sub eax, [src]
    add eax, 1
    ret
  lb1:
    sub eax, [src]
    ret

endp

proc szCatStr stdcall uses edx edi ecx,\
              szSource:DWORD, szAdd:DWORD

    stdcall szLen,[szSource] ; get source length
    mov edi, [szSource]
    mov ecx, [szAdd]
    add edi, eax            ; set write starting position
    xor edx, edx            ; zero index
    xor eax, eax            ; avoid stall with following AL reads and writes

  @@:
    mov al, [ecx+edx]       ; write append string to end of source
    mov [edi+edx], al
    add edx, 1
    test al, al             ; exit when terminator is written
    jne @B

    mov eax, [szSource]     ; return start address of source
    ret

endp

proc szTrim stdcall uses esi edi ecx edx,\
            src:DWORD

    mov esi, [src]
    mov edi, [src]
    xor ecx, ecx

    sub esi, 1
  @@:
    add esi, 1
    cmp byte [esi], 32  ; strip space
    je @B
    cmp byte [esi], 9   ; strip tab
    je @B
    cmp byte [esi], 0   ; test for zero after tabs and spaces
    jne @F
    xor eax, eax            ; set EAX to zero on 0 length result
    mov byte [edi], 0   ; set string length to zero
    jmp tsOut               ; and exit

  @@:
    mov al, [esi+ecx]       ; copy bytes from src to dst
    mov [edi+ecx], al
    add ecx, 1
    test al, al
    je @F                   ; exit on zero
    cmp al, 33              ; don't store positions lower than 33 (32 + 9)
    jb @B
    mov edx, ecx            ; store count if asc 33 or greater
    jmp @B

  @@:
    mov byte [edi+edx], 0   ; write terminator

    mov eax, edx            ; return trimmed string length
    mov ecx, [src]

  tsOut:

    ret

endp
  
start:
        stdcall   szCatStr,szSrcString," szCatStr"
        invoke    MessageBox,0,eax,"szCatStr",0

        stdcall   szTrim,szTrimString
        invoke    MessageBox,0,szTrimString,"szTrim",0

        invoke    ExitProcess,0

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

.data

        szSrcString        db      "okasvialkokasvisjdokasvi",0
        szTrimString       db      "            okasvi          ",0 ; contains spaces(byte 32) and tabs(byte 9)
        szDstString        rb      100 ;dup (0)

.end start    

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 14 Jan 2006, 21:24
View user's profile Send private message MSN Messenger Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 14 Jan 2006, 21:37
when i went thru it with OllyDbg i think error is here in szCatStr:

Code:
  @@:
    mov al, [ecx+edx]       ; write append string to end of source
    mov [edi+edx], al
    add edx, 1
    test al, al             ; exit when terminator is written
    jne @B     

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 14 Jan 2006, 21:37
View user's profile Send private message MSN Messenger Reply with quote
velox



Joined: 06 Jan 2006
Posts: 14
velox 14 Jan 2006, 21:58
this is because you overwrite szTrimString with "szCatStr" when you call
szCatStr,szSrcString," szCatStr"

you should reserve more bytes at the end of szSrcString, or better add an
additional argument for your szCatStr function -> a DstString:DWORD
Post 14 Jan 2006, 21:58
View user's profile Send private message Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi 15 Jan 2006, 02:24
Thanks Smile

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 15 Jan 2006, 02:24
View user's profile Send private message MSN Messenger 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.