assembly 无法在FASM或NASM中使用wprintf打印Unicode字符串

qaxu7uf2  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(119)

我在使用FASM(Flat Assembler)中的wprintf函数打印Unicode字符串时遇到问题。
我尝试了以下代码,但它产生随机输出(αñ αñ αñ¿ αÑìαñ┐):

format PE64 console
entry start

include './include/win64w.inc'
include './include/macro/proc64.inc'
include './include/encoding/utf8.inc'

;======================================
section '.data' data readable writeable
;======================================
;unicode for हिन्दी
wunicode_string dw  0xe0, 0xa4, 0xb9, 0xe0, 0xa4, 0xbf, 0xe0, 0xa4, 0xa8, 0xe0, 0xa5, 0x8d, 0xe0, 0xa4, 0xbf


;=======================================
section '.code' code readable executable
;=======================================

start:
    
    mov rax, 0
    ccall [wprintf], "%ls", wunicode_string
   

    ccall   [getchar]                   ; I added this line to exit the application AFTER the user pressed any key.
    stdcall [ExitProcess],0             ; Exit the application

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',        msvcrt,'msvcrt.dll'

import  kernel,        ExitProcess,'ExitProcess'

import  msvcrt,        printf,'printf', wprintf, 'wprintf',       getchar,'_fgetchar'
wwtsj6pe

wwtsj6pe1#

如果我们为控制台设置正确的code page,它会显示正确的输出,我们可以在FASM中这样做(也可以在NASM中工作),如下所示:

format PE64 console
entry start

include './include/win64a.inc'
include './include/macro/proc64.inc'

;=======================================
section '.code' code readable executable
;=======================================

start:

    ccall   [SetConsoleOutputCP], 65001
    ccall   [printf], "%s", "हिन्दी"

    ccall   [getchar]                   ; I added this line to exit the application AFTER the user pressed any key.
    stdcall [ExitProcess], 0            ; Exit the application

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',\  
        msvcrt,'msvcrt.dll'

import  kernel,\  
        ExitProcess,'ExitProcess',\  
        SetConsoleOutputCP, 'SetConsoleOutputCP'

import  msvcrt,\  
        printf,'printf',\  
        getchar,'_fgetchar'

我用过printf,但它也适用于wprintf

相关问题