作爲我的計算機安全課程的一部分,我正在解析hiberfil.sys文件,尋找PNG文件。我正在C中嘗試這個。我已經準備好了邏輯,當涉及到指針和C時,我完全感到困惑。我無法編譯以下代碼:解析png圖像的hiberfil.sys文件
#include<stdio.h>
#include<string.h>
int main(void)
{
FILE* fd = NULL;
FILE* out = NULL;
unsigned char* buff;
unsigned char* chunk[1024];
fd = fopen("hiberfil.sys","r");
out = fopen("a.png","w+");
if(NULL == fd)
{
printf("\n fopen() Error!!!\n");
return 1;
}
fread(buff,2,1,fd);
while(1){
if(*buff==137){
fread(buff,2,1,fd);
if(*buff==80){
fread(buff,2,1,fd);
if(*buff==78){
fread(buff,2,1,fd);
if(*buff==71){
fread(buff,2,1,fd);
if(*buff==13){
fread(buff,2,1,fd);
if(*buff==10){
fread(buff,2,1,fd);
if(*buff==26){
fread(buff,2,1,fd);
if(*buff==10){
int * a,b,c,d,e,f,g,h,i;
*a=137;
*b=80;
*c=78;
*d=71;
*e=13;
*f=10;
*g=26;
*h=10;
fwrite(a,2,1,out);
fwrite(b,2,1,out);
fwrite(c,2,1,out);
fwrite(d,2,1,out);
fwrite(e,2,1,out);
fwrite(f,2,1,out);
fwrite(g,2,1,out);
fwrite(h,2,1,out);
break;
}
else continue;
}
else continue;
}
else continue;
}
else continue;
}
else continue;
}
else continue;
}
else fread(buff,2,1,fd);
}
}
unsigned char type[4]=0;
while(type[0]!=73 || type[1]!=69 || type[2]!=78 || type[3]!=68){
fread(length,sizeof(int),1,fd);
fread(type,4,1,fd);
fread(chunk,length+4,1,fd);
fwrite(length,sizeof(int),1,out);
fwrite(type,4,1,out);
fwrite(chunk,length+8,1,out);
}
fclose(fd);
fclose(out);
return 0;
}
非常感謝! PS:有人可以幫助我的代碼塊的格式!
編輯有錯誤
error: invalid type argument of unary ‘*’ (have ‘int’) <<<< Refering to int * pointers
error: initializing argument 1 of ‘size_t fwrite(const void*, size_t, size_t, FILE*)’ <<<< Refering to int length i believe.
他們現在看起來微不足道給我,但還是說明小劑量會幫助我。至於這些指針呢?
Holy Moly!這很複雜。也許尋找一種方式來重構它與數據結構和循環? – wallyk