程序集 PE64 控制台找不到命令行参数计数和数组 (argc) + (argv)



>im正在处理Win64的程序集项目,并且在正常情况下使用命令行参数!!!有问题,命令行参数的地址是:

[rsp] = Number of Command-line Arguments
[rsp+8] = First Argument (Name of Executable)
[rsp+16] = First Client Argument
....

但在我的情况下,这些不是我想要的价值观!([RSP] 不是 ...和 [rsp+8] 不是参数和...

这是我的源代码(FASM PE64控制台(

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 控制台( ?

命令行参数,包括可执行文件本身的名称,由操作系统解析并放在Linux中的堆栈上 但是在Windows中情况非常不同。你需要调用内核函数 GetCommandLineA(( 并自行解析返回的字符串。

调用 ExitProcess 永远不会返回到退出的程序,因此您的指令hlt将不会执行,应省略。

最新更新