Click here to Skip to main content
Click here to Skip to main content

Hide a file in a BMP file (Plus).

By , 27 Nov 2003
 

Sample Image - HideIt2.jpg

Introduction

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.

Background

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
{
 ...
public:
 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:

    ...
     nIndex=0;
      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];
         nIndex=nIndex+8; 
      }
    
      int mask=254; 
      for (i=0 ; i<iBinaryLen ; i++){
          bmpBuffer[i+55]=bmpBuffer[i+55] & mask;
          if (srcBinary[i]=='1')  
            bmpBuffer[i+55]=bmpBuffer[i+55]+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 
       +pHermitCrabHead->bPasswordLen*8+
       pHermitCrabHead->bFileNameLen*8;j++){
          recBin[j]= 
           (unsigned char) ((unsigned char)buffer[j] & 1);
     }
     CString strTemp;
     for(j=55+8*nHeadSize; j < 
       55+8*nHeadSize+pHermitCrabHead->bPasswordLen*8+
       pHermitCrabHead->bFileNameLen*8;j=j+8){
          temp=128*recBin[j]+64*recBin[j+1]+32*recBin[j+2]+
              16*recBin[j+3]+8*recBin[j+4]+4*recBin[j+5]+
              2*recBin[j+6]+1*recBin[j+7];
        strTemp+=temp;
     } 
    ...
  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!

License

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
Member
I'm programmer,and love it.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralIt does not check if the to hide file is too large!memberrootdial18 Dec '08 - 22:39 
Hi you did a good job yes.
But there is one big important thing missing:
 
A message if the to hide file is too big for a join to the
set bitmap to hide it in.
 
The other mentioned project does inform you if this happens...
 
Add it please Wink | ;-)
GeneralHimembertnla26 Nov '08 - 4:07 
Good job
GeneralHimembertnla25 Nov '08 - 9:25 
Thank u its good job
Generalhmm....memberAuroraX3 Apr '05 - 19:34 
wel...to encrypt the data, i think u can use the random no. to change the original data to encrypted (by some simple mathematical operation).....all u need to maintain is the random seed...so that u can still manage to extract back the file.....pliz let me know if this work..as I'm only a beginner programmer and doesnt know lot about C++.....
 
also one more thing....what happen if the file to be hidden is LARGER than the bmp file????/
 

 

GeneralHmm so sosussAnonymous23 Apr '04 - 15:19 
Why would you even consider giving Bin Laden any praise?
 
You suck!
 
RJ
GeneralRe: Hmm so somemberstrych94 May '05 - 6:44 
What are you talking about???
QuestionCan you include *.exe file in the bitmapmemberMurad2 Dec '03 - 4:44 
Can you include *.exe file in the bitmap, so that it will be launched on bitmap opening. It is also possible to include an exe file, but how to launch it, i don't know.Blush | :O
 
Best Regards
Murad.
AnswerRe: Can you include *.exe file in the bitmapmemberchopeen2 Dec '03 - 5:10 
Murad wrote:
It is also possible to include an exe file
 
How?
 
Murad wrote:
but how to launch it, i don't know
 
Hope it's not possible - think of all the viruses.
 
"Gods die, when their believers are gone." --from Sandman by Neil Gaiman
GeneralRe: Can you include *.exe file in the bitmapmemberlallous2 Dec '03 - 21:06 
You should be able to hide any file inside a bitmap. Try researching about 'steganography'.
 
Don't think there is a way to launch the EXE inside the bitmap upon viewing the BMP, cause the bitmap viewer doesn't not know how to extract the hidden file from the BMP nor does it cate to do more than reading pixel info and displaying them on the screen.
 
Regards,
Elias
GeneralInsecurememberDominik Reichl28 Nov '03 - 6:48 
Perhaps you should mention in your article that it only should demonstrate how to manipulate bitmap files and that the "encryption" method is totally insecure.
 
The password is stored in plain in the bitmap and the data isn't encrypted at all. Everyone can easily read the data hidden in bitmap files created by your program.
 
Rose | [Rose]
Dominik

 

_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do?? Wink | ;)
(doesn't work on NT)

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

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