### Author Topic: text to unicode format  (Read 11700 times)

#### Magnum

• Member
• Posts: 2351
##### text to unicode format
« on: November 24, 2012, 10:34:25 AM »
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

• Regular Member
• Posts: 48
##### Re: text to unicode format
« Reply #1 on: November 24, 2012, 11:04:14 AM »
~Rob

#### qWord

• Member
• Posts: 1473
• The base type of a type is the type itself
##### Re: text to unicode format
« Reply #2 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
MREAL macros - when you need floating point arithmetic while assembling!

#### CommonTater

• Guest
##### Re: text to unicode format
« Reply #3 on: November 24, 2012, 11:37:43 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

• Member
• Posts: 2351
##### Re: text to unicode format
« Reply #4 on: November 24, 2012, 01:00:32 PM »
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.

Andy

Code: [Select]
`;CONSOLE program; RegisterEventSource.asm  Writes an event log in the Application section;                          .686.model flat,stdcalloption casemap:noneinclude \masm32\include\windows.incinclude \masm32\include\kernel32.incinclude \masm32\include\user32.incinclude \masm32\include\advapi32.incincludelib \masm32\lib\kernel32.libincludelib \masm32\lib\user32.libincludelib \masm32\lib\advapi32.lib.dataOutputBuffer BYTE 512 dup(0)Provider_Name BYTE 'The provider', 0Failed          BYTE 'Failure, Register Event Function Returned %d.',0Success BYTE 'Success, Register Event Function Returned %d.', 0AppName          BYTE 'SiegeWorks 2011',0;                      Unicode created by UniString.exestringpointers 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",0p_string_input DWORD 0.DATA?hEventLog        HWND ?dwEventDataSize WORD ?.codestart: 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, NULLDisplay_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 retDisplay_Return_Message endpEND start`
Take care,
Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

#### Magnum

• Member
• Posts: 2351
##### Re: text to unicode format
« Reply #5 on: November 24, 2012, 01:02:10 PM »
Thanks CommonTater.

Andy
Take care,
Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

#### qWord

• Member
• Posts: 1473
• The base type of a type is the type itself
##### Re: text to unicode format
« Reply #6 on: November 24, 2012, 02:17:14 PM »
There are several macros that allows Unicode data without declaring the __UNICODE__ equate:
e.g.:
Code: [Select]
`UCSTR Success,'Success, Register Event Function Returned %d.',13,10,0UCSTR 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

• Member
• Posts: 10464
• Assembler is fun ;-)
##### Re: text to unicode format
« Reply #7 on: November 24, 2012, 06:07:40 PM »
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).

Init

wLet esi=wChr\$("Hello coder")+wCrLf\$+"How are you?"
wPrint esi
wMsgBox 0, esi, "Hello", MB_OK
Exit
end start

#### Magnum

• Member
• Posts: 2351
##### Re: text to unicode format
« Reply #8 on: November 25, 2012, 12:57:41 AM »
Thanks to everyone.

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

Code: [Select]
`UCSTR Fail,        "Failure, Register Event Function Returned.",13,10,0UCSTR Success,"Success, Register Event Function Returned.",13,10,0invoke GetLastErrorinvoke wsprintf, ADDR OutputBuffer, ADDR Fail, EAXinvoke  MessageBox, 0, ADDR OutputBuffer, ADDR AppName, 0`
Take care,
Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

#### jj2007

• Member
• Posts: 10464
• Assembler is fun ;-)
##### Re: text to unicode format
« Reply #9 on: November 25, 2012, 01:06:55 AM »
Try MessageBoxW

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

#### qWord

• Member
• Posts: 1473
• The base type of a type is the type itself
##### Re: text to unicode format
« Reply #10 on: November 25, 2012, 01:16:50 AM »
It 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

• Member
• Posts: 8827
• Still using Abacus 2.0
##### Re: text to unicode format
« Reply #11 on: November 25, 2012, 01:46:25 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
Code: [Select]
`__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...
Code: [Select]
`__UNICODE__ EQU`that should work   :P

#### Magnum

• Member
• Posts: 2351
##### Found a way to display Chinese
« Reply #12 on: November 25, 2012, 11:10:39 AM »
It's been a long long day.

This displays the right text along with some Chinese characters.

Code: [Select]
`;CONSOLE program;; RegisterEventSource.asm  Writes an event log in the Application section;                           __UNICODE__=1 ; NEEDED ?include \masm32\include\masm32rt.incinclude \masm32\include\advapi32.incincludelib \masm32\lib\advapi32.lib.dataOutputBuffer BYTE 512 dup(0)Provider_Name BYTE 'The provider', 0Fail    db "Failure, Register Event Function Returned %d.",0Success db "Success, Register Event Function Returned %d.",0;UCSTR AppName ,'SiegeWorks 2011',0 ; the label is optionalAppName          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",0p_string_input DWORD 0.DATA?hEventLog        HWND ?dwEventDataSize WORD ?.codestart: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, NULLDisplay_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 retDisplay_Return_Message endpEND start`
Take care,
Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

#### qWord

• Member
• Posts: 1473
• The base type of a type is the type itself
##### Re: text to unicode format
« Reply #13 on: November 25, 2012, 11:48:30 AM »
Code: [Select]
`;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.incinclude \masm32\include\advapi32.incincludelib \masm32\lib\advapi32.lib; a little helper macro ;-DTCHR macro lbl,literals:VARARG        IFDEF __UNICODE__                UCSTR lbl,literals        ELSE                lbl db literals        ENDIFendm.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     ?.codestart: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, NULLDisplay_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         retDisplay_Return_Message endpEND start`
MREAL macros - when you need floating point arithmetic while assembling!

#### Magnum

• Member
• Posts: 2351
##### Re: text to unicode format
« Reply #14 on: November 25, 2012, 12:36:16 PM »
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