How do i change a exe file to a txt file and then back to exe using c++?
Sorry, but i'm totally clueless on how to do this.
How do i change a exe file to a txt file and then back to exe using c++?
Sorry, but i'm totally clueless on how to do this.
Quite simply you can't.
You are viewing the exe as a text file - it means nothing as a text file.
EXEs are binary files - they contain an EXE header and some type of (x)Z at the beginning depending on the version of the EXE and if it's a Windows PE or not. Basically all an exe is, is the assembly opcodes for the instructions within the program. Since the opcodes do not correspond correctly with the ASCII character codes or any text for that matter...you get garbage in a text editor...but in reality you are getting exactly what the opcode is.
For instance if a jmp instruction is coded as 65h (it's not, but bear with me) then the jmp opcode in ASCII text would appear as capital A.
You could use a disassembler to correctly interpret the opcode sequences in the EXE but it would still only be assembly. To actually go back to C++ or even just C would be nearly impossible
w/o knowing which C functions were called and what parts of the EXE are simply the C static libraries and which are not. As well it would be close to impossible to re-interpret a switch() block simply based on opcodes. The interpreter would have to know a sufficient amount of information about how the compiler translated the C text into assembly. Not easy and nearly impossible. I say nearly because nothing in computers is truly impossible.
Thank for the info bubba, i learn something.
I need to encrypt exe file using my own encryption program that could only encrypt characters ( its lousy, i know ), so i was thinking of converting the exe file to a text file or something.
>that could only encrypt characters
Characters or bytes? Unless you went out of your way to only correctly encrypt printable characters, there shouldn't be a problem.
My best code is written with the delete key.
characters and numbers shouldn't a problem, i could encrypt a normal text file.
i could also program it to take in bytes but i need to get the exe file to a txt file or a binary file.
>but i need to get the exe file to a txt file or a binary file
Just open the .exe as binary in C++ and you can read the raw bytes for encryption. Then write the cipher code to another binary file.
My best code is written with the delete key.
Encrypting an EXE file is not a good idea. You will more than likely break it...and in a sense they are already encrypted to the average viewer.
An easy way to encrypt it is to retrieve words from the file. Swap the low and high bytes and write that back to the disk. But be warned this will break the EXE until you swap it back. A simple way to swap the low and high bytes is by using the assembly instruction ROR or ROL rotate right or rotate left. You need to rotate the WORD by 8 bits either left or right to swap the order.
If you really wanted to get goofy you could swap the word's in a DWORD after you swapped the BYTES in a WORD or you can use XOR encryption or anything else you can come up with. Just make sure you can get it all put back together correctly.
You are probably much better off making your algorithm work with binary data. However if what you want to do is convert an arbitrary file into a sequence of printable characters and back again then there are lots of ways to do this. Radix-64 of mime and PGP fame is probably the most popular and portable. The plan here is basically the same as printing a byte as hex digits. the first character is based on the byte divided by 16, the second based on the remainder. With radix-64 you devide a 24 bit int by 64 creating 4 characters. Naturally this can all be done with shifts and or's and you treat the 24 bit int as 3 bytes. There is also good old uuencode that back in my day you had to use when someone sent you some pornagraphy, uh, I mean fractals, I need you to up my quota because we are sharing fractals and pictures of Shoemaker-Levy 9.