Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char *argv[])
- {
- // keep filenames
- char *infile = argv[1],
- *outfile = NULL;
- FILE *inptr = fopen(infile, "r"),
- *outptr = NULL;
- BYTE *byte_array = malloc(512 * sizeof(BYTE));
- int filename_counter = 0;
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // program works only with initialized outfile - remove this part and it crashes on sprintf
- outfile = malloc(sizeof("000.jpg") + 1);
- sprintf(outfile, "%03i.jpg", filename_counter);
- outptr = fopen(outfile, "w");
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- /**
- * CODE
- * CODE
- * CODE
- **/
- if (header_is_jpeg(inptr))
- {
- create_new_outfile(&outfile, &outptr, &filename_counter);
- }
- // only keep reading if block is proper size (512)
- while (fread(outptr, 1, 512, inptr) == 512)
- {
- // rewind seek
- fseek(inptr, -512, SEEK_CUR);
- // read and write 512 bytes, 1 byte at a time
- for(int i = 0, arr_size = sizeof(byte_array); i < arr_size; i++)
- {
- fread(&byte_array[i], 1, 1, inptr);
- /**
- * !!!!!!!!!!!!!!!!!!!!!!!
- * CODE CRASHES HERE
- * !!!!!!!!!!!!!!!!!!!!!!!
- **/
- fwrite(&byte_array[i], 1, 1, outptr);
- }
- }
- // close files
- fclose(inptr);
- fclose(outptr);
- return 0;
- }
- int header_is_jpeg(FILE *memcard)
- {
- /**
- * CODE
- * CODE
- * CODE
- **/
- }
- void create_new_outfile(char **outfile, FILE **outptr, int *filename_counter)
- {
- // if a file is open - close the old one before creating new one
- if (*outptr != NULL)
- {
- printf("Recovered image: %s\n", *outfile);
- fclose(*outptr);
- free(*outfile);
- }
- // create new output file
- *outfile = malloc(sizeof("000.jpg") + 1);
- sprintf(*outfile, "%03i.jpg", *filename_counter+3);
- *outptr = fopen(*outfile, "w");
- (*filename_counter)++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement