Im just curious what register does lstrlen return in? Also can it count ascii in buffers?
Posted on 2002-11-03 13:27:19 by resistance_is_futile
It returns the lenght in eax and it counts the chars in your buffer until it reaches a 0.

:) JC
Posted on 2002-11-03 13:58:48 by JimmyClif
So does that mean if the buffer is like 256 dup(?) then it will return all zeros after it counts the actual count of whats in the buffer?
Posted on 2002-11-03 14:07:25 by resistance_is_futile
Strings in memory are typically "null terminated", meaning at the end of the byte array there is a 0 to indicate termination.

myString db "Hello World", 0

myString has a length of 11. Strlen() scans the bytes, counting as it goes, and when it finds a 0 it stops counting.
Posted on 2002-11-03 14:38:38 by iblis
oh okay. thanks for the explaination. Do you know of any thing (api etc) that can count what is inside a buffer. Like for example I put "Hello world" in a buffer (lets say this one: "mybuffer db 254 dup(?)"). Is there a way to get it to count and read out how many letters are in that buffer?
Posted on 2002-11-03 15:37:44 by resistance_is_futile
Originally posted by resistance_is_futile in thread lstrlen???
oh okay. thanks for the explaination. Do you know of any thing (api etc) that can count what is inside a buffer. Like for example I put "Hello world" in a buffer (lets say this one: "mybuffer db 254 dup(?)"). Is there a way to get it to count and read out how many letters are in that buffer?


Yes, there's an api called lstrlen which does exactly that :grin:

lol
Posted on 2002-11-03 16:49:33 by JimmyClif
lol Umm this doesnt work:


invoke lstrlen,offset Buffer
invoke MessageBox,0,eax,0,0


How do I get it to print out how many characters are in Buffer?
Posted on 2002-11-03 17:00:06 by resistance_is_futile
Use a debugger to see what it returns. It will return a number in eax.
This number will not be in ascii format - so you can't show it inside a MessageBox.
You have to convert the number first using for example the function from masmlib dwtoa. (Dword to Ascii)
So:



invoke lstrlen, ADDR Buffer
mov dword ptr [Buffer],0
mov dword ptr [Buffer+1],0
invoke dwtoa, eax, ADDR Buffer
invoke MessageBox, 0, ADDR Buffer, 0, 0
Posted on 2002-11-03 17:11:39 by JimmyClif
okay d00d thx a lot...
Posted on 2002-11-03 17:56:53 by resistance_is_futile