Click here to Skip to main content
14,699,613 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
Hi,
Below is my scenario.
a.out on execution produces the below output.
"File-1 is the output"
b.out on execution produces the below output.
"File-2 is the output"

All i want to do is a binary merge and in this case the merged output should
give output as below
"File-1 is the output"
"File-2 is the output"

How can i achieve this in C on linux or windows

please :)
Posted
Comments
xenotron 14-Aug-12 13:35pm
   
Its unclear what is your goal. Noone will be able to answer this, only guessing is possible. Please make your intentions clear.
Sergey Alexandrovich Kryukov 14-Aug-12 13:38pm
   
And not clear what's the problem. Merge them the way you want...
--SA
[no name] 14-Aug-12 13:42pm
   
but the output is not expected even though the final merged .out file is the sum of the individual .out files
[no name] 14-Aug-12 13:42pm
   
typo....the output is not as expected
Sergey Alexandrovich Kryukov 14-Aug-12 15:16pm
   
How do you define this "sum"? And what's the problem?
--SA
[no name] 14-Aug-12 15:24pm
   
i mean sum of the sizes of .out files and the expected output was not as below.
"File-1 is the output"
"File-2 is the output"

But instead it was only the below
"File-2 is the output"
Sergey Alexandrovich Kryukov 14-Aug-12 15:31pm
   
No wonder. Your assumption that both parts of code will execute is kind of naive. This is not how executable images work. Please see my answer.
--SA
xenotron 14-Aug-12 13:53pm
   
Solid true.
Sergey Alexandrovich Kryukov 14-Aug-12 15:21pm
   
After the OP's clarification, I answered somehow, please see.
--SA
[no name] 14-Aug-12 13:41pm
   
Okay! I was interested in the concept of merging binary files. In case of text files suppose 'a.c' is the parent file and say X has made some changes to 'a.c' file and saved it to 'x.c' file and then suppose say Y has made some changes to 'a.c' file and saved it to 'y.c' file then we can produce a merged file of 'x.c' and 'y.c' to a new file say 'b.c'.
Now this is possible in text files and how about merging of the executable produced by x.out and y.out to a new file.
Please let me know incase if I have'nt made my idea clear
[no name] 14-Aug-12 13:46pm
   
yes. Is there a way to achieve it programmatically?
xenotron 14-Aug-12 13:50pm
   
Well, you can merge two branches of the same source code (a.c and y.c) but that often needs human mind, can not be automatized. Merging binaries??? That makes no sense at all.
[no name] 14-Aug-12 13:52pm
   
How about merging concept in version control systems. They do have merging of Binary files right?
Sergey Alexandrovich Kryukov 14-Aug-12 15:22pm
   
No!
--SA
[no name] 14-Aug-12 14:26pm
   
Ok. It is a wrong question to be asked here. I was basically thinking that merging of binary files in version control system means that the both binaries are merged into a new file altogether and still that binary works but instead it saves a copy of both the binaries from different repositories in a single repository. May not be the exact way but i guess I had this doubt.
Sorry to bother!
Sergey Alexandrovich Kryukov 14-Aug-12 15:22pm
   
If would be more useful if you explained your ultimate goal or the main idea...
--SA
Albert Holguin 15-Aug-12 11:08am
   
Oh... yeah, no version control system would ever actually merge binaries. "Merge" is a term commonly used in version control to mean merge branches or merge repositories (but usually branches).

Thank you for the clarification. It does not make any sense and is not possible. I can explain why, but this is too boring. Wrong useless idea anyway. In a way, you can decompile executable modules and compile it in a single executable, but it is not guaranteed to succeed due to possible name clash, and not easy, and makes no practical sense.

[EDIT]

I would suggest you read on general programming and lean about the concepts of source, object and executable files, entry points, address spaces, application loading and resolution of addresses. The question is based on some misconceptions around these areas.

—SA
   
v2
Comments
xenotron 14-Aug-12 15:43pm
   
+5 I was afraid of that this is the goal...
Sergey Alexandrovich Kryukov 14-Aug-12 15:49pm
   
Thank you. What do you afraid of? What goal? I did not get it.
--SA
xenotron 14-Aug-12 16:25pm
   
Yep, the pointless goal of merging binaries.
Albert Holguin 14-Aug-12 19:57pm
   
Pointless to try to merge binaries, but I gave him an option that should make more sense.
If you want the functionality of two executables, why not simply run both from a single point. Scripts are a great option for something simple like this...

Batch[^] (for Windows) or bash[^] (for UNIX/Linux) are two commonly used scripting languages that enable power users to do this type of thing. Each runs pretty much natively in their environment, if you want a script that runs on either platform, then go with one of the other multi-platform scripting options (Perl, Python, etc.).
   
Comments
   
At least it makes some sense. My 5.
--SA
You want to merge executable files? Are you looking for software to apply binary patches?

Something like this?
Binary diff/patch utility
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900