File: Libextract_plugin.java

package info (click to toggle)
sleuthkit 4.11.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,388 kB
  • sloc: ansic: 143,074; cpp: 33,286; java: 32,933; sh: 4,342; xml: 2,197; makefile: 436; python: 270
file content (64 lines) | stat: -rwxr-xr-x 1,746 bytes parent folder | download | duplicates (8)
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
59
60
61
62
63
64

/**
 * @author james migletz
 * Template based on JPEG_extractor.java written by
 * Simson Garfinkel
 * 
 * Filename: Libextract_Plugin.java
 *
 * Description: Java plug-in for libextractor.
 * This plug-in gateways to the "libextractor" plug-in 
 * through the command line, using the standard DGI interface.
 */

import java.io.*;
import java.util.regex.*;
import java.lang.Runtime;

class Libextract_plugin {
    static String processLibextractOutput(String s){
        String[] parts = s.split(" -");

	try {
	    String name  = parts[0].replace(" ","-");
	    String value = parts[1];
	    return name + ": " + value;
	} catch (ArrayIndexOutOfBoundsException e){
	    return null;
	}
    }
    /**
     * process FN with libextractor and return a string of name: value\r
     */
    static String process(String fn){     
        
        StringBuilder sb = new StringBuilder();
        try {
            ProcessBuilder pb = new ProcessBuilder("extract",fn);
            Process p = pb.start();
            InputStream is = p.getInputStream(); // "data piped from the standard output stream of the process"
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            while(true){
                String s = br.readLine();
                if(s==null) break;	// end of file
		String a = processLibextractOutput(s);
		if(a!=null){
		    sb.append(a);
		    sb.append("\n");
		}
            }
            br.close();
            is.close();
            
        } catch (java.io.IOException e){
            e.printStackTrace();
        }
        return sb.toString();
    }

    public static void main(String[] args){
        System.out.print(process(args[0]));
    }
}