Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Is it possible to read a binary file such as .exe / .jpg files using C++ and encrypt it using some simple algorithm.

The real question is how to read an entire .exe or jpg file into 1 dimensional array and manipulate it.
Posted
Comments
Sergey Alexandrovich Kryukov 12-May-13 13:44pm    
Is it C++ or C++/CLI? What library do you use for reading JPEG? It be able should to store the data in any stream including memory stream...
—SA
compuknow 12-May-13 22:12pm    
I am not using any specific class or function for reading image files. I am just trying to load the entire binary file (jpg / exe) into a 1 dimensional array using commands in fstream.h.

But the problem is I am unable to manipulate the array data (elements).
Jochen Arndt 13-May-13 4:29am    
It is unclear where you got stuck.
The common steps to read, manipulate and write a file are:
- Get the file size (e.g. using the stat() function)
- Allocate a buffer of that size (type unsigned char [] for binary data)
- Read the file content into that buffer (using read() with iostreams)
- Manipulate the buffer
- Write the buffer to the output file (using write() with iostreams)

1 solution

The simple answer is "yes". You can encrypt any type of file, and a .exe/.dll is just another type of file. You have to beware of obvious things like file access and ownership but it can be done without significant trouble. You typically won't be able to write to system files or files that are currently in use.
 
Share this answer
 

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