PDA

View Full Version : Function to execute a binary incase of code.



akshay.sulakhe
January 15th, 2013, 01:48 PM
Hello friends,
I am working currently in C programming. For some reasons, in the code, i have to give a path to the binary(executable), which can be directly used instead of any code.
For eg :-
if(condition_satisfied){
execve'absolute_path_to_executable_file'
}
With this, it should execute this binary file. Is this possible? If yes, Kindly let me know. Thank you for your time. :-) ):P

PaulM1985
January 15th, 2013, 02:01 PM
I think you can use the exec() function for this.

Paul

rnerwein
January 15th, 2013, 05:46 PM
Hello friends,
I am working currently in C programming. For some reasons, in the code, i have to give a path to the binary(executable), which can be directly used instead of any code.
For eg :-
if(condition_satisfied){
execve'absolute_path_to_executable_file'
}
With this, it should execute this binary file. Is this possible? If yes, Kindly let me know. Thank you for your time. :-) ):P
hi
you can use any kind of exec calls try: man -k exec to see the different calls. i am sure one of the will satisfy your claim. the normal exec is ok too.
ciao

Bachstelze
January 15th, 2013, 08:14 PM
With this, it should execute this binary file. Is this possible?

You have the code written, how about you try it and find out?

jwbrase
January 17th, 2013, 07:44 AM
Keep in mind that if you just use exec(), your program will be replaced by the program you exec(), so any code after the exec() in your program won't get executed.

For example:




foo=bar;

if(condition)
{
exec(program);
}

foo=baz; //If "condition" is true, you'll never get to this line.