Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly MASM 64位-无法使CreateFileW正常工作。CreateFileA工作正常_Assembly_64 Bit_Masm_Createfile - Fatal编程技术网

Assembly MASM 64位-无法使CreateFileW正常工作。CreateFileA工作正常

Assembly MASM 64位-无法使CreateFileW正常工作。CreateFileA工作正常,assembly,64-bit,masm,createfile,Assembly,64 Bit,Masm,Createfile,CreateFileW返回-1,GetLastError返回2(系统找不到指定的文件。) 运行最新的VS社区2017 使用带有最新更新的Windows 10 还尝试了以下注册表设置: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies] "Lon

CreateFileW返回-1,GetLastError返回2(系统找不到指定的文件。)

运行最新的VS社区2017 使用带有最新更新的Windows 10

还尝试了以下注册表设置:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem]
"LongPathsEnabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Policies]
"LongPathsEnabled"=dword:00000001
代码:


您是否意识到
W
意味着它需要宽unicode字符?您正在传递ascii,当然它不会工作。为什么它返回“未找到文件”?CreateFileW不够聪明,无法知道文件中有什么。而且,它不在乎。ReadFile也可以工作,但是在这种情况下,“Hello”会被破坏,因为文件内容是ASCII。
W
指的是文件名,而不是内容。正如你所说,它不在乎这个。
;-------------------------------------------------------------------------------------------
extern ExitProcess:proc
extern CreateFileA:proc
extern CreateFileW:proc
extern ReadFile:proc
extern GetLastError:proc
extern CloseHandle:proc
;----------------------------------------------------------------------------------------------
GENERIC_READ            equ 080000000h
FILE_ATTRIBUTE_NORMAL   equ 080h
OPEN_EXISTING           equ 3
OPEN_ALWAYS             equ 4
;-------------------------------------------------------------------------------------------
.data
align 1
    gFileName       db "D:\C# Projects\TestAsm\Simple.txt", 0       ;Simple.txt contains Hello
    ;gFileName      db "\\?\D:\C# Projects\TestAsm\Simple.txt", 0   ;Tried this too.
    gFileHeapPtr    db 10 Dup(0)
;-------------------------------------------------------------------------------------------
align 8
    gFileHandle dq 0
    gBytesRead  dq 0
;-------------------------------------------------------------------------------------------
.code
;-------------------------------------------------------------------------------------------
main proc
    mov rbp, rsp

    mov rcx, offset gFileName
    mov rdx, GENERIC_READ
    xor r8, r8
    xor r9, r9

    push 0
    push FILE_ATTRIBUTE_NORMAL
    push OPEN_EXISTING

    sub rsp, 32
    call CreateFileA    ; CreateFileA works fine.
    ;call CreateFileW   ; Returns -1
    ;call GetLastError  ; Returns 2 > The system cannot find the file specified.
    mov rsp, rbp

    mov gFileHandle, rax

    mov rcx, gFileHandle
    mov rdx, offset gFileHeapPtr
    mov r8, 5

    lea rax, gBytesRead
    mov r9, rax
    push 0

    sub rsp, 32
    call ReadFile
    mov rsp, rbp

    mov rcx, gFileHandle
    sub rsp, 32
    call CloseHandle
    mov rsp, rbp

    call ExitProcess
main endp
;-------------------------------------------------------------------------------------------
End
;-------------------------------------------------------------------------------------------