udw2str proc dwNumber:DWORD, pszString:DWORD
push ebx
push esi
push edi
mov eax, [dwNumber]
mov esi, [pszString]
mov edi, [pszString]
mov ecx,429496730
@@redo:
mov ebx,eax
mul ecx
mov eax,edx
lea edx,[edx*4+edx]
add edx,edx
sub ebx,edx
add bl,'0'
mov [esi],bl
inc esi
test eax, eax
jnz @@redo
jmp @@chks
@@invs:
dec esi
mov al, [edi]
xchg [esi], al
mov [edi], al
inc edi
@@chks:
cmp edi, esi
jb @@invs
pop edi
pop esi
pop ebx
ret
udw2str endp
error changed:
udw2str proc dwNumber:QWORD, pszString:QWORD
push rbx
push rsi
push rdi
mov rax,dwNumber
mov rsi,pszString
mov rdi,pszString
mov rcx,0199999999999999Ah
@@redo:
mov rbx,rax
mul rcx
mov rax,rdx
lea rdx,[rdx*4+rdx]
add rdx,rdx
sub rbx,rdx
add bl,'0'
mov [rsi],bl
inc rsi
test rax, rax
jnz @@redo
jmp @@chks
@@invs:
dec rsi
mov al, [rdi]
xchg [rsi], al
mov [rdi], al
inc rdi
@@chks:
cmp rdi, rsi
jb @@invs
pop rdi
pop rsi
pop rbx
ret
udw2str endp
This is a recursive variation, which supports radix and can be easily changed to support qwords as well:
includelib \masm32\lib64\kernel32.lib
ExitProcess PROTO :dword
includelib \masm32\lib64\msvcrt.lib
printf PROTO :ptr, :vararg
RADIX=16
.data
value dd 0AA773145h
;value dd 2859938117
result db 32 dup (0)
.code
utostr64 proc pValue:dword, pStr:PTR, itCount:dword
LOCAL locValue : DWORD
and rsp, -16
mov r9, rdx
mov locValue, 0
cmp r8,0
jnz @F
mov r10d, ecx
@@:
cmp ecx, RADIX
jb L0
mov rax, rcx
mov ecx, RADIX
xor rdx, rdx
div ecx
mov locValue, eax
mov rdx, r9
mov ecx, eax
inc r8
call utostr64
L0:
xor rdx, rdx
mov eax, locValue
mov ecx, RADIX
div ecx
cmp edx, 10
jb @F
add edx, 55
jmp short L1
@@:
add edx, 48
L1:
mov byte ptr [r9], dl
inc r9
mov rdx, r9
mov ecx, locValue
cmp r8,0
jnz @F
mov locValue, r10d
dec r8
jmp short L0
@@:
dec r8
ret
utostr64 endp
main proc
sub rsp, 28h
mov r8, 0
mov ecx, value
mov rdx, OFFSET result
call utostr64
mov rcx, OFFSET result
call printf
mov ecx,0
call ExitProcess
main endp
end
So it prints:
0AA773145
hi,aw27
thanks you very much.
your codes works well.
the following codes is being crashed. i don't know that's why.
Quote\UASM64\bin\uasm64 -c -win64 %name%.asm
\UASM64\bin\rc %name%.rc
\UASM64\bin\link /ENTRY:start /SUBSYSTEM:windows /MACHINE:X64 %name%.obj %name%.res
UASM v2.46, Dec 4 2017, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
gdiType_3.asm: 162 lines, 3 passes, 170 ms, 0 warnings, 0 errors
Microsoft (R) Windows (R) Resource Compiler Version 6.3.9600.17336
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
option casemap:none
option win64:7
include \UASM64\include\windows.inc
include \UASM64\include\gdiplus.inc
includelib \UASM\UASM64\Lib\user32.lib
includelib \UASM\UASM64\Lib\kernel32.lib
includelib \UASM\UASM64\Lib\gdiplus.lib
includelib \UASM\UASM64\Lib\Ole32.lib
includelib \UASM\UASM64\Lib\NtosKrnl.lib
ICO_MAIN equ 1000
DLG_MAIN equ 100
IDC_CLEAR equ 101
IDC_START equ 102
IDC_OUTPUT equ 103
comment #
ImageCodecInfo struct
;public:
Clsid CLSID <>
FormatID GUID <>
CodecName DWORD ?
DllName DWORD ?
FormatDescription DWORD ?
FilenameExtension DWORD ?
MimeType DWORD ?
Flags DWORD ?
Version DWORD ?
SigCount DWORD ?
SigSize DWORD ?
SigPattern DWORD ?
SigMask DWORD ?
ImageCodecInfo ends
#
.data?
hInstance dq ?
hWinMain dq ?
m_gdiplusToken dd ?
@gdis GdiplusStartupInput <?>
num dd ?
_size dd ?
pImageCodecInfo dq ?
.data
swTest dw "1","2","3","A","B","C",0,0
.code
UnicodeStrAscii PROC USES rsi rbx src:QWORD,dest:QWORD
mov rsi,src
mov rbx,1
mov rdx,dest
xor rax,rax
sub rax,rbx
@@:
add rax,rbx
movzx rcx, WORD PTR [rsi+rax*2]
mov BYTE PTR [rdx+rax],cl
test rcx,rcx
jnz @b
ret
UnicodeStrAscii ENDP
GetEncoderClsids proc uses rbx rsi rdi _hWnd:qword
LOCAL strGuid[2048]:BYTE
LOCAL _szBuffer[256]:BYTE
LOCAL ansiTxt[128]:BYTE
LOCAL ansiTxt1[256]:BYTE
invoke RtlZeroMemory,ADDR strGuid, sizeof strGuid
invoke GdipGetImageEncodersSize, addr num ,addr _size
xor edi,edi
mov ecx,_size
.if ecx
invoke GlobalAlloc,GPTR,_size
mov pImageCodecInfo,rax
invoke GdipGetImageEncoders,num, _size,pImageCodecInfo
mov rsi,pImageCodecInfo
@@:
invoke RtlZeroMemory,ADDR ansiTxt, sizeof ansiTxt
invoke StringFromGUID2,rsi,addr _szBuffer,sizeof _szBuffer
invoke WideCharToMultiByte,CP_ACP,0,addr _szBuffer,-1,addr ansiTxt,sizeof ansiTxt,0,0
invoke RtlZeroMemory,ADDR ansiTxt1, sizeof ansiTxt1
;int 3
xor rbx,rbx
mov rbx,qword ptr[rsi].ImageCodecInfo.MimeType
;invoke UnicodeStrAscii,rbx, addr ansiTxt1 ;--》called at second , crashed.
invoke UnicodeStrAscii,addr swTest, addr ansiTxt1
invoke lstrcat,addr strGuid,CStr("Type: ")
invoke lstrcat,addr strGuid,addr ansiTxt1
invoke lstrcat,addr strGuid,CStr(", GUID: ")
invoke lstrcat,addr strGuid,addr ansiTxt
invoke lstrcat,addr strGuid,CStr(13,10)
invoke SetDlgItemText,_hWnd,IDC_OUTPUT,addr strGuid
add rsi, sizeof ImageCodecInfo
inc edi
cmp edi,num
jne @B
invoke GlobalFree,pImageCodecInfo
.endif
ret
GetEncoderClsids endp
_ProcDlgMain proc uses rbx rsi rdi hWnd:qword,wMsg:dword,wParam:qword,lParam:qword
mov eax,wMsg
.if eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
.elseif eax == WM_COMMAND
mov rax,wParam
.if ax == IDC_CLEAR
invoke SetDlgItemText,hWnd,IDC_OUTPUT,NULL
.elseif ax == IDC_START
invoke GetEncoderClsids,hWinMain
.endif
.elseif eax == WM_CLOSE
invoke EndDialog,hWnd,NULL
.else
mov rax,FALSE
ret
.endif
mov rax,TRUE
ret
_ProcDlgMain endp
start Proc
invoke GetModuleHandle,NULL
mov hInstance,rax
mov @gdis.GdiplusVersion, 1
mov @gdis.DebugEventCallback, 0
mov @gdis.SuppressBackgroundThread, 0
mov @gdis.SuppressExternalCodecs, 0
invoke GdiplusStartup,ADDR m_gdiplusToken,ADDR @gdis,0
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke GdiplusShutdown,m_gdiplusToken
invoke ExitProcess,NULL
start Endp
end
#include <\UASM64\include\resource.h>
#define ICO_MAIN 1000
#define DLG_MAIN 100
#define IDC_CLEAR 101
#define IDC_START 102
#define IDC_OUTPUT 103
DLG_MAIN DIALOG 210, 108, 288, 150
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Test_GetEncoderClsids"
FONT 11, "Calibri"
{
EDITTEXT IDC_OUTPUT, 7, 2, 274, 125,ES_MULTILINE | ES_AUTOVSCROLL | WS_BORDER | WS_TABSTOP | WS_VSCROLL
PUSHBUTTON "Clear(&C)", IDC_CLEAR,202, 131, 40, 14
PUSHBUTTON "Get(&G)", IDC_START, 243, 131, 40, 14, WS_TABSTOP
}
six_L,
The structure ImageCodecInfo is not correctly defined for 64-bit.
This is not a rare event.
ImageCodecInfo struct
ClassID CLSID <>
FormatID GUID <>
CodecName QWORD ?
DllName QWORD ?
FormatDescription QWORD ?
FilenameExtension QWORD ?
MimeType QWORD ?
Flags DWORD ?
Version DWORD ?
SigCount DWORD ?
SigSize DWORD ?
SigPattern QWORD ?
SigMask QWORD ?
ImageCodecInfo ends
ImageCodecInfo (https://msdn.microsoft.com/en-us/library/aa452241.aspx)
hi: aw27,mabdelouahab.
it has worked at last.
thanks for yours guidance.