ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
BITS 32
xor eax,eax // zeroing out eax register
cdq // zeroing out edx register (3rd arg)
push eax // pushing zero or NULL onto the stack
push long 0x73702f2f // pushing "//ps" onto the stack
push long 0x6e69622f // pushing "/bin" onto the stack
push long 0x7273752f // pushing "/usr" onto the stack
mov ebx,esp // saving the pointer to the string in ebx register (1st arg)
push eax // pushing zero or NULL onto the stack
push long 0x20202061 // pushing "a " onto the stack
push ebx // pushing the pointer to the string "/usr/bin/ps0" onto the stack
mov ecx, esp // saving the pointer of the string in the ecx register (2nd arg)
mov al,0x0b // moving decimal 11 into the al register, 11 syscall for execve
int 0x80 // executing, no need to call exit
Not even close. I'm not sure if the comments are off, or the actual code is wrong ... or both ...
... but ...
Suggestions:
1. Write a 5-line C program that does your execve, compile with "-S" to generate an assembly listing and see how it works.
2. I don't recall if "execve" is an OS call (which would use "int 0x80"), or a standard library call (which wouldn't).
In either case, "gcc -S" would tell you.
3. Declare local variables for your string and use variable names. DON'T use big hairy hexadecimal constants
... and ...
4. Check out this tutorial. It's free, and it's a really, really good introduction to assembly programming in general (and assembly programming on Linux in particular):
PS:
NASM syntax might be appealing if you're looking at DOS examples, or if you're only ever programming Intel CPUs.
But you SHOULDN'T be looking at DOS examples - they'll give you some nasty bad habits you'll have to unlearn
And Gnu Assembler syntax really shines the moment you try your hand at OTHER assembly languages, BESIDES Intel (like MIPS, ARM or Power PC, for example).
1. When I compiled with "-S", my execve did indeed resolve to a standard library call (*not* directly to the underlying syscall). But invoking the syscall directly is equally valid. They're all defined here, in "asm/unistd.h":
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.