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.
How can I add programming code to existing binary program, is it possible? Like Inno setup installer is additional code over the package inside and when I run the setup.exe (produced by inno) it is not started the program inside, but the additional code over it and then the files are installed/extracted.
I just search for some way to run code before the main linux console binary file (or at the end of this file), but with scripting will be visible to others the programming code.
How can I add programming code to existing binary program, is it possible? Like Inno setup installer is additional code over the package inside and when I run the setup.exe (produced by inno) it is not started the program inside, but the additional code over it and then the files are installed/extracted.
I just search for some way to run code before the main linux console binary file (or at the end of this file), but with scripting will be visible to others the programming code.
If you have the ability to modify file locations (ie root privileges), then you can create a simple compiled and linked binary which can load and run the original runtime binary.
Code:
#include <stdio.h>
#include <stdlib.h>
int childPid;
int main(int argc, char * argv[] ){
childPid = fork();
if( childPid ){ /* I am the parent... */
/* do something or wait for child */
}
else{ /* I am the child... */
/* Maybe do some processing here; depends on your requirments...
*/
execvp( "/the/original/program", argv );
/* We never return from exec... */
}
}
Once this is compiled and linked, you still have to arrange that it gets run by default, instead of the original code. That requires moving/renaming files, hence the requirement to be root.
PDV -payload delivery vehicle, can be used to create a binary ELF self-extracting archive which extracts a payload from itself when run and can execute a script at the same time.
Imagine the security implications of being able to inject 'extra' code into previously compiled binaries! Scary.
I'm guessing you're up to no good, why would you be concerned if the end-user could see you were running one program before another?
Actually, that's how many programs work. Look up Dyninst, or as one responded wrote - LD_PRELOAD. Some unix flavors don't support LD_PRELOAD, or have that functionality disabled for security reasons.
Afa the original question goes, there are many ways of doing what you require. Some would have you simply put a marker at end of the file, write your binary into the file, and then search out the marker for extraction. Many of the SUN / nVidia .bin files work by having a script with the tar embedded (and you can probably have some encryption/password for protection). As one user noted, PDV is a way of accomplishing a 'self-extracting' file.
gulfstream: what are you trying to accomplish by appending another binary to an existing one. It probably can be done if you're compiling the binary yourself, but otherwise you'd have to append the binary and find a way to jump to the new instructions in this new appendage, not at all easy.
If you goal is to create an installer, it can be accomplished with a shell script. I've done it many times before and it's fairly simple, there are examples all over the internet.
I just want to add binary to binary code (no src available) and I thought that I can do it somehow - to make new binary, like copy-paste of text to text via cat:-) it's like a small program preparing some things before to run other binary. I like the easy simple way like theNbomr wrote in his code. I already had similar idea. With editor can be traced the command that will be started in shellexec/shell, this will be no problem at all.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.