Is there a method to insert a shell script in a c program or binary source code so that when I compile the source code the shell script gets compiled as well?
Two obvious ways I guess:
The first is to use the "system" function to call a shell script but obviously then you need to ensure that you keep the C executable and the shell script together.
The second is similar but you store the shell source in the C source and get the C program to create the shell script "on the fly". Then you can guarantee that it will always be available. You will, of course, have to worry about file locations and names and permissions.
I know I've done this in the past but I lost my documentation. I was able to add a shell script within a C source code and compiled it. I don't remember using the "system" function but if anyone could provide me a little more detail, I would appreciate it.
I guess you just embed your Shell source in the C as a char array and just before you need to execute it, you fprintf it to a file and "system" it.
I guess I could sit down and write an example but that will take a little time and I'm just a little short of time for a while.
I should be back later though so if you'd had no further help by then...
The system function doesn't contain it, you write it to a file. The system function is merely given the name of the file.
The only pain is storing the source for the shell script in the C source.
Another idea would be to encrypt the shell script and leave it encrypted and get the C program to decrypt a copy and send that to a shell.
To do that your C program would open the script, read all the data to a char array and decrypt it and then open a pipeline to a shell and feed it the script as stdin.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.