Codebase list magicrescue / ed3e667
Imported Upstream version 1.1.5 Joao Eriberto Mota Filho 9 years ago
19 changed file(s) with 157 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
00 For less detailed change information, see the NEWS file
11
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
278 ------------------------------------------------------------------------
379 r329 | jbj | 2004-08-15 01:10:37 +0200 (Sun, 15 Aug 2004) | 1 line
480 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
05 Version 1.1.4: Sun Aug 15 01:11:27 CEST 2004
16 - Fixed a minor bug that prevented some not yet written recipes from working
27 perfectly
1515 Building
1616 --------
1717
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.
2222
2323 ./configure && make && make install
2424
3232 MAKE_VARS=
3333
3434 if [ -f config.config ]; then
35 . config.config
35 . ./config.config
3636 fi
3737
3838 #
9595 trap "mv config.h.bak config.h" 0
9696 fi
9797 cat > config.h << EOF
98 /* XXX This file automatically generated by configure. */
98 /* XXX This file was automatically generated by configure. */
9999
100100 EOF
101101
172172 . "$f"
173173 done
174174
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
176180
177181 #
178182 # Generate Makefile
200204
201205 chmod 444 Makefile
202206
203 trap - 0
204
205207 echo
206208 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
11 .\"
22 .\" Standard preamble:
33 .\" ========================================================================
128128 .\" ========================================================================
129129 .\"
130130 .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"
132132 .SH "NAME"
133133 dupemap \- Creates a database of file checksums and uses it to eliminate
134134 duplicates
215215 delete all duplicate files in \fI/tmp/recovered\-files\fR, do:
216216 .PP
217217 .Vb 1
218 \& $ dupemap delete /tmp/recovered files
218 \& $ dupemap delete /tmp/recovered-files
219219 .Ve
220220 .PP
221221 Often, \fBdupemap scan\fR is run to produce a checksum database of all files in a
110110 The easiest operations to understand is when the B<-d> option is not given. To
111111 delete all duplicate files in F</tmp/recovered-files>, do:
112112
113 $ dupemap delete /tmp/recovered files
113 $ dupemap delete /tmp/recovered-files
114114
115115 Often, B<dupemap scan> is run to produce a checksum database of all files in a
116116 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
11 .\"
22 .\" Standard preamble:
33 .\" ========================================================================
128128 .\" ========================================================================
129129 .\"
130130 .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"
132132 .SH "NAME"
133133 magicrescue \- Scans a block device and extracts known file types by looking at
134134 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
11 .\"
22 .\" Standard preamble:
33 .\" ========================================================================
128128 .\" ========================================================================
129129 .\"
130130 .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"
132132 .SH "NAME"
133133 magicsort \- Categorize files by their \fBfile\fR(1) magic
134134 .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"
197197
198198 static int checksum_calc(checksum_t *checksum, const char *file)
199199 {
200 static unsigned char buf[BUFLEN];
200 static char buf[BUFLEN];
201201 ssize_t bytes_read;
202202 off_t _length = 0;
203203 long _crc = 0;
211211 }
212212
213213 while ((bytes_read = fread(buf, 1, BUFLEN, fp)) > 0) {
214 unsigned char *cp = buf;
214 char *cp = buf;
215215
216216 _length += bytes_read;
217217 while (bytes_read--)
6666 static ssize_t overlap = 0;
6767
6868 /* General-purpose buffer. Mostly used to hold the raw data when scanning. */
69 static unsigned char *buf;
69 static char *buf;
7070 static const size_t bufsize = 102400;
7171
7272
116116 * them.
117117 * Returns 1 if an external program has been called, which means the file
118118 * 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,
120120 int fd, off_t scanbuf_filepos)
121121 {
122122 int filepos_changed = 0;
144144 }
145145
146146 array_foreach(&scanners, scanner) {
147 const unsigned char *p = scanbuf + scanner->offset;
147 const char *p = scanbuf + scanner->offset;
148148
149149 while (p - scanbuf < scanbuf_len &&
150150 (p = scanner->func(p, scanbuf_len - (p-scanbuf) +
225225 int fd = 0;
226226 int result, firsttime = 1;
227227
228 unsigned char *readbuf = buf, *scanbuf = buf;
228 char *readbuf = buf, *scanbuf = buf;
229229 size_t readsize = bufsize;
230230 off_t offset_before_read;
231231
2525 #include "recipe.h"
2626
2727
28 int op_string(const unsigned char *s, union param *p)
28 int op_string(const char *s, union param *p)
2929 {
3030 return memcmp(s, p->string.s, p->string.l) == 0;
3131 }
3232
33 int op_int32(const unsigned char *s, union param *p)
33 int op_int32(const char *s_signed, union param *p)
3434 {
35 const unsigned char *s = (unsigned char *)s_signed;
3536 return ((s[0]<<24 | s[1]<<16 | s[2]<<8 | s[3]) & p->int32.mask)
3637 == p->int32.val;
3738 }
99 } int32;
1010 };
1111
12 typedef int (*op_function)(const unsigned char *, union param *);
12 typedef int (*op_function)(const char *, union param *);
1313
1414 struct operation {
1515 op_function func;
2828 int allow_overlap;
2929 };
3030
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);
3333
3434 void op_destroy(struct operation *op);
3535 void recipe_init(struct recipe *r);
2727 #include "recipe.h"
2828 #include "scanner.h"
2929
30 const unsigned char *scanner_char(const unsigned char *scanbuf,
30 const char *scanner_char(const char *scanbuf,
3131 size_t scanbuf_len, union scan_param *param, off_t offset)
3232 {
3333 return memchr(scanbuf, param->c, scanbuf_len);
3434 }
3535
36 const unsigned char *scanner_block(const unsigned char *scanbuf,
36 const char *scanner_block(const char *scanbuf,
3737 size_t scanbuf_len, union scan_param *param, off_t offset)
3838 {
3939 long extrabytes = (long)offset & (param->block-1);
4646 return scanbuf;
4747 }
4848
49 const unsigned char *scanner_string(const unsigned char *scanbuf,
49 const char *scanner_string(const char *scanbuf,
5050 size_t scanbuf_len, union scan_param *param, off_t offset)
5151 {
52 const unsigned char *p = scanbuf + param->scanstring.magicoff;
52 const char *p = scanbuf + param->scanstring.magicoff;
5353 struct string string = param->scanstring.string;
54 unsigned char magicchar = param->scanstring.magicchar;
54 char magicchar = param->scanstring.magicchar;
5555 scanbuf_len += param->scanstring.magicoff;
5656
5757 while ((size_t)(p - scanbuf) < scanbuf_len &&
1414 } scanstring;
1515 };
1616
17 typedef const unsigned char *(*scan_function)(const unsigned char *, size_t,
17 typedef const char *(*scan_function)(const char *, size_t,
1818 union scan_param *, off_t);
1919
2020 struct scanner {
2525 struct array recipes;
2626 };
2727
28 const unsigned char *scanner_char(const unsigned char *scanbuf,
28 const char *scanner_char(const char *scanbuf,
2929 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,
3131 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,
3333 size_t scanbuf_len, union scan_param *param, off_t offset);
3434
3535 void scanner_string_init(union scan_param *param);
3131
3232
3333 /** 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)
3535 {
3636 return (c >= '0' && c <= '9' ? c-'0' :
3737 (c >= 'a' && c <= 'f' ? c-'a'+10 :
3838 (c >= 'A' && c <= 'F' ? c-'A'+10 : 0)));
3939 }
4040
41 long long hextoll(const unsigned char *str)
41 long long hextoll(const char *str)
4242 {
4343 long long result = 0;
4444 size_t i, len = strlen(str);
108108
109109 /** Initializes a struct string from a 0-terminated string, parsing escape
110110 * 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)
112112 {
113113 const size_t slen = strlen(src);
114114 size_t i;
77 #endif
88
99 struct string {
10 unsigned char *s;
10 char *s;
1111 size_t l;
1212 };
1313
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);
1616 long atol_calc(const char *str);
1717 off_t rich_seek(int fd, const char *string);
1818
19 void string_init(struct string *dst, const unsigned char *src);
19 void string_init(struct string *dst, const char *src);
2020 void string_destroy(struct string *string);
2121
2222 #define _UTIL_H
3737 static long max_bytes = 0;
3838
3939 static size_t bufsize = 8192;
40 static unsigned char *buf;
40 static char *buf;
4141
4242 static short scorelut[UCHAR_MAX+1], replut[UCHAR_MAX+1];
4343
4444 struct rule {
4545 short score, rep;
46 unsigned char *ranges;
46 char *ranges;
4747 };
4848
4949 enum direction { DIR_FORWARD, DIR_REVERSE };
5050 static enum direction direction = DIR_FORWARD;
5151
5252 struct scores {
53 unsigned char *last_letter;
53 char *last_letter;
5454 unsigned char repeated_char;
5555 int sum_score, sum_repeats, cur_line;
5656 off_t offset;
167167 };
168168
169169 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;
171172 int i;
172173
173174 do {
218219 static int read_backward(struct scores *s, int outfd)
219220 {
220221 ssize_t read_count;
221 unsigned char *p;
222 char *p;
222223
223224 if (s->offset <= 0)
224225 return 0;
256257 static int read_forward(struct scores *s, int outfd)
257258 {
258259 ssize_t read_count;
259 unsigned char *p, *bufpos;
260 char *p, *bufpos;
260261
261262 bufpos = buf;
262263