When i read a binary file from fstream, the data in file is read in Hex! If thats true, then i can read any closed source application easily. I just have to open the file in fstream, then extract all hex from .exe
& convert these hexes to int, then read the ints as char to get the pure source code (chars) of the application! Isn't that true?
OPTIONAL INFO:
If you wonder why i say fstream can read .exe data in hex, here is a quote:
"Once you open the .exe by fstream, find the following sequence of bytes (hex): 32 35 35 2E 32 35 35 2E 32 35 35 2E 32 35 35. Read the file byte-by-byte, and try to match the pattern. If/when you do find that sequence, you'll write out the new IP address starting at the location you found the first '2'."
Every file on a computer is just a long series of numbers (that's what "digital" means -- everything is represented by digits). Text files generally just have 1 byte representing a character. For example the character 'A' is represented by the number 0x41. (Try looking at a text file in a hex editor)
Source files are just text files. Binary files contain machine code. The difference between these is that bytes in the source file represent a character of text, whereas the bytes in binaries are actual instructions that the computer is to execute. These are two very different things.
There is no way to get the original source from a binary file. Even if you can "decompile" it and get usable C or even C++ code -- you would lose lots of stuff like variable/function names, comments and the like, as these are not stored anywhere in the binary file. Decompiling is an incredibly complicated process, though, and is not anything at all like you allude to in your post.
Disch is right, but I would like to add something.
What he said is completely correct for native executables. Nowadays, there are programs that can be semi-easily decompiled. Any program whose binary contains byte-code rather than native instructions (e.g. Java and .NET programs) can be decompiled with an output very similar to the original source code. In the case of .NET, it's even possible to automatically translate a C# source to a VB.NET source.
This is because byte-code is a precompiled version of the original source. At run time, a virtual machine or just-in-time compiler interprets the program for the CPU.
Not wanting to insult OP, I feel compelled to ask if he didn't thought someone else might have thought that before, or why would the open source movement exist if it was to easy to look at a program's source code.