The MASM Forum

General => The Campus => Topic started by: Magnum on April 05, 2013, 10:16:28 AM

Title: Buffer not filling correctly
Post by: Magnum on April 05, 2013, 10:16:28 AM
This is only filling the buffer with one A.

Andy

xor ecx,ecx

comp:

mov    ebx,offset Buffer
mov    [ebx],byte ptr 'A'

inc    ebx
inc    ecx
cmp    ecx,5
jne    comp
Title: Re: Buffer not filling correctly
Post by: MichaelW on April 05, 2013, 11:01:05 AM
The code is setting EBX to the start of the buffer at the top of the loop... you  need to move your loop label.
Title: Re: Buffer not filling correctly
Post by: Gunner on April 05, 2013, 11:02:14 AM
xor     ecx,ecx

mov     ebx,offset Buffer

comp:
mov     [ebx],byte ptr 'A'

inc     ebx
inc     ecx
cmp     ecx,5
jne     comp


See the difference?  Your code, each time the loop starts you reload the Buffer address into ebx, move an "A", then reload the address.  You keep resetting the pointer each iteration.
Title: Re: Buffer not filling correctly
Post by: Magnum on April 05, 2013, 11:41:54 AM
Thanks.

Andy
Title: Re: Buffer not filling correctly
Post by: Magnum on April 06, 2013, 03:39:48 AM
I know that buffer overruns are bad, but I wanted to see what happened if I did.

If I put another buffer after the 1st one, it writes into that.

Otherwise, I assume it is writing over my code.

Just for information, when does that become a problem ?

I could not see any ill effects writing 30 bytes over.

Title: Re: Buffer not filling correctly
Post by: dedndave on April 06, 2013, 04:12:53 AM
it's a trick used for malware
we can't really discuss it any further on this forum   :P