Click here to Skip to main content
13,347,998 members (66,935 online)
Click here to Skip to main content
Add your own
alternative version


40 bookmarked
Posted 27 Nov 2003

Hide a file in a BMP file (Plus).

, 27 Nov 2003
Rate this:
Please Sign up or sign in to vote.
Hide a file in a BMP file: extended from the author Ahmed Osama's article.

Sample Image - HideIt2.jpg


After I read the article 'Hiding a text file in a BMP file', I found it very funny, and maybe useful. So I decided to extend it to fit in with any file, any password, and become easy to use.


You can find its principle here: Hiding a text file in a BMP file. Very thanks to Ahmed Osama's idea and good work.

Class Structure

class CBmpHermitCrab
 bool Hermit(const char* pszDestFileName, 
  const char* pszSrcFileName,
  const char* pszPassword=NULL, 
  const char* pszResultFile=NULL); 
 bool IsHermitCrabBMPFile(const char* pszFileName);
 bool RecoverCrabFile(const char* pszFileName, 
  const char* pszPassword=NULL, const char* pszPath=NULL);

It provides three methods to implement the following tasks:

  1. Hermit(). Hides a file in a BMP file.

    The main code:

      for(int i=0;i<(iBinaryLen/8); i++){
         temp= m_binaryMap[(unsigned char) strBufferAll[i]];
         srcBinary[nIndex] = temp[0];
         srcBinary[nIndex+1] =temp[1];
         srcBinary[nIndex+2] =temp[2];
         srcBinary[nIndex+3] =temp[3];
         srcBinary[nIndex+4] =temp[4];
         srcBinary[nIndex+5] =temp[5];
         srcBinary[nIndex+6] =temp[6];
         srcBinary[nIndex+7] =temp[7];
      int mask=254for (i=0 ; i<iBinaryLen ; i++){
          bmpBuffer[i+55]=bmpBuffer[i+55] & mask;
          if (srcBinary[i]=='1')  

    Through our binary table srcBinary and the correct index, we can express a char by using the original pixel color value micro-changed.

  2. RecoverCrabFile(). Recovers hidden file from a HermitCrab ;) BMP file.

    The key code:

     for(j=55+8*nHeadSize; j < 55+8*nHeadSize 
           (unsigned char) ((unsigned char)buffer[j] & 1);
     CString strTemp;
     for(j=55+8*nHeadSize; j < 
  3. IsHermitCrabBMPFile(). Like method 2, but it just recovers the fist 8 bytes, and whether the first two bytes: 'C' and 'H'.

Using the code

  1. Include the BmpHermitCrab.h file.
  2. Generate a CBmpHermitCrab instance.
  3. With the instance, use the Hermit() method to hide a file in a BMP file with optional password and use the RecoverCrabFile() method to recover a file from a 'HermitCrab' BMP file. You can check the BMP file format by IsHermitCrabBMPFile() method.

Hope you enjoy the program!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Neil Xu
Web Developer IT - All
China China
I'm programmer,and love it.

You may also be interested in...


Comments and Discussions

GeneralIt does not check if the to hide file is too large! Pin
rootdial18-Dec-08 23:39
memberrootdial18-Dec-08 23:39 
GeneralHi Pin
tnla26-Nov-08 5:07
membertnla26-Nov-08 5:07 
GeneralHi Pin
tnla25-Nov-08 10:25
membertnla25-Nov-08 10:25 
Generalhmm.... Pin
AuroraX3-Apr-05 20:34
memberAuroraX3-Apr-05 20:34 
GeneralHmm so so Pin
Anonymous23-Apr-04 16:19
sussAnonymous23-Apr-04 16:19 
GeneralRe: Hmm so so Pin
strych94-May-05 7:44
memberstrych94-May-05 7:44 
QuestionCan you include *.exe file in the bitmap Pin
Murad2-Dec-03 5:44
memberMurad2-Dec-03 5:44 
AnswerRe: Can you include *.exe file in the bitmap Pin
chopeen2-Dec-03 6:10
memberchopeen2-Dec-03 6:10 
GeneralRe: Can you include *.exe file in the bitmap Pin
lallous2-Dec-03 22:06
memberlallous2-Dec-03 22:06 
GeneralInsecure Pin
Dominik Reichl28-Nov-03 7:48
memberDominik Reichl28-Nov-03 7:48 
Generalnew challenge Pin
TeaShirt28-Nov-03 6:05
memberTeaShirt28-Nov-03 6:05 
GeneralGood, but you should have put yr code inside the <pre>,</pre> Pin
Zhefu Zhang28-Nov-03 4:27
memberZhefu Zhang28-Nov-03 4:27 
Generalthx :) Pin
Adore C++28-Nov-03 3:41
memberAdore C++28-Nov-03 3:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 28 Nov 2003
Article Copyright 2003 by Neil Xu
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid