I open the file through main and pass the file pointer to the function.I've tested it by using Hex Workshop and adding the hex string 0200 0424.I tried it on a text file and an EXE.Here is the full code:
Code:
#include <stdio.h>
int dvd_chk(FILE *x);
int main(int argc, char *argv[])
{
FILE *inf;
int noc;
printf("DVD Check finder\n\n");
if (argc!=2){
printf("insufficient program usage\n");
printf("usage: dvdchk <file to be scanned>\n");
return 0;
}
inf=fopen( argv[1], "rb" );
if (inf==null){
printf("File %s does not exist\n");
return 0;
}
noc=dvd_chk(inf);
printf("Number of Checks: %d\n",noc);
return 0;
}
int dvd_chk(FILE *x)
{
int match=0;
char c;
while( (c = fgetc( x )) != EOF )
{
if ( c == 0x02 ) { c=fgetc(x);
if ( c == 0x00 ) { c=fgetc(x);
if ( c == 0x04 ) { c=fgetc(x);
if ( c == 0x24 ) { match++; }
}}}
}
fclose( x );
return match;
}