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
Thread Post new topic Reply to topic
xiaolaba



Joined: 31 Jan 2015
Posts: 15
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


Description:
Filesize: 196.23 KB
Viewed: 249 Time(s)

UTF-16LE.JPG


Description:
Download
Filename: FASM_test中文.ASM
Filesize: 2.93 KB
Downloaded: 34 Time(s)


_________________
best regards,
xiao


Last edited by xiaolaba on 26 Aug 2024, 01:42; edited 1 time in total
Post 24 Aug 2024, 04:52
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 24 Aug 2024, 08:28
I changed the title to FASMW because FASM is the CLI tool,
Post 24 Aug 2024, 08:28
View user's profile Send private message Visit poster's website Reply with quote
xiaolaba



Joined: 31 Jan 2015
Posts: 15
xiaolaba 26 Aug 2024, 01:30
revolution wrote:
I changed the title to FASMW because FASM is the CLI tool,


sort of that, here is the batch file used to deal with the FASM CLI, a copy,

Code:

@echo off
 
REM Readme first
REM 2017-MAR-25, xioalaba
REM Uses FASMW or FASM, goto C:\fasmw17160\TOOLS\WIN32
REM to build 3-EXE one time first, listing.exe, prepsrc.exe, symbols.exe
 

SET FASM=E:\FASM


SET TOOLS=%FASM%\TOOLS\WIN32
SET INCLUDE=%FASM%\INCLUDE
 
set path=%FASM%;%INCLUDE%;%TOOLS%;%path%
path

 
if exist %TOOLS%\listing.exe goto skip
@echo ---- Uses FASMW or FASM, goto %TOOLS%
@echo ---- To build 3 EXE first at one time deal, listing.exe, prepsrc.exe, symbols.exe
cd %TOOLS%
fasm.exe listing.asm listing.exe
fasm.exe prepsrc.asm prepsrc.exe
fasm.exe symbols.asm symbols.exe
:skip


REM change to current dir
cd /D "%~dp0"
@echo.
@echo working folder = %1

 
@echo FASM build.bat, by xiaolaba, MAR/26/2017
@echo.
@echo ---- Drag .asm file to this build.bat, produce .exe and .fas
fasm.exe %1 %1.exe -s %1.fas

::goto end
 
@echo.
@echo ---- Uses .fas, produce .lst
listing -a %1.fas %1.lst
 
@echo.
@echo ---- Uses .fas, produce .src
prepsrc %1.fas %1.src
 
@echo.
@echo ---- Uses .fas, produce .fas
symbols %1.fas %1.sym

:end

del *.fas
 
@echo DONE !!
pause 

    

_________________
best regards,
xiao
Post 26 Aug 2024, 01:30
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.