hi all.

i searched around a bit but can't seem to find what i'm looking for, i'm using a dialog box to help me debug my ever buggy program. i'm using setdlgitemtext which accepts a string but somtimes i need to put dwords there as weel as text, what i want to know is how to convert a dword to a string i can use with lstrcat and hence with setdlgitemtext.

it's probably simple.
Posted on 2003-03-26 20:20:11 by Crunchi
atodw found in masm or maybe search the algorithm forums for it. If you want, you can also use wsprintf
Posted on 2003-03-26 20:25:43 by roticv
If you're using MASM32 you can use dw2a like this

invoke dw2a, MyDword, ADDR MyStringBuffer

or if your using another assembler or want an alternative you can use the wsprintf API function :

fmtString db "%ld",0 ; put this in your data section

invoke wsprintf, ADDR MyStringBuffer, ADDR fmtString , MyDword
Posted on 2003-03-26 20:28:36 by donkey
thanks guys.

i went with donkeys suggestion, works great.

:alright:

thats the dw2a suggestion
Posted on 2003-03-26 21:03:11 by Crunchi
Hi

Here's an algorithm I've used for converting a hex string of any length to ascii. I pulled it together from information from Art of Assembly I think. I don't know how it compares to other routines, but some might find it useful.

Kayaker

[size=12]

; ----------------------------------------------------
; Routine for formatting hex string, on a per byte basis
; ----------------------------------------------------

mov ebx, StringLength
inc ebx ; add null terminator to length
lea edi, InputString ; hex string input from memory
lea esi, offset OutputBuff ; ascii string output (buffer size TWICE InputString)

UNPACKHEX2STRING ; MACRO

;========================================
; Macro to unpack hex data to a string
;========================================

UNPACKHEX2STRING MACRO
;-------------------------------------------------------------
; The shift right instruction is especially useful for unpacking data.
; For example, suppose you want to extract the two nibbles in the al register,
; leaving the H.O. nibble in ah and the L.O. nibble in al.
;-------------------------------------------------------------
.while ebx!=1
mov al, byte ptr [edi]
mov ah, al ; Get a copy of the H.O. nibble
shr ah, 4 ; Move H.O. to L.O. and clear H.O. nibble
and al, 0Fh ; Remove H.O. nibble from al
; 8Bh would now be unpacked as 080B in ax and
; each nibble can be converted to ascii separately

; Check H.O. bit (i.e. '8' of 8Bh)
.if ah<=9 ; if it's 0-9
add ah, 30h ; convert to ascii
.elseif ; if it's A-F
add ah, 37h ; convert to ascii
.endif
; Repeat for L.O. (i.e. 'B' of 8Bh)
.if al<=9
add al, 30h
.elseif
add al, 37h
.endif
mov byte ptr [esi], ah
mov byte ptr [esi+1], al
inc edi
add esi, 2
dec ebx
.endw
mov byte ptr [esi], 0 ; null terminate
ENDM

[/size]
Posted on 2003-03-26 22:27:13 by Kayaker
You know Crunchi if your using it for debugging you would be better off to get a debug program like Ollydbg or something similar. But if you're like me, somtimes you just want to know what a single number is at run time you can use the routine that I use for that :
 ShowNumber proc DeBuGNuM:DWORD

LOCAL tBuFfEr[16] :BYTE

pushad
jmp @F
DeBuGTeXt BYTE "Show Number",0
fMtStRiNg db "%ld",0
@@:

invoke wsprintf,ADDR tBuFfEr,ADDR fMtStRiNg,DeBuGNuM
invoke MessageBox,NULL,ADDR tBuFfEr,ADDR DeBuGTeXt,MB_OK
popad

ret
ShowNumber endp
The weird upper/lower case variables are because it's a snipplet and that format guarantees that it won't conflict with other variables. The data registers are preserved so you can put it anywhere without affecting your program. It only takes DWORDs but registers, constants and variables are fine. Just a thought, I use it constantly.

Use it like this

invoke ShowNumber, AnyDWORD
Posted on 2003-03-26 22:35:25 by donkey
that looks like a usefull tool, thanks.

i do use ollydebug but like you said, i just wanted to get 1 value, i had to use a dialog box as this value changes on a timer and i had to look at how it changes every 50mS. that would be WAY too many messageboxes.

this may not be any use to anyone, the resource is pretty much just a hack from icz's tute, you have to include this text into your own rsrc file. call MakeBug after you call createwindowex, then a call to SendBug or SendBugDW will put things right. there are probably 1,000,000 ways to do this better but this one worked for me. any other hints welcome.

;bug .inc
; include this in you asm file
; include your .inc file here
;prototypes

MakeBug PROTO
DlgProc PROTO :HWND, :DWORD, :DWORD, :DWORD


;macros

SendBug MACRO Messsage

invoke SendMessage,DlgHndl,MM_BUGDIALOG,NULL,Messsage

ENDM

SendBugDW MACRO Messsage

invoke dw2a, Messsage, ADDR StringBuffer
invoke SendMessage,DlgHndl,MM_BUGDIALOG,NULL,ADDR StringBuffer

ENDM

.data

DlgName db "MyDialog",0
DlgHndl dd 0

.data?

buff db 20000 dup(?)
StringBuffer db 20 dup(?)

.const

MM_BUGDIALOG equ 3001

MAX equ 20000

IDM_EXIT equ 1
IDM_ABOUT equ 2
IDC_EDIT equ 3000
IDC_EXIT equ 3002

.code


MakeBug proc

invoke CreateDialogParam, hInstance, addr DlgName,hWnd,OFFSET DlgProc,NULL
mov DlgHndl, eax

MakeBug endp

DlgProc PROC _hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM
.if iMsg==WM_INITDIALOG
invoke GetDlgItem,_hWnd,IDC_EDIT
invoke SetFocus,eax
mov eax, _hWnd
.elseif iMsg==WM_CLOSE
invoke EndDialog,_hWnd,NULL
mov DlgHndl,0
.elseif iMsg==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
.if dx==BN_CLICKED
.if eax==IDC_EXIT
invoke SendMessage,_hWnd,WM_CLOSE,NULL,NULL
.endif
.endif
.elseif iMsg==MM_BUGDIALOG

invoke GetDlgItemText,_hWnd,IDC_EDIT,ADDR buff, MAX
invoke lstrcat, addr buff, addr newl
invoke lstrcat, addr buff, lParam
invoke SetDlgItemText,_hWnd,IDC_EDIT,ADDR buff
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp

***********************************************
resource file addin,
***********************************************
// constants for dialog box
#define IDC_EDIT 3000
#define IDC_EXIT 3002
#define WS_MINIMIZEBOX 0x00020000L
#define WS_SYSMENU 0x00080000L
#define WS_VISIBLE 0x10000000L
#define WS_OVERLAPPED 0x00000000L
#define DS_MODALFRAME 0x80L
#define DS_3DLOOK 0x0004L
#define WS_CAPTION 0xC00000L
#define ES_AUTOHSCROLL 0x80L
#define ES_AUTOVSCROLL 0x40L
#define ES_LEFT 0
#define ES_MULTILINE 0x4L
#define WS_VSCROLL 0x200000L

MyDialog DIALOG 0, 0, 205, 300
STYLE 0x0004 | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Le Bugger!"
BEGIN

PUSHBUTTON "E&xit", IDC_EXIT, 10,10,52,13

EDITTEXT IDC_EDIT, 10,28,185,267, ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_LEFT | ES_MULTILINE |WS_VSCROLL

END
Posted on 2003-03-26 22:58:48 by Crunchi
Crunchi,

You can use also the VkDebug library:




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
include \masm32\include\debug.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\debug.lib

.data
.code
start:
mov eax,12345678
PrintDec eax
invoke ExitProcess,0
end start

Posted on 2003-03-27 03:26:00 by Vortex
hmmmm....

learn a new thing every day you do...
Posted on 2003-03-27 23:48:41 by Crunchi