Click here to Skip to main content
13,252,206 members (55,321 online)
Rate this:
Please Sign up or sign in to vote.
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 12-May-13 6:10am
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...
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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 14 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100