Imported Upstream version 1.1.5
Joao Eriberto Mota Filho
9 years ago
0 | 0 | For less detailed change information, see the NEWS file |
1 | 1 | |
2 | ------------------------------------------------------------------------ | |
3 | r602 | jbj | 2008-01-17 12:33:57 +0100 (Thu, 17 Jan 2008) | 1 line | |
4 | Changed paths: | |
5 | M /magicrescue/trunk/configure | |
6 | ||
7 | Workaround for Solaris /bin/sh non-POSIX 'trap' command | |
8 | ------------------------------------------------------------------------ | |
9 | r590 | jbj | 2007-12-31 16:25:04 +0100 (Mon, 31 Dec 2007) | 1 line | |
10 | Changed paths: | |
11 | M /magicrescue/trunk/src/dupemap.c | |
12 | M /magicrescue/trunk/src/magicrescue.c | |
13 | M /magicrescue/trunk/src/recipe.c | |
14 | M /magicrescue/trunk/src/recipe.h | |
15 | M /magicrescue/trunk/src/scanner.c | |
16 | M /magicrescue/trunk/src/scanner.h | |
17 | M /magicrescue/trunk/src/util.c | |
18 | M /magicrescue/trunk/src/util.h | |
19 | M /magicrescue/trunk/tools/textextract.c | |
20 | ||
21 | Change buffers to signed string types to silence gcc warnings | |
22 | ------------------------------------------------------------------------ | |
23 | r589 | jbj | 2007-12-31 15:37:57 +0100 (Mon, 31 Dec 2007) | 1 line | |
24 | Changed paths: | |
25 | M /magicrescue/trunk/new_NEWS | |
26 | ||
27 | news | |
28 | ------------------------------------------------------------------------ | |
29 | r588 | jbj | 2007-12-31 15:13:24 +0100 (Mon, 31 Dec 2007) | 1 line | |
30 | Changed paths: | |
31 | A /magicrescue/trunk/recipes/canon-cr2 | |
32 | ||
33 | Add a recipe for Canon CR2 RAW files | |
34 | ------------------------------------------------------------------------ | |
35 | r490 | jbj | 2007-06-22 10:49:38 +0200 (Fri, 22 Jun 2007) | 1 line | |
36 | Changed paths: | |
37 | M /magicrescue/trunk/configure | |
38 | ||
39 | typo | |
40 | ------------------------------------------------------------------------ | |
41 | r489 | jbj | 2007-06-21 22:30:14 +0200 (Thu, 21 Jun 2007) | 1 line | |
42 | Changed paths: | |
43 | M /magicrescue/trunk/configure | |
44 | ||
45 | Syntax fix to make configure script work on the dash shell (Debian, Ubuntu, ...) | |
46 | ------------------------------------------------------------------------ | |
47 | r488 | jbj | 2007-06-03 23:30:57 +0200 (Sun, 03 Jun 2007) | 1 line | |
48 | Changed paths: | |
49 | M /magicrescue/trunk/doc/dupemap.pod | |
50 | ||
51 | typo | |
52 | ------------------------------------------------------------------------ | |
53 | r483 | jbj | 2007-05-01 22:14:43 +0200 (Tue, 01 May 2007) | 1 line | |
54 | Changed paths: | |
55 | M /magicrescue/trunk/new_NEWS | |
56 | A /magicrescue/trunk/recipes/flac | |
57 | ||
58 | Add flac recipe | |
59 | ------------------------------------------------------------------------ | |
60 | r333 | jbj | 2004-08-15 11:19:08 +0200 (Sun, 15 Aug 2004) | 1 line | |
61 | Changed paths: | |
62 | M /magicrescue/trunk/configure | |
63 | ||
64 | Proper cleanup after configure | |
65 | ------------------------------------------------------------------------ | |
66 | r332 | jbj | 2004-08-15 01:31:23 +0200 (Sun, 15 Aug 2004) | 1 line | |
67 | Changed paths: | |
68 | M /magicrescue/trunk/README | |
69 | ||
70 | No users know what X/OPEN is | |
71 | ------------------------------------------------------------------------ | |
72 | r330 | jbj | 2004-08-15 01:16:20 +0200 (Sun, 15 Aug 2004) | 1 line | |
73 | Changed paths: | |
74 | M /magicrescue/trunk/NEWS | |
75 | M /magicrescue/trunk/new_NEWS | |
76 | ||
77 | Release 1.1.4 | |
2 | 78 | ------------------------------------------------------------------------ |
3 | 79 | r329 | jbj | 2004-08-15 01:10:37 +0200 (Sun, 15 Aug 2004) | 1 line |
4 | 80 | Changed paths: |
0 | Version 1.1.5: Thu Jan 17 14:03:49 CET 2008 | |
1 | - Recipe for Flac files | |
2 | - Recipe for Canon CR2 RAW files | |
3 | - Configure script compatibility fix for Debian-based Linuxes | |
4 | ||
0 | 5 | Version 1.1.4: Sun Aug 15 01:11:27 CEST 2004 |
1 | 6 | - Fixed a minor bug that prevented some not yet written recipes from working |
2 | 7 | perfectly |
15 | 15 | Building |
16 | 16 | -------- |
17 | 17 | |
18 | There are no build requirements other than a C library and an X/OPEN system | |
19 | interface. To use the dupemap(1) utility, you must have the NDBM | |
20 | compatibility header, which either comes with your system or the development | |
21 | libraries of GDBM or Berkeley DB. | |
18 | There are no build requirements other than a C library and a UNIXish system. | |
19 | To use the dupemap(1) utility, you must have the NDBM compatibility header, | |
20 | which either comes with your system or the development libraries of GDBM or | |
21 | Berkeley DB. | |
22 | 22 | |
23 | 23 | ./configure && make && make install |
24 | 24 |
32 | 32 | MAKE_VARS= |
33 | 33 | |
34 | 34 | if [ -f config.config ]; then |
35 | . config.config | |
35 | . ./config.config | |
36 | 36 | fi |
37 | 37 | |
38 | 38 | # |
95 | 95 | trap "mv config.h.bak config.h" 0 |
96 | 96 | fi |
97 | 97 | cat > config.h << EOF |
98 | /* XXX This file automatically generated by configure. */ | |
98 | /* XXX This file was automatically generated by configure. */ | |
99 | 99 | |
100 | 100 | EOF |
101 | 101 | |
172 | 172 | . "$f" |
173 | 173 | done |
174 | 174 | |
175 | rm -f conftest.c conftest.o conftest | |
175 | # | |
176 | # Clean up | |
177 | # | |
178 | trap "" 0 | |
179 | rm -f config.h.bak conftest.c conftest.o conftest | |
176 | 180 | |
177 | 181 | # |
178 | 182 | # Generate Makefile |
200 | 204 | |
201 | 205 | chmod 444 Makefile |
202 | 206 | |
203 | trap - 0 | |
204 | ||
205 | 207 | echo |
206 | 208 | echo "Done. Now type 'make' to compile" |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 | |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 | |
1 | 1 | .\" |
2 | 2 | .\" Standard preamble: |
3 | 3 | .\" ======================================================================== |
128 | 128 | .\" ======================================================================== |
129 | 129 | .\" |
130 | 130 | .IX Title "DUPEMAP 1" |
131 | .TH DUPEMAP 1 "2004-07-11" "1.1.4" "Magic Rescue" | |
131 | .TH DUPEMAP 1 "2007-12-31" "1.1.5" "Magic Rescue" | |
132 | 132 | .SH "NAME" |
133 | 133 | dupemap \- Creates a database of file checksums and uses it to eliminate |
134 | 134 | duplicates |
215 | 215 | delete all duplicate files in \fI/tmp/recovered\-files\fR, do: |
216 | 216 | .PP |
217 | 217 | .Vb 1 |
218 | \& $ dupemap delete /tmp/recovered files | |
218 | \& $ dupemap delete /tmp/recovered-files | |
219 | 219 | .Ve |
220 | 220 | .PP |
221 | 221 | Often, \fBdupemap scan\fR is run to produce a checksum database of all files in a |
110 | 110 | The easiest operations to understand is when the B<-d> option is not given. To |
111 | 111 | delete all duplicate files in F</tmp/recovered-files>, do: |
112 | 112 | |
113 | $ dupemap delete /tmp/recovered files | |
113 | $ dupemap delete /tmp/recovered-files | |
114 | 114 | |
115 | 115 | Often, B<dupemap scan> is run to produce a checksum database of all files in a |
116 | 116 | directory tree. Then B<dupemap delete> is run on another directory, possibly |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 | |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 | |
1 | 1 | .\" |
2 | 2 | .\" Standard preamble: |
3 | 3 | .\" ======================================================================== |
128 | 128 | .\" ======================================================================== |
129 | 129 | .\" |
130 | 130 | .IX Title "MAGICRESCUE 1" |
131 | .TH MAGICRESCUE 1 "2004-07-11" "1.1.4" "Magic Rescue" | |
131 | .TH MAGICRESCUE 1 "2007-12-31" "1.1.5" "Magic Rescue" | |
132 | 132 | .SH "NAME" |
133 | 133 | magicrescue \- Scans a block device and extracts known file types by looking at |
134 | 134 | magic bytes. |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.14 | |
0 | .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32 | |
1 | 1 | .\" |
2 | 2 | .\" Standard preamble: |
3 | 3 | .\" ======================================================================== |
128 | 128 | .\" ======================================================================== |
129 | 129 | .\" |
130 | 130 | .IX Title "MAGICSORT 1" |
131 | .TH MAGICSORT 1 "2004-05-02" "1.1.4" "Magic Rescue" | |
131 | .TH MAGICSORT 1 "2007-12-31" "1.1.5" "Magic Rescue" | |
132 | 132 | .SH "NAME" |
133 | 133 | magicsort \- Categorize files by their \fBfile\fR(1) magic |
134 | 134 | .SH "SYNOPSIS" |
0 | # Extract (at most 30 MB) Canon CR2 RAW files. These are used by the Powershot | |
1 | # and EOS digital cameras. | |
2 | # This recipe was contributed by Daniel J Blueman | |
3 | 0 string II* | |
4 | 8 string CR | |
5 | extension CR2 | |
6 | command dd bs=1024k count=30 of="$1" 2>/dev/null; dcraw -i "$1" || rm -f "$1" |
0 | # Extracts flac sound files: http://flac.sourceforge.net/ | |
1 | # Contributed by Richard Zidlicky <rz (at) linux (dash) m68k (dot) org> | |
2 | ||
3 | 0 string fLaC | |
4 | ||
5 | extension flac | |
6 | ||
7 | # Allow infinite overlap because the recompressed file may be much larger than | |
8 | # the original one.. at least in theory | |
9 | ||
10 | allow_overlap -1 | |
11 | ||
12 | ||
13 | # hope that flac will do the right thing | |
14 | command flac -d - | flac -8 - > "$1" |
197 | 197 | |
198 | 198 | static int checksum_calc(checksum_t *checksum, const char *file) |
199 | 199 | { |
200 | static unsigned char buf[BUFLEN]; | |
200 | static char buf[BUFLEN]; | |
201 | 201 | ssize_t bytes_read; |
202 | 202 | off_t _length = 0; |
203 | 203 | long _crc = 0; |
211 | 211 | } |
212 | 212 | |
213 | 213 | while ((bytes_read = fread(buf, 1, BUFLEN, fp)) > 0) { |
214 | unsigned char *cp = buf; | |
214 | char *cp = buf; | |
215 | 215 | |
216 | 216 | _length += bytes_read; |
217 | 217 | while (bytes_read--) |
66 | 66 | static ssize_t overlap = 0; |
67 | 67 | |
68 | 68 | /* General-purpose buffer. Mostly used to hold the raw data when scanning. */ |
69 | static unsigned char *buf; | |
69 | static char *buf; | |
70 | 70 | static const size_t bufsize = 102400; |
71 | 71 | |
72 | 72 | |
116 | 116 | * them. |
117 | 117 | * Returns 1 if an external program has been called, which means the file |
118 | 118 | * position has changed. Returns -1 on fatal error. */ |
119 | static int scan_buf(const unsigned char *scanbuf, ssize_t scanbuf_len, | |
119 | static int scan_buf(const char *scanbuf, ssize_t scanbuf_len, | |
120 | 120 | int fd, off_t scanbuf_filepos) |
121 | 121 | { |
122 | 122 | int filepos_changed = 0; |
144 | 144 | } |
145 | 145 | |
146 | 146 | array_foreach(&scanners, scanner) { |
147 | const unsigned char *p = scanbuf + scanner->offset; | |
147 | const char *p = scanbuf + scanner->offset; | |
148 | 148 | |
149 | 149 | while (p - scanbuf < scanbuf_len && |
150 | 150 | (p = scanner->func(p, scanbuf_len - (p-scanbuf) + |
225 | 225 | int fd = 0; |
226 | 226 | int result, firsttime = 1; |
227 | 227 | |
228 | unsigned char *readbuf = buf, *scanbuf = buf; | |
228 | char *readbuf = buf, *scanbuf = buf; | |
229 | 229 | size_t readsize = bufsize; |
230 | 230 | off_t offset_before_read; |
231 | 231 |
25 | 25 | #include "recipe.h" |
26 | 26 | |
27 | 27 | |
28 | int op_string(const unsigned char *s, union param *p) | |
28 | int op_string(const char *s, union param *p) | |
29 | 29 | { |
30 | 30 | return memcmp(s, p->string.s, p->string.l) == 0; |
31 | 31 | } |
32 | 32 | |
33 | int op_int32(const unsigned char *s, union param *p) | |
33 | int op_int32(const char *s_signed, union param *p) | |
34 | 34 | { |
35 | const unsigned char *s = (unsigned char *)s_signed; | |
35 | 36 | return ((s[0]<<24 | s[1]<<16 | s[2]<<8 | s[3]) & p->int32.mask) |
36 | 37 | == p->int32.val; |
37 | 38 | } |
9 | 9 | } int32; |
10 | 10 | }; |
11 | 11 | |
12 | typedef int (*op_function)(const unsigned char *, union param *); | |
12 | typedef int (*op_function)(const char *, union param *); | |
13 | 13 | |
14 | 14 | struct operation { |
15 | 15 | op_function func; |
28 | 28 | int allow_overlap; |
29 | 29 | }; |
30 | 30 | |
31 | int op_string(const unsigned char *s, union param *p); | |
32 | int op_int32(const unsigned char *s, union param *p); | |
31 | int op_string(const char *s, union param *p); | |
32 | int op_int32(const char *s, union param *p); | |
33 | 33 | |
34 | 34 | void op_destroy(struct operation *op); |
35 | 35 | void recipe_init(struct recipe *r); |
27 | 27 | #include "recipe.h" |
28 | 28 | #include "scanner.h" |
29 | 29 | |
30 | const unsigned char *scanner_char(const unsigned char *scanbuf, | |
30 | const char *scanner_char(const char *scanbuf, | |
31 | 31 | size_t scanbuf_len, union scan_param *param, off_t offset) |
32 | 32 | { |
33 | 33 | return memchr(scanbuf, param->c, scanbuf_len); |
34 | 34 | } |
35 | 35 | |
36 | const unsigned char *scanner_block(const unsigned char *scanbuf, | |
36 | const char *scanner_block(const char *scanbuf, | |
37 | 37 | size_t scanbuf_len, union scan_param *param, off_t offset) |
38 | 38 | { |
39 | 39 | long extrabytes = (long)offset & (param->block-1); |
46 | 46 | return scanbuf; |
47 | 47 | } |
48 | 48 | |
49 | const unsigned char *scanner_string(const unsigned char *scanbuf, | |
49 | const char *scanner_string(const char *scanbuf, | |
50 | 50 | size_t scanbuf_len, union scan_param *param, off_t offset) |
51 | 51 | { |
52 | const unsigned char *p = scanbuf + param->scanstring.magicoff; | |
52 | const char *p = scanbuf + param->scanstring.magicoff; | |
53 | 53 | struct string string = param->scanstring.string; |
54 | unsigned char magicchar = param->scanstring.magicchar; | |
54 | char magicchar = param->scanstring.magicchar; | |
55 | 55 | scanbuf_len += param->scanstring.magicoff; |
56 | 56 | |
57 | 57 | while ((size_t)(p - scanbuf) < scanbuf_len && |
14 | 14 | } scanstring; |
15 | 15 | }; |
16 | 16 | |
17 | typedef const unsigned char *(*scan_function)(const unsigned char *, size_t, | |
17 | typedef const char *(*scan_function)(const char *, size_t, | |
18 | 18 | union scan_param *, off_t); |
19 | 19 | |
20 | 20 | struct scanner { |
25 | 25 | struct array recipes; |
26 | 26 | }; |
27 | 27 | |
28 | const unsigned char *scanner_char(const unsigned char *scanbuf, | |
28 | const char *scanner_char(const char *scanbuf, | |
29 | 29 | size_t scanbuf_len, union scan_param *param, off_t offset); |
30 | const unsigned char *scanner_block(const unsigned char *scanbuf, | |
30 | const char *scanner_block(const char *scanbuf, | |
31 | 31 | size_t scanbuf_len, union scan_param *param, off_t offset); |
32 | const unsigned char *scanner_string(const unsigned char *scanbuf, | |
32 | const char *scanner_string(const char *scanbuf, | |
33 | 33 | size_t scanbuf_len, union scan_param *param, off_t offset); |
34 | 34 | |
35 | 35 | void scanner_string_init(union scan_param *param); |
31 | 31 | |
32 | 32 | |
33 | 33 | /** Returns the value (0-15) of a single hex digit. Returns 0 on error. */ |
34 | int hex2num(unsigned char c) | |
34 | int hex2num(char c) | |
35 | 35 | { |
36 | 36 | return (c >= '0' && c <= '9' ? c-'0' : |
37 | 37 | (c >= 'a' && c <= 'f' ? c-'a'+10 : |
38 | 38 | (c >= 'A' && c <= 'F' ? c-'A'+10 : 0))); |
39 | 39 | } |
40 | 40 | |
41 | long long hextoll(const unsigned char *str) | |
41 | long long hextoll(const char *str) | |
42 | 42 | { |
43 | 43 | long long result = 0; |
44 | 44 | size_t i, len = strlen(str); |
108 | 108 | |
109 | 109 | /** Initializes a struct string from a 0-terminated string, parsing escape |
110 | 110 | * sequences. The struct string will not be 0-terminated. */ |
111 | void string_init(struct string *dst, const unsigned char *src) | |
111 | void string_init(struct string *dst, const char *src) | |
112 | 112 | { |
113 | 113 | const size_t slen = strlen(src); |
114 | 114 | size_t i; |
7 | 7 | #endif |
8 | 8 | |
9 | 9 | struct string { |
10 | unsigned char *s; | |
10 | char *s; | |
11 | 11 | size_t l; |
12 | 12 | }; |
13 | 13 | |
14 | int hex2num(unsigned char c); | |
15 | long long hextoll(const unsigned char *str); | |
14 | int hex2num(char c); | |
15 | long long hextoll(const char *str); | |
16 | 16 | long atol_calc(const char *str); |
17 | 17 | off_t rich_seek(int fd, const char *string); |
18 | 18 | |
19 | void string_init(struct string *dst, const unsigned char *src); | |
19 | void string_init(struct string *dst, const char *src); | |
20 | 20 | void string_destroy(struct string *string); |
21 | 21 | |
22 | 22 | #define _UTIL_H |
37 | 37 | static long max_bytes = 0; |
38 | 38 | |
39 | 39 | static size_t bufsize = 8192; |
40 | static unsigned char *buf; | |
40 | static char *buf; | |
41 | 41 | |
42 | 42 | static short scorelut[UCHAR_MAX+1], replut[UCHAR_MAX+1]; |
43 | 43 | |
44 | 44 | struct rule { |
45 | 45 | short score, rep; |
46 | unsigned char *ranges; | |
46 | char *ranges; | |
47 | 47 | }; |
48 | 48 | |
49 | 49 | enum direction { DIR_FORWARD, DIR_REVERSE }; |
50 | 50 | static enum direction direction = DIR_FORWARD; |
51 | 51 | |
52 | 52 | struct scores { |
53 | unsigned char *last_letter; | |
53 | char *last_letter; | |
54 | 54 | unsigned char repeated_char; |
55 | 55 | int sum_score, sum_repeats, cur_line; |
56 | 56 | off_t offset; |
167 | 167 | }; |
168 | 168 | |
169 | 169 | for (rule = rules; rule->ranges != NULL; rule++) { |
170 | unsigned char a, b, *range = rule->ranges; | |
170 | unsigned char a, b; | |
171 | char *range = rule->ranges; | |
171 | 172 | int i; |
172 | 173 | |
173 | 174 | do { |
218 | 219 | static int read_backward(struct scores *s, int outfd) |
219 | 220 | { |
220 | 221 | ssize_t read_count; |
221 | unsigned char *p; | |
222 | char *p; | |
222 | 223 | |
223 | 224 | if (s->offset <= 0) |
224 | 225 | return 0; |
256 | 257 | static int read_forward(struct scores *s, int outfd) |
257 | 258 | { |
258 | 259 | ssize_t read_count; |
259 | unsigned char *p, *bufpos; | |
260 | char *p, *bufpos; | |
260 | 261 | |
261 | 262 | bufpos = buf; |
262 | 263 |