nasm上的execvp用法

nasm上的execvp用法,第1张

概述nasm上的execvp用法

我正在学习NASM,可能是linux系统调用。 我试图复制一个进程并调用linux实用程序,但与execvp有同样的麻烦,我不知道如何传递参数到它。 我如何做到这一点?

SECTION .data cmd_cat: db '/bin/cat',0 arg_cat: db 'log.txt',0 cat: dd cmd_cat,arg_cat,0 fd1: DW 0,0 pipe_error_message: db 'pipe error occured',0xa pipe_error_message_length: equ $ - pipe_error_message fork_error_message: db 'fork error occured',0xa fork_error_message_length: equ $ - fork_error_message SECTION .text GLOBAL _start: _start: ;call pipe(fd1) ;42 - pipe system call number mov eax,42 mov ebx,fd1 ;call kernel to execute int 080h cmp eax,0 jne pipe_error ;call pipe(fd2) mov eax,fd1 int 080h cmp eax,0 jne pipe_error ;fork() mov eax,2 int 080h cmp eax,-1 je fork_error jnz child_cat call exit ;displays error message and finishes the programm when something is wrong with pipe pipe_error: mov edx,pipe_error_message_length mov ecx,pipe_error_message call sys_write call exit ;displays error message and finishes the programm when something is wrong with fork fork_error: mov edx,fork_error_message_length mov ecx,fork_error_message call sys_write call exit ;sys_write(unsigned int fd,const char __user *buf,size_t count); sys_write: mov ebx,1 mov eax,4 int 080h ;exit(0) exit: mov eax,1 mov ebx,0 int 080h child_cat: mov ebx,[fd1] mov eax,6 int 080h ;dup2(fds[1],1) mov ecx,[fds + 4] mov eax,63 int 080h mov eax,11 mov ebx,cmd_cat mov ecx,cat int 080h

使用程序集closureslinux时出现分段错误

Asm CALL指令 – 它是如何工作的?

为什么将GDB断点设置为x86汇编函数的错误地址?

如何计算在ARM程序中执行的指令数量?

使用预取队列的反deBUGging不能用于我的cpu

以下代码适用于天然气装配工。 我已经解释了它做了什么,所以希望别人可以提供nasm翻译。

.text .global _start _start: movl $0xb,%eax # system call 0xb (execve) goes in eax movl $arg0,%ebx # put the _address_ of the command string # in ebx (we are provIDing a pointer) movl $ptrarray,%ecx # put the _address_ of the array of pointers # to arguments in ecx (again,a pointer) movl $0,%edx # put a literal zero in edx (we don't have # environment variables to pass,so we give # a null pointer) int $0x80 # run the system call .data ptrarray: # This is the array of pointers to command line # arguments .long arg0,arg1,0 # The first element is a _pointer_ to the command # The second element is a _pointer_ to an argument # The third is a null pointer to indicate no more arg0: # This is the command string .asciz "/bin/cat" arg1: # This is the argument string .asciz "file.txt"

总结

以上是内存溢出为你收集整理的nasm上的execvp用法全部内容,希望文章能够帮你解决nasm上的execvp用法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1285134.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存