春天到了,今天在贴吧看到有个人在散播种子, 然后贴了张图片,说种子就藏在这张图片之中。
只要另存为后拓展名改成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();
{
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();
}
}
}
}
