flat assembler
Message board for the users of flat assembler.
Index
> Windows > FASMW to deal with UTF-8 and non-ANSI name of variables |
Author |
|
xiaolaba 24 Aug 2024, 04:52
perhaps this is a workaround with a bit tricky, but anyway a solution. it is a complete working prototype.
Code: ;; refs: https://board.flatassembler.net/topic.php?p=217706 ;; https://board.flatassembler.net/topic.php?t=938 ;; Unicode in FASM ;; FASM 1.73.32 ;; win10 64 bit, CHT version ;; uses other editor, save this source code as UTF-8, FASM IDE is be able to process CHT input ;; open FSAM IDE, load/compile this code, it is displaying UTF-8 CHT char properly, data type must be DU ;; by xiaolaba format PE GUI entry start include '\fasm\include\win32w.inc' include '\fasm\include\encoding\utf8.inc' section '.data' data readable writeable IS64 du '64位元 Windows',0 IS32 du '32位元 Windows',0 argv dd ? argc dd ? dummyW dw 'AB' ;2 bytes, 0x41 0x42, compile ok ;dummyW dw 'ABCD' ;2 words, error, could not compile, value out of range dummyU du 'AB' ;4 bytes, 41 00 42 00 ;compile ok ;;;; https://www.compart.com/en/unicode/U+4E2D ;;;; '中' ;;;; UTF-8 encoding 0xE4 0xB8 0xAD ;;;; UTF-16 4E2D ;dummyWZ dw '中' ;compile error, value out of range dummyWZ du '中' ;2D 4E, compile ok dummyUZ du '中文' ;2D 4E 87 65, compile ok ; Define the wide (2-byte) strings for MessageBox ;messageBoxTitle dw 'U','T','F','-','8',' ',' ','中','文','測', '試',0 ; dw, Wide string for MessageBox title, did not work ;debugMessage dw 'F','A','S','M',' ','S','t','a','r','t','e','d','中','文','測','試',0 ; Wide string for debug message ; Define the U (4-byte) strings for MessageBox ;messageBoxTitle du 'U','T','F','-','8',' ',' ','中','文','測', '試',0 ; du, Wide string for MessageBox title, working ;debugMessage du 'F','A','S','M',' ','S','t','a','r','t','e','d','-','中','文','測','試',0 ; Wide string for debug message messageBoxTitle du 'UTF8-中文測試',0 ; du, Wide string for MessageBox title, working debugMessage du 'FASM Started-中文測試',0 ; Wide string for debug message 晚安 du '晚安',0 section '.code' code readable executable start: ; Display debug message to verify execution invoke MessageBoxW, NULL, debugMessage, messageBoxTitle, MB_OK invoke MessageBoxW, NULL, IS64, messageBoxTitle, MB_OK invoke GetCommandLineW invoke CommandLineToArgvW, eax, argc mov [argv], eax ; Check if we have at least one argument cmp dword [argc], 1 jbe exit ; Init loop mov ecx, 1 mov eax, [argv] @@: ; Get argument pointer mov edx, [eax + 4 * ecx] invoke MessageBoxW, NULL, edx, messageBoxTitle, MB_OK ; Repeat until ecx = argc inc ecx cmp ecx, dword [argc] jb @B exit: invoke MessageBoxW, NULL, 晚安, messageBoxTitle, MB_OK invoke ExitProcess, 0 section '.idata' import data readable writeable library kernel32, 'kernel32.dll', \ user32, 'user32.dll', \ shell32, 'shell32.dll' import kernel32, \ GetCommandLineW, 'GetCommandLineW', \ ExitProcess, 'ExitProcess' import user32, \ MessageBoxW, 'MessageBoxW' import shell32, \ CommandLineToArgvW, 'CommandLineToArgvW' used IDA Free and the asm generated listing file, it is able to see the compiled code with Wide-Char used as UTF16-LE (Little-Endian byte order), i.e., 'U' = 0x55, 0x00
_________________ best regards, xiao Last edited by xiaolaba on 26 Aug 2024, 01:42; edited 1 time in total |
||||||||||||||||||||
24 Aug 2024, 04:52 |
|
revolution 24 Aug 2024, 08:28
I changed the title to FASMW because FASM is the CLI tool,
|
|||
24 Aug 2024, 08:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.