Hi

I have this buffer (32 bytes),
I put for instance a value like "50" in the buffer.
Now I want to prefix this value, with "0x"

If I use wsprintf (%#lX), the output will be
formatted so the value "50" is "vanished".

How can it be done like this: 0X50

regards,

The SharK
Posted on 2005-01-11 18:08:52 by The SharK
Something like this, maybe?



.486
.MODEL FLAT, STDCALL
option casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\advapi32.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\masm32.inc
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\advapi32.lib
includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\masm32.lib


Main PROTO

CTEXT MACRO text:VARARG
LOCAL TxtName
.data
TxtName BYTE text,0
.code
EXITM <ADDR TxtName>
ENDM

.const

.data
buffer db 32 dup (0)

.data?
buffer2 db 1024 dup (?)

.code
Start:

invoke Main
invoke ExitProcess, eax

Main proc

lea edx, buffer
mov BYTE PTR [edx], 50h

xor ecx, ecx
mov cl, BYTE PTR [edx]
invoke wsprintf, ADDR buffer2, CTEXT("%#x"), ecx
invoke StdOut, ADDR buffer2

xor eax, eax

Exitus:
ret
Main endp
end Start
Posted on 2005-01-12 04:44:26 by SamiP
%X format specifier is for when you pass integers to wsprintf. Ie, stuff like


.data
mydata DWORD 42
.code
invoke wsprintf, addr buf, CTEXT("0x%X - 0x%X"), 50, [mydata]

if you have the string "50" in you buffer, use '%s' instead of '%X'.
Posted on 2005-01-12 11:48:59 by f0dder


mov ecx,50h
invoke wsprintf,addr szBuffer, CTEXT("0x%2x"),ecx


This worked in my test, %2x forces it to be the 2 character long representation of the hex digit.

Regards,
Bryant Keller
Posted on 2005-01-12 11:49:55 by Synfire
If you want it to be 2 characters wide even if there's only one character of data you should use 0x%02x which will pad the beginning of your hex number with a 0 if needed.

Spara
Posted on 2005-01-12 13:22:39 by Sparafusile
The thing is, the number "50" I was talking
about, was the ASCII output - the ASCII code
was: 35 30.

So it's two bytes, which has to be converted to
one byte "50", and then use wsprintf with "%#X".

an alternative would be:
To define this buffer, as an UNDEFINED ASCIIZ string ?
then maybe "%s" would do it :)

But how do I append NULL to an undefined buffer,
to make it a string :?

regards,

The SharK
Posted on 2005-01-14 18:19:33 by The SharK
define vars
.data
PreFixStr db "0X",0

.data?
Buffer db 32 dup(?)
TempBuff db 34 dup(?)

those are the buffers you might want to use

now just used wsprint get your value into the main buffer

then use lstrcat

The lstrcat function appends one string to another.

LPTSTR lstrcat(

LPTSTR lpString1, // address of buffer for concatenated strings
LPCTSTR lpString2 // address of string to add to string1
);

If the function succeeds, the return value is a pointer to the buffer.


that would be the easy way..

lol i guess i did leave a few details out but i would hope you could figure the rest out..
Posted on 2005-01-17 20:33:37 by devilsclaw