图片文件中隐藏一个rar压缩包的秘密

这篇博客揭示了一种将RAR压缩包隐藏在图片文件中的技巧。通过分析图片格式,作者发现可以在图片文件的尾部附加RAR文件,因为RAR格式会从头部开始寻找正确的解压标识。使用VC++ MFC和C#编写的小程序演示了如何合并图片和RAR文件,创建一个看似普通图片但实际上包含隐藏数据的文件。这种方法可以用于隐蔽信息传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

春天到了,今天在贴吧看到有个人在散播种子, 然后贴了张图片,说种子就藏在这张图片之中。羡慕  只要另存为后拓展名改成rar后能被压缩软件识别并解压。尝试了一下,竟然真可以。
    挺好奇的,于是就开始查找jpg图片的格式信息,发现jpg、bmp、gif文件头部有标识文件大小的数据段,所以我想如果在文件不管写入什么文件都是可以被识别的,而rar格式会从头搜索直到找到正确的rar头,然后根据这个rar头解压。于是其实只要把这两个文件合并成一个文件就可以了。于是就用VC++、C#写了一个小程序尝试了下果真如此。
VC++ MFC
bool Cjpg_rarDlg::dealwith(TCHAR* path1, TCHAR* path2, TCHAR* path3) 
{ 
    std::ifstream inf1, inf2; 
    std::ofstream ouf; 
    inf1.open(path1,std::ios::binary); 
    if(!inf1) 
    { 
        MessageBox(_T("待合成图片文件不存在!")); 
        return false; 
    } 
    inf2.open(path2,std::ios::binary); 
    if(!inf2) 
    { 
        MessageBox(_T("待合成rar压缩文件不存在!")); 
        inf1.close(); 
        return false; 
    } 
    ouf.open(path3, std::ios::out| std::ios::binary); 
 if(!ouf) 
    { 
        MessageBox(_T("创建文件失败!")); 
        inf1.close(); 
        inf2.close(); 
        return false; 
    } 
    char buff[1024]; 
    while(!inf1.eof()) 
    { 
        inf1.read((char*)buff, sizeof(buff)); 
        ouf.write((char*)buff, inf1.gcount());//用inf1.gcount()防止末尾缓存区有空的 
    } 
    inf1.close(); 
     
    while(!inf2.eof()) 
    { 
        inf2.read((char*)buff,sizeof(buff)); 
        ouf.write((char*)buff ,inf2.gcount());//用inf1.gcount(/防止末尾缓存区有空的 
    } 
    inf2.close(); 
    ouf.close(); 
    MessageBox(_T("合成成功,请检查!")); 
    return true; 
}

C#
C#
private bool dealwith( string path1, string path2, string path3)
       {
           FileStream inf1 = null;
           FileStream inf2 = null;
           FileStream outf = null;
           byte[] buff = new byte[1024]; //缓冲区
           try
           {
               inf1 = new FileStream(path1, FileMode.Open);
               inf2 = new FileStream(path2, FileMode.Open);
               outf = new FileStream(path3, FileMode.CreateNew);
               int hasRead = 0;

               hasRead = inf1.Read(buff, 0,1024);
               while (hasRead != 0)
               {
                   outf.Write(buff, 0, hasRead);
                   hasRead = inf1.Read(buff, 0, 1024);
               }

               hasRead = inf2.Read(buff, 0, 1024);
               while (hasRead != 0)
               {
                   outf.Write(buff, 0, hasRead);
                   hasRead = inf2.Read(buff, 0, 1024);
               }
               return true;
           }
           catch (Exception err)
           {
               MessageBox.Show( "发生错误!\n错误信息:\n" + err.Message);
               return false;
           }
           finally
           {
               inf1.Close();
               inf2.Close();
               outf.Close();
           }

       }
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值