据推测,将参数传递给 execve 系统调用非常简单。
在教程中,讲师说它只有一行,把它留作练习。
下面的代码执行“ls”命令。我正在尝试执行类似“ls -la”的操作。 找了又找,还是不知道在什么地方加上“-la”!
我知道它在 ecx 寄存器指向的结构中,并且必须以 null 终止。目前,ecx 包含一个到/bin/ls 的地址。参数应该是另一个地址吗? argv 是一个数组,第一个元素是“/bin/ls”...
global _start
section .text
_start:
xor eax, eax
push eax
push 0x736c2f6e
push 0x69622f2f ; //bin/ls
mov ebx, esp
push eax
mov edx, esp
push ebx
mov ecx, esp
mov al, 11
int 0x80
这是行不通的:
xor eax, eax
push eax
push 0x2a632020
push 0x736c2f6e
push 0x69622f2f ; /bin/ls c*
mov ecx, esp
最佳答案
您必须将-la
参数保存在ecx
寄存器中,并将其复制到esp
寄存器(我的意思是在堆栈中)
push eax
push byte 0x61
push word 0x6c2d
mov ecx, esp ; -la
以下是您修改后的代码:
global _start
section .text
_start:
xor eax, eax
push eax
push byte 0x61
push word 0x6c2d
mov ecx, esp ; -la
push eax
push 0x736c2f6e
push 0x69622f2f ; //bin/ls
mov ebx, esp
push edx
push ecx
push ebx
mov ecx, esp
mov al, 11
int 0x80
代码运行良好:)
% ./list
total 4
-rwxrwxr-x 1 febri febri 512 Oct 5 07:45 list
%
关于linux - 将参数传递给 execve 系统调用的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58244168/