File: jpeg_extract.cpp

package info (click to toggle)
sleuthkit 4.14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,268 kB
  • sloc: ansic: 143,839; cpp: 54,644; java: 39,009; xml: 2,417; python: 1,085; perl: 874; makefile: 451; sh: 196
file content (58 lines) | stat: -rw-r--r-- 1,265 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * jpeg DGI:
 *
 * build a jpeg extractor using the exif library.
 */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc,char **argv)
{
    char cmdbuf[1024];			// command buffer
    char linebuf[1024];


    if(argc!=2){
	fprintf(stderr,"usage: %s <filename>",argv[0]);
	exit(1);
    }
    sprintf(cmdbuf,"exif -m %s 2>/dev/null",argv[1]);
    FILE *f = popen(cmdbuf,"r");
    if(!f) perror(cmdbuf);

    /* the exif -m command will give us lines of output, tab delimited.
     * For DGI output we want names: values
     */
    while(fgets(linebuf,sizeof(linebuf),f)){
	/* Fix known errors in formatting */
	if(strncmp(linebuf,"Date and Time",13)==0){
	    char *ds = strchr(linebuf,'\t');
	    if(ds && ds[5]==':' && ds[8]==':'){
		ds[5]='-';
		ds[8]='-';
	    }
	}

	bool before = true;
	for(char *cc=linebuf;*cc;cc++){ // change ' '->'_" and '\t'->':' until we find the \t
	    if(before){
		switch(*cc){
		case ' ': putchar('-');break;
		case ':': putchar('-');break;
		case '(': putchar('-');break;
		case ')': putchar('-');break;
		case '\t': putchar(':');putchar(' ');before=false;break;
		default: putchar(*cc);break;
		}
	    }
	    else {
		putchar(*cc);
	    }
	}
    }
    pclose(f);
    return(0);
}