If I have a ten byte mem chunk that contains the following:
00 00 01 31 05 DB 0A 45 68 F3
and the first four bytes designate the IPX network number and the last six bytes designate the MAC address of the network card, how would I convert this straight into the format:
00-00-01-31:05-DB-0A-45-68-F3
for displaying in a MessageBox or the like.
I tried wsprintf with this as the template:
%02X-%02X-%02X-%02X:%02X-%02X-%02X-%02X-%02X-%02X
but it comes out crazy like this:
00-00-00-01:31-000000-05-0000-56
or something. Am I missing something? I dumped the mem block into a file and checked it with a hex editor and it looks just like at the top of the message. thx.
00 00 01 31 05 DB 0A 45 68 F3
and the first four bytes designate the IPX network number and the last six bytes designate the MAC address of the network card, how would I convert this straight into the format:
00-00-01-31:05-DB-0A-45-68-F3
for displaying in a MessageBox or the like.
I tried wsprintf with this as the template:
%02X-%02X-%02X-%02X:%02X-%02X-%02X-%02X-%02X-%02X
but it comes out crazy like this:
00-00-00-01:31-000000-05-0000-56
or something. Am I missing something? I dumped the mem block into a file and checked it with a hex editor and it looks just like at the top of the message. thx.
I think you should use an lstrcat.
I think this should work. storage must be in .data? section. completestorage can be in .data, and is the string in which you are going to add storage, for example: "completestorage: storage", so: "address: 05....etc".
Tell us if it works or not. Sorry if this is not correct, just tell me if not, and i will check it again.
See you
invoke wsprintf,addr storage,addr szformat, addr string
invoke lstrcat, addr completestorage, addr storage
I think this should work. storage must be in .data? section. completestorage can be in .data, and is the string in which you are going to add storage, for example: "completestorage: storage", so: "address: 05....etc".
Tell us if it works or not. Sorry if this is not correct, just tell me if not, and i will check it again.
See you
rdaneel, that looks right, but try this, too?
%.2X-%.2X-%.2X-%.2X:%.2X-%.2X-%.2X-%.2X-%.2X-%.2X
I have a project here that uses:
"%s, %lu, %lu%.9lu !"
...and it appears as expected.
Edit: Whoops, forgot that wsprintf doesn't truncate numbers that are bigger, so it's trying to convert a 32-bit number in each case and filling the possition with as many significant figures as it has or two - which ever is greater. This won't work - ignore me. :grin:
From the PSDK:
The width specification never causes a value to be truncated. The value is not truncated when the number of digits exceeds the specified precision
%.2X-%.2X-%.2X-%.2X:%.2X-%.2X-%.2X-%.2X-%.2X-%.2X
I have a project here that uses:
"%s, %lu, %lu%.9lu !"
...and it appears as expected.
Edit: Whoops, forgot that wsprintf doesn't truncate numbers that are bigger, so it's trying to convert a 32-bit number in each case and filling the possition with as many significant figures as it has or two - which ever is greater. This won't work - ignore me. :grin:
From the PSDK:
The width specification never causes a value to be truncated. The value is not truncated when the number of digits exceeds the specified precision
Each of the bytes must be expanded (zero padding) to a DWORD before they are used as arguments to wsprintf.
tank is correct.
.data
szFormat db "%02X-%02X-%02X-%02X:%02X-%02X-%02X-%02X-%02X-%02X",0
MemMac db 00h, 00h, 01h, 31h, 05h, 0DBh, 0Ah, 045h, 068h, 0F3h
szMacAddy db 40 dup (0)
.code
..
mov ecx, 10 ;10 bytes
@@:
movzx eax, byte ptr [MemMac+ecx]
push eax
dec ecx
jnz @b
push offset szFormat
push offset szMacAddy
call wsprintf
add esp, 4*(2+10) ;fix stack
invoke MessageBox, 0, addr szMacAddy, 0, MB_OK
Thanks everyone. It works fine now. So that means that wsprintf takes a DWORD value only. Either a DWORD address of a string in mem. or a DWORD integer value but it has to be a DWORD value for each argument. That makes sense. Most all the functions in the api take dword arguments don't they. Thanks again.