【发布时间】:2019-12-09 13:09:52
【问题描述】:
我正在为 Win64 开发一个组装项目,但我遇到了命令行参数的问题!!!!正常情况下,命令行参数的地址是:
[rsp] = Number of Command-line Arguments
[rsp+8] = First Argument (Name of Executable)
[rsp+16] = First Client Argument
....
但在我的情况下,这些不是我想要的价值观! ([rsp] 不是 ... 的数量, [rsp+8] 不是参数和 ....)
这是我的源代码(FASM PE64 CONSOLE)
FORMAT PE64 CONSOLE
ENTRY MAIN
SECTION '.text' CODE READABLE EXECUTABLE
MAIN:
mov r12, [rsp] ; now r12 is the number of Commandline Arguments (but it's not !!!!!!!!!!!!)
sub rsp, 56
mov ecx, -11
call [K32.GetStdHandle]
cmp r12, 1 ; Argument Count Must be More than 1 (because it's 1 by default (Executable name) and we want to print, if it's More than 1 (if Argument Provided))
jle .exit
.write:
mov ecx, eax ; STD_OUTPUT_HANDLE (EAX)
mov rdx, .hello
mov r8d, .hello_len
xor r9d, r9d
mov QWORD [rsp+32], 0
call [K32.WriteFile]
.exit:
add rsp, 56
xor ecx, ecx
call [K32.ExitProcess]
hlt
.hello DB 'Argument Received', 0x00
.hello_len = $ - .hello
SECTION '.idata' IMPORT DATA READABLE WRITABLE
DD 0,0,0,RVA K32DLL,RVA K32
DD 0,0,0,0,0
K32DLL DB 'KERNEL32.DLL', 0x00
K32:
.ExitProcess DQ RVA ___ExitProcess
.GetStdHandle DQ RVA ___GetStdHandle
.WriteFile DQ RVA ___WriteFile
DQ 0
___ExitProcess DB 0,0,'ExitProcess',0
___GetStdHandle DB 0,0,'GetStdHandle',0
___WriteFile DB 0,0,'WriteFile',0
在我的程序中,如果我们添加一个参数,它是必须打印消息。否则它必须只是退出,但它总是打印该消息(“命令行参数数量”的值是错误的!)
我还检查了“rcx”作为命令行参数的数量和“rdx”作为参数数组,但它们仍然不是!!!
argc 和 argv 在哪里!!!!!!!!!这是关于我的格式吗? (PE64 控制台)?
【问题讨论】:
-
我读过它......有点用......但是一个问题!我必须将条目名称更改为“WinMain”或使用此名称,我还有参数吗?
-
名字无关紧要。无论如何,您也可以致电GetCommandLine