Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <stdint.h>
- typedef uint8_t BYTE;
- typedef struct {
- BYTE out;
- }__attribute__((__packed__))
- outf;
- int main(int argc, char *argv[])
- {
- if(argc != 2) {
- fprintf(stderr, "Usage: %s forensic_file \n", argv[0]);
- return 1;
- }
- FILE *img = fopen(argv[1], "r");
- if(img == NULL) {
- fprintf(stderr, "Could not open\n");
- return 2;
- }
- FILE *out;
- int count = 0;
- while(1) {
- outf * C = malloc(sizeof(outf) * 512);
- size_t n = fread(C, sizeof(BYTE), 512, img);
- char filename[10];
- if((int)C[0].out == 0xff && (int)C[1].out == 0xd8 && (int)C[2].out == 0xff && ((int)C[3].out & 0xf0) == 0xe0) {
- if(count == 0) {
- sprintf(filename, "%03i.jpg", count);
- out = fopen(filename,"w");
- fwrite(C, 1, 512, out);
- count ++;
- // free(C);
- } else {
- fclose(out);
- sprintf(filename, "%03i.jpg", count);
- out = fopen(filename,"w");
- fwrite(C, 1, 512, out);
- count ++;
- // free(C);
- }
- } else if(count != 0) {
- fwrite(C, 512, 1, out);
- // free(C);
- }
- if(n != 512) {
- fclose (out);
- fclose(img);
- free(C);
- break;
- }
- free(C);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment