我正试图从.raw文件中恢复JPG,当我尝试打开" .jpg""从我的程序的输出,它给出了这个错误,或者它说了一些奇怪的十六进制,并说它是一个不受支持的JPEG标记类型(但它说它是一个jpg!)。我做错了什么?
*
* Recovers JPEGs from a forensic image.
*/
//0xff 0xd8 0xff 0xe0
//0xff 0xd8 0xff 0xe1
#define BLOCK 512
#define START1END 0xe0
#define START2END 0xe1
#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include <stdint.h>
//sets the begins or jpgs
uint8_t checkjpg1[4] = {0xff, 0xd8, 0xff, 0xe0};
uint8_t checkjpg2[4] = {0xff, 0xd8, 0xff, 0xe1};
//making variables
int found = 0;
char title[BLOCK];
FILE* img;
int ifopen = 1;
int main(int argc, char* argv[])
{
//opening file
FILE* inptr = fopen("card.raw", "r");
//checking if file opening failed
if (inptr == NULL)
{
return 2;
}
//making buffer
unsigned char buffer[BLOCK];
//going through the file
while(fread(&buffer,sizeof(char),BLOCK,inptr) == BLOCK)
{
//checking if begin == the possible begin of jpg
if ((buffer[0] == checkjpg1[0] && buffer[1] == checkjpg1[1] && buffer[2] == checkjpg1[2]) &&
(buffer[3] == checkjpg1[3] || buffer[3] == checkjpg2[3]))
{
//if a jpg is not open
if (ifopen == 1)
{
//make one
found+=1;
sprintf(title,"00%d.jpg",found);
img = fopen(title,"a");
if(buffer[3] == checkjpg1[3])
{
fwrite(&checkjpg1,sizeof(char),4,img);
}
}
else//else
{
//end the one and open new one
fclose(img);
found +=1;
sprintf(title,"00%d.jpg",found);
img = fopen(title,"a");
if(buffer[3] == checkjpg1[3])
{
fwrite(&checkjpg2,sizeof(char),4,img);
}
}
}
else if (img != NULL)
{
fwrite(buffer,sizeof(char),BLOCK,img);
}
}
fclose(inptr);
}
答案 0 :(得分:0)
帧开始(SOF)市场定义了图像的结构。扫描标记的开始包含压缩图像数据。您需要知道图像的大小(SOF)才能扩展压缩数据(SOS)。
听起来你的溪流缺少SOF标记。