flat assembler
Message board for the users of flat assembler.

Index > Linux > How do I execute other program from a Linux program

Author
Thread Post new topic Reply to topic
2



Joined: 26 Sep 2006
Posts: 92
2
I found this not too long ago.


Quote:
11 EXECVE const char *filename, char const argv[], char const envp[]
execute a program

arg eax 11
ebx ptr to <nul> terminated string of program path&name
ecx ptr to zero terminated list of ptrs to <nul> terminated
program argument stgs
edx ptr to zero terminated list of ptrs to <nul> terminated
environment strings
return no return, executed prog inherits resources and overwrites caller
errors eax 2big, acces, inval, io, isdir, libbad loop, nfile, noexec,
noent, nomem, notdir, fault, nametoolong, perm, txtbusy
ref arch/i386/kernel/process.c
note waiting caller of a "fork"ed or "clone"d job being released immediately
after entry to execve.


I haven't figured out how it works yet though.
Will it allow me to execute any other program from inside a Linux program?

_________________
There are 10 kinds of people in the world.
Those who know binary and those who haven't met me.
Post 08 May 2007, 03:30
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
Code:
format elf executable

mov eax,0xB
mov ecx,args
mov edx,0
mov ebx,arg0
int 0x80

mov eax,1
int 0x80

arg0: db '/bin/ls',0
arg1: db '-l',0
args: dd arg0,arg1,0

;this program is designed to have the same effect
;as entering "/bin/ls -l" at the terminal
    
Post 08 May 2007, 04:15
View user's profile Send private message Reply with quote
2



Joined: 26 Sep 2006
Posts: 92
2
I noticed that after it executes the other program,it only returns to the OS instead of going back to the original program that called it! Any way to make it go back?
Post 08 May 2007, 04:27
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Unix has a different approach, you can't do the CreateProcess of Windows but change the process image with another. However you are allowed to duplicate your process and later making one of them execute the desired program. Read about sys_fork/sys_vfork.

PS: Use the child process to execute the program, using the current will kill the child after program termination.
Post 08 May 2007, 16:13
View user's profile Send private message Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:52; edited 1 time in total
Post 09 Apr 2009, 14:26
View user's profile Send private message Reply with quote
drhowarddrfine



Joined: 10 Jul 2007
Posts: 535
drhowarddrfine
Just google for 'man execve' for the manpage.
Post 09 Apr 2009, 20:23
View user's profile Send private message Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
See this thread http://board.flatassembler.net/topic.php?t=9279 Console output after intern program execution.
Post 13 Apr 2009, 14:39
View user's profile Send private message Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.