News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

text to unicode format

Started by Magnum, November 24, 2012, 10:34:25 AM

Previous topic - Next topic

Magnum

I searched through the old forum but can't find what I am looking for.

Someone wrote a program that would convert text to this format.   'M','e','r','r','y'

Any ideas ?

Thanks,
               Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Gunner

This maybe? http://www.gunnerinc.com/files/unistring.zip
~Rob

qWord

The MASM32 SDK also contains macros that can be used to declare unicode strings -> see \masm32\hlhelp.chm
MREAL macros - when you need floating point arithmetic while assembling!

CommonTater

Quote from: qWord on November 24, 2012, 11:24:58 AM
The MASM32 SDK also contains macros that can be used to declare unicode strings -> see \masm32\hlhelp.chm

You may also want to take a look at a couple of windows apis I find extremely useful when reading and writing text files....

WideCharToMultiByte()  ...  utf16le (windows WCHAR) to utf8 or ansi.
MultiByteToWideChar() ... ansi or utf8 to utf16le.

Windows WCHAR is an unsigned 16 bit value
Windows CHAR is a signed 8 bit value (ansi)
Windows UCHAR is an unsigned 8 bit value (utf8)


Magnum

Quote from: qWord on November 24, 2012, 11:24:58 AM
The MASM32 SDK also contains macros that can be used to declare unicode strings -> see \masm32\hlhelp.chm

Thanks Qword.

So if I put this in__UNICODE__ equ 1, then I can fix this code which used to work, but now doesn't.  :biggrin:

Andy


;CONSOLE program
; RegisterEventSource.asm  Writes an event log in the Application section
;                         
.686
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\advapi32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\lib\advapi32.lib

.data

OutputBuffer BYTE 512 dup(0)
Provider_Name BYTE 'The provider', 0
Failed          BYTE 'Failure, Register Event Function Returned %d.',0
Success BYTE 'Success, Register Event Function Returned %d.', 0
AppName          BYTE 'SiegeWorks 2011',0

;                      Unicode created by UniString.exe
stringpointers WORD "T","h","i","s"," ","i","s"," ","a","n"," ","e","x","a","m","p","l","e"
                  WORD  "."," ","S","i","e","g","e","W","o","r","k","s"," ","2","0","1","1",0

p_string_input DWORD 0

.DATA?

hEventLog        HWND ?
dwEventDataSize WORD ?

.code

start:
invoke RegisterEventSource, 0, ADDR Provider_Name
mov hEventLog, EAX
call Display_Return_Message
lea EAX, stringpointers
mov p_string_input, EAX
invoke ReportEvent, hEventLog, \ ; handle to log file
1, \             ; EVENTLOG_ERROR_TYPE
2, \ ; DATABASE_CATEGORY
0C0000101H, \ ; MSG_BAD_FILE_CONTENTS the event ID
0, \ ; NULL
1, \ ; number input strings
0, \ ; number bytes to write in word value or 0
ADDR p_string_input, \ ; ADDRess of strings
0 ; pointer to binary data or NULL
call Display_Return_Message
invoke DeregisterEventSource, hEventLog
call Display_Return_Message
invoke ExitProcess, NULL

Display_Return_Message proc

.if EAX == 0
pusha
invoke GetLastError
invoke wsprintf, ADDR OutputBuffer, ADDR Failed, EAX
invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
popa
.endif

.if EAX != 0
invoke wsprintf, ADDR OutputBuffer, ADDR Success, EAX
invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
.endif
ret

Display_Return_Message endp

END start


Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

qWord

There are several macros that allows Unicode data without declaring the __UNICODE__ equate:
e.g.:
UCSTR Success,'Success, Register Event Function Returned %d.',13,10,0
UCSTR AppName ,'SiegeWorks 2011',0 ; the label is optional

Other macros are: WSTR, uni$(), A2WDAT, uc$(), ucc$() and UCCSTR.
Also, the macros fn, fnc, fnx, fncx, rv(), rvc(), rvx() and rvcx() allow string literals and are __UNICODE__ aware.
Furthermore the fnx/fncx/rvx/rvcx macros additional allow to explicit choose the type of string: L"unicode string" or A"ASCII string".

    fncx crt_wprintf,L"Success, Register Event Function Returned %d.\n",123


BTW: all macros are found in the file \masm32\macros\macros.asm, which must be included to use the macros ;-D
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

There are over 30 Unicode commands in MasmBasic - see here (all commands starting with w) and in particular \Masm32\RichMasm\Res\SkelFileIO_Unicode.asc for an example with Unicode filenames (the Arabic and Chinese charsets should be installed on your machine - see this thread). All you need to do is:
a) get the library
b) substitute include \masm32\include\masm32rt.inc with the first line of the snippet below.

For "true" Unicode, i.e. Chinese, Arabic etc, you need a resource file with a string table. It can then be accessed e.g. as wPrint wRes$(MyID).

include \masm32\MasmBasic\MasmBasic.inc   ; Download
   Init
   
wLet esi=wChr$("Hello coder")+wCrLf$+"How are you?"
   wPrint esi
   wMsgBox 0, esi, "Hello", MB_OK
   Exit
end start

Magnum

Thanks to everyone.

I read through macros.asm but I am not using this correctly.
It just shows the first character of my string.


UCSTR Fail,        "Failure, Register Event Function Returned.",13,10,0
UCSTR Success,"Success, Register Event Function Returned.",13,10,0

invoke GetLastError
invoke wsprintf, ADDR OutputBuffer, ADDR Fail, EAX
invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Try MessageBoxW

(writing Unicode to console is more tricky - use wPrint from the MasmBasic library if you really need it)

qWord

Quote from: Magnum on November 25, 2012, 12:57:41 AMIt just shows the first character of my string.
as JJ showed, you are probably using the ANSI version of the API. Also, note that UCSTR must be called from the .data section and not inside the code section.
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

Quote from: jj2007 on November 25, 2012, 01:06:55 AM
Try MessageBoxW

if you define the value __UNICODE__ before the include files,
calling MessageBox should get you the wide version automatically
notice that the wide version (where applicable) of all other functions will be used, as well
__UNICODE__ EQU 1
        include \masm32\include\masm32rt.inc

it doesn't matter what value you assign to __UNICODE__
in fact, you don't have to assign any value, you just have to define the symbol...
__UNICODE__ EQU
that should work   :P

Magnum

It's been a long long day.

This displays the right text along with some Chinese characters.



;CONSOLE program
;
; RegisterEventSource.asm  Writes an event log in the Application section
;                         

__UNICODE__=1 ; NEEDED ?
include \masm32\include\masm32rt.inc
include \masm32\include\advapi32.inc

includelib \masm32\lib\advapi32.lib

.data

OutputBuffer BYTE 512 dup(0)
Provider_Name BYTE 'The provider', 0

Fail    db "Failure, Register Event Function Returned %d.",0
Success db "Success, Register Event Function Returned %d.",0

;UCSTR AppName ,'SiegeWorks 2011',0 ; the label is optional
AppName          BYTE 'SiegeWorks 2012',0
;                     
stringpointers WORD "T","h","i","s"," ","i","s"," ","a","n"," ","e","x","a","m","p","l","e"
                  WORD  "."," ","S","i","e","g","e","W","o","r","k","s"," ","2","0","1","2",0

p_string_input DWORD 0

.DATA?

hEventLog        HWND ?
dwEventDataSize WORD ?

.code

start:

invoke RegisterEventSource, 0, ADDR Provider_Name
mov hEventLog, EAX
call Display_Return_Message
lea EAX, stringpointers
mov p_string_input, EAX
invoke ReportEvent, hEventLog, \ ; handle to log file
1, \             ; EVENTLOG_ERROR_TYPE
2, \ ; DATABASE_CATEGORY
0C0000101H, \ ; MSG_BAD_FILE_CONTENTS the event ID
0, \ ; NULL
1, \ ; number input strings
0, \ ; number bytes to write in word value or 0
ADDR p_string_input, \ ; ADDRess of strings
0 ; pointer to binary data or NULL
call Display_Return_Message
invoke DeregisterEventSource, hEventLog
call Display_Return_Message
invoke ExitProcess, NULL

Display_Return_Message proc

.if EAX == 0
pusha
invoke GetLastError
invoke wsprintf, ADDR OutputBuffer, ADDR Fail, EAX
invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
popa
.endif

.if EAX != 0
invoke wsprintf, ADDR OutputBuffer, ADDR Success, EAX
invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
.endif
ret

Display_Return_Message endp

END start
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

qWord

;CONSOLE program
;
; RegisterEventSource.asm  Writes an event log in the Application section
;                         

__UNICODE__=1 ; application is now TCHAR aware, so you will get the same result without __UNICODE__
include \masm32\include\masm32rt.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\advapi32.lib

; a little helper macro ;-D
TCHR macro lbl,literals:VARARG
        IFDEF __UNICODE__
                UCSTR lbl,literals
        ELSE
                lbl db literals
        ENDIF
endm

.data
        OutputBuffer     TCHAR   512 dup(0)
        TCHR Provider_Name,'The provider',0
       
        TCHR Fail,"Failure, Register Event Function Returned %d.",0
        TCHR Success,"Success, Register Event Function Returned %d.",0
       
        TCHR AppName,'SiegeWorks 2012',0
                   
        TCHR stringpointers,"This is an example",13,10
        TCHR               ,"SiegeWorks 2012",0

        p_string_input   PTCHAR  0

.data?
        hEventLog               HWND     ?
        dwEventDataSize         WORD     ?
.code

start:

invoke RegisterEventSource, 0, ADDR Provider_Name
         mov hEventLog, EAX
         call Display_Return_Message
         lea     EAX, stringpointers
         mov     p_string_input, EAX
         invoke ReportEvent, hEventLog, \                ; handle to log file
                 1, \                                        ; EVENTLOG_ERROR_TYPE
                 2, \                                            ; DATABASE_CATEGORY
                 0C0000101H, \                           ; MSG_BAD_FILE_CONTENTS the event ID
                 0, \                                            ; NULL
                 1, \                                            ; number input strings
                 0, \                                            ; number bytes to write in word value or 0
                 ADDR p_string_input, \                  ; ADDRess of strings
                 0                                               ; pointer to binary data or NULL
         call Display_Return_Message
         invoke DeregisterEventSource, hEventLog
         call Display_Return_Message
         invoke ExitProcess, NULL

Display_Return_Message proc

         .if EAX == 0
                 pusha
                 invoke GetLastError
                 invoke wsprintf, ADDR OutputBuffer, ADDR Fail, EAX
                 invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
                 popa
         .endif

         .if EAX != 0
                 invoke wsprintf, ADDR OutputBuffer, ADDR Success, EAX
                 invoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0
         .endif
         ret

Display_Return_Message endp

END start
MREAL macros - when you need floating point arithmetic while assembling!

Magnum

Event Type:   Error
Event Source:   桔⁥牰癯摩牥䘀楡畬敲‬敒楧瑳牥䔠敶瑮䘠湵瑣潩敒畴湲摥┠⹤匀捵散獳‬敒楧瑳牥䔠敶瑮䘠湵瑣潩敒畴湲摥┠⹤匀敩敧潗歲⁳〲㈱吀栀椀猀 椀猀 愀渀 攀砀愀洀瀀氀攀⸀ 匀椀攀最攀圀漀爀欀猀 ㈀ ㄀㈀
Event Category:   (2)
Event ID:   257
Thanks qWord.

I may use my original code as an anti debugging procedure.

Andy

Date:      11/24/2012
Time:      6:01:36 PM
User:      N/A
Computer:   
Description:
The description for Event ID ( 257 ) in Source ( 桔⁥牰癯摩牥䘀楡畬敲‬敒楧瑳牥䔠敶瑮䘠湵瑣潩敒畴湲摥┠⹤匀捵散獳‬敒楧瑳牥䔠敶瑮䘠湵瑣潩敒畴湲摥┠⹤匀敩敧潗歲⁳〲㈱吀栀椀猀 椀猀 愀渀 攀砀愀洀瀀氀攀⸀ 匀椀攀最攀圀漀爀欀猀 ㈀ ㄀㈀ ) cannot be found. The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. You may be able to use the /AUXSOURCE= flag to retrieve this description; see Help and Support for details. The following information is part of the event: This is an example. SiegeWorks 2012.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org