Code on masm64 for Visual Studio 2022:
Code: Select all
ExitProcess PROTO
MessageBoxW PROTO
GetCurrentDirectoryW PROTO
.data
caption db "C", 0, "u", 0, "r", 0, "r", 0, "e", 0, "n", 0, "t", 0, "D", 0, "i", 0, "r", 0, "e", 0, "c", 0, "t", 0, "o", 0, "r", 0, "y", 0, ":", 0, 0, 0
Buffer db 520 dup(0)
.code
main PROC
push rbp
mov rbp, rsp
sub rsp, 20h
mov ecx, 520
lea rdx, Buffer
call GetCurrentDirectoryW
xor rcx, rcx
lea rdx, Buffer
lea r8, caption
xor r9, r9
call MessageBoxW
mov rcx, 0
call ExitProcess
main ENDP
END
If you run 'CurrentDirectory.exe' by double-clicking the mouse, the correct path of 'CurrentDirectory.exe' file location will be displayed.
But if you open this file through the x64 context menu, the path will be 'C:\Program Files (x86)\XYplorer', which should not be the case.
Opening a file via 64-bit context menu:
The file is located in the 'D:App\MSVS\ASM\CurrentDirectory\x64\Release' directory, and the GetCurrentDirectory function returns 'C:\Program Files (x86)\XYplorer'.
If the file is launched by double-clicking or via the 32-bit context menu, the GetCurrentDirectory function returns the correct value: