简体   繁体   中英

How to set up execve call on nasm right?

The following code shows

relocation truncated to fit: R_386_8 against `.data'

 child:
    mov eax,11
    mov ebx,echo
    mov ecx,argv
    xor edx,edx
    int 0x80

section .data    
echo db '/bin/echo',0

argv0 db 'echo',0
argv1 db 'child excuted',0
argv db argv0, argv1

How I should set up execve call right? I thought to put addresses in stack and use esp but I still need to know how to declare array of strings in nasm.

As @Jester suggested, you need to declare argv properly:

argv dd argv0, argv1, 0

db refers to defining a list of 8-bit bytes. dw would let you define 16-bit shorts. dd is for 32-bit numbers - on 32-bit Linux, this is the proper pointer size. (You would use dq on 64-bit, because that's a 64-bit number, which is the right pointer size in that case.)

execve expects a NULL-terminated list of pointers, so we use dd for each of our pointers, and then NULL (0) to terminate the parameter list.

Also - while execve normally does not return, robust code will take into account the possibility that execve fails, and handle this properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM