问题描述
在pset4恢复中,我已经成功恢复了49个而不是50个JPG,尽管它们看起来还不错,但check50告诉我图像不匹配: :) recovery.c存在。 :) recovery.c编译。 :)处理缺乏取证图像 :(正确恢复000.jpg 恢复的图像不匹配 :(正确恢复中间图像 恢复的图像不匹配 :(可正确恢复049.jpg 049.jpg未找到
我的代码是:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
typedef uint8_t BYTE;
// Declare a function
int find_start(FILE *ptr);
int find_jpeg(FILE *ptr);
int main(int argc,char *argv[])
{
// Accept only one command-line argument
if (argc != 2)
{
printf("Enter the name of the forensic image\n");
return 1;
}
char *name = argv[1];
FILE *pointer = fopen(name,"r");
// Inform the reader if the file can't be opened
if (pointer == NULL)
{
printf("File cannot be opened\n");
return 1;
}
int q = 0;
// Find the signature for the beginning of the first jpeg
int d1 = find_start(pointer);
// Loop
while (q < 50)
{
if (q == 0)
{
fseek(pointer,508,SEEK_CUR);
}
int e = find_jpeg(pointer);
fseek(pointer,-(e + 512),SEEK_CUR);
BYTE array[e + 512];
fread(array,1,e + 512,pointer);
// Transfer the jpeg from the array to a new file
char new_name[8];
int o = sprintf(new_name,"%i%i%i.jpg",q / 100,q / 10 - (q / 100) * 100,q - (q / 100) * 100 - (q / 10) * 10);
FILE *out = fopen(new_name,"w");
fwrite(array,out);
q++;
fclose(out);
}
// Close all files
fclose(pointer);
return 0;
}
// Define the function for finding the beginning of the first jpeg
int find_start(FILE *ptr)
{
BYTE i,j,k,l;
int x;
int *count = &x;
*count = 0;
do
{
do
{
do
{
do
{
i = fgetc(ptr);
*count = *count + 1;
}
while (i != 0xff);
j = fgetc(ptr);
}
while (j != 0xd8);
k = fgetc(ptr);
*count = *count + 1;
}
while (k != 0xff);
l = fgetc(ptr);
*count = *count + 1;
}
while (l < 224 || l > 240);
return x;
}
int find_jpeg(FILE *ptr)
{
BYTE i,l;
int x;
int *count = &x;
*count = 0;
do
{
i = fgetc(ptr);
j = fgetc(ptr);
k = fgetc(ptr);
l = fgetc(ptr);
fseek(ptr,SEEK_CUR);
*count = *count + 1;
}
while (i != 0xff || j != 0xd8 || k != 0xff || l < 224 || l > 240);
int a = x * 512;
return a;
}
我知道这很长而且不优雅,但是否则问题是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)