1
- /* $Id$
1
+ /* $Id: dcfldd.c,v 1.3 2005/05/13 18:52:06 harbourn Exp $
2
2
* dcfldd - The Enhanced Forensic DD
3
3
* By Nicholas Harbour
4
4
*/
59
59
#include "pattern.h"
60
60
#include "output.h"
61
61
#include "split.h"
62
+ #include "hashformat.h"
63
+ #include "util.h"
62
64
63
65
/* The name this program was run with. */
64
66
char * program_name ;
@@ -124,11 +126,20 @@ int do_split = 0;
124
126
#define DEFAULT_SPLIT_FORMAT "nnn"
125
127
#endif /* DEFAULT_SPLIT_FORMAT */
126
128
129
+ #ifndef DEFAULT_HASHWINDOW_FORMAT
130
+ #define DEFAULT_HASHWINDOW_FORMAT "#window_start# - #window_end#: #hash#"
131
+ #endif /* DEFAULT_HASHWINDOW_FORMAT */
132
+
133
+ #ifndef DEFAULT_TOTALHASH_FORMAT
134
+ #define DEFAULT_TOTALHASH_FORMAT "Total (#algorithm#): #hash#"
135
+ #endif /* DEFAULT_TOTALHASH_FORMAT */
136
+
127
137
static char * splitformat = DEFAULT_SPLIT_FORMAT ;
128
138
static off_t splitsize ;
129
139
130
140
/* How many blocks in between screen writes for status output. */
131
- const ssize_t update_thresh = 256 ;
141
+ ssize_t update_thresh = 256 ;
142
+
132
143
time_t start_time ;
133
144
134
145
static struct conversion conversions [] =
@@ -157,57 +168,86 @@ void usage(int status)
157
168
printf ("\
158
169
Copy a file, converting and formatting according to the options.\n\
159
170
\n\
160
- bs=BYTES force ibs=BYTES and obs=BYTES\n\
161
- cbs=BYTES convert BYTES bytes at a time\n\
162
- conv=KEYWORDS convert the file as per the comma separated keyword list\n\
163
- count=BLOCKS copy only BLOCKS input blocks\n\
164
- ibs=BYTES read BYTES bytes at a time\n\
165
- if=FILE read from FILE instead of stdin\n\
166
- obs=BYTES write BYTES bytes at a time\n\
167
- of=FILE write to FILE instead of stdout\n\
168
- NOTE: of=FILE may be used several times to write\n\
169
- output to multiple files simultaneously\n\
170
- seek=BLOCKS skip BLOCKS obs-sized blocks at start of output\n\
171
- skip=BLOCKS skip BLOCKS ibs-sized blocks at start of input\n\
172
- pattern=HEX use the specified binary pattern as input\n\
173
- textpattern=TEXT use repeating TEXT as input\n\
174
- hashwindow=BYTES perform a hash on every BYTES amount of data\n\
175
- hash=NAME either md5, sha1, sha256, sha384 or sha512\n\
176
- default algorithm is md5. To select multiple\n\
177
- algorithms to run simultaneously enter the names\n\
178
- in a comma separated list\n\
179
- hashlog=FILE send MD5 hash output to FILE instead of stderr\n\
180
- if you are using multiple hash algorithms you\n\
181
- can send each to a seperate file using the\n\
182
- convention ALGORITHMlog=FILE, for example\n\
183
- md5log=FILE1, sha1log=FILE2, etc.\n\
184
- status=[on|off] display a continual status message on stderr\n\
185
- default state is \"on\"\n\
186
- sizeprobe=[if|of] determine the size of the input or output file\n\
187
- for use with status messages. (this option\n\
188
- gives you a percentage indicator)\n\
189
- WARNING: do not use this option against a\n\
190
- tape device.\n\
191
- split=BYTES write every BYTES amount of data to a new file\n\
192
- This operation applies to any of=FILE that follows\n\
193
- splitformat=TEXT the file extension format for split operation.\n\
194
- you may use any number of 'a' or 'n' in any combo\n\
195
- the default format is \"nnn\"\n\
196
- NOTE: The split and splitformat options take effect\n\
197
- only for output files specified AFTER these\n\
198
- options appear in the command line. Likewise,\n\
199
- you may specify these several times for\n\
200
- for different output files within the same\n\
201
- command line. you may use as many digits in\n\
202
- any combination you would like.\n\
203
- (e.g. \"anaannnaana\" would be valid, but\n\
204
- quite insane)\n\
205
- vf=FILE verify that FILE matches the specified input\n\
206
- verifylog=FILE send verify results to FILE instead of stderr\n\
171
+ bs=BYTES force ibs=BYTES and obs=BYTES\n\
172
+ cbs=BYTES convert BYTES bytes at a time\n\
173
+ conv=KEYWORDS convert the file as per the comma separated keyword list\n\
174
+ count=BLOCKS copy only BLOCKS input blocks\n\
175
+ ibs=BYTES read BYTES bytes at a time\n\
176
+ if=FILE read from FILE instead of stdin\n\
177
+ obs=BYTES write BYTES bytes at a time\n\
178
+ of=FILE write to FILE instead of stdout\n\
179
+ NOTE: of=FILE may be used several times to write\n\
180
+ output to multiple files simultaneously\n\
181
+ seek=BLOCKS skip BLOCKS obs-sized blocks at start of output\n\
182
+ skip=BLOCKS skip BLOCKS ibs-sized blocks at start of input\n\
183
+ pattern=HEX use the specified binary pattern as input\n\
184
+ textpattern=TEXT use repeating TEXT as input\n\
185
+ hashwindow=BYTES perform a hash on every BYTES amount of data\n\
186
+ hash=NAME either md5, sha1, sha256, sha384 or sha512\n\
187
+ default algorithm is md5. To select multiple\n\
188
+ algorithms to run simultaneously enter the names\n\
189
+ in a comma separated list\n\
190
+ hashlog=FILE send MD5 hash output to FILE instead of stderr\n\
191
+ if you are using multiple hash algorithms you\n\
192
+ can send each to a seperate file using the\n\
193
+ convention ALGORITHMlog=FILE, for example\n\
194
+ md5log=FILE1, sha1log=FILE2, etc.\n\
195
+ hashformat=FORMAT display each hashwindow according to FORMAT\n\
196
+ the hash format mini-language is described below\n\
197
+ totalhashformat=FORMAT display the total hash value according to FORMAT\n\
198
+ status=[on|off] display a continual status message on stderr\n\
199
+ default state is \"on\"\n\
200
+ statusinterval=N update the status message every N blocks\n\
201
+ default value is 256\n\
202
+ sizeprobe=[if|of] determine the size of the input or output file\n\
203
+ for use with status messages. (this option\n\
204
+ gives you a percentage indicator)\n\
205
+ WARNING: do not use this option against a\n\
206
+ tape device.\n\
207
+ split=BYTES write every BYTES amount of data to a new file\n\
208
+ This operation applies to any of=FILE that follows\n\
209
+ splitformat=TEXT the file extension format for split operation.\n\
210
+ you may use any number of 'a' or 'n' in any combo\n\
211
+ the default format is \"nnn\"\n\
212
+ NOTE: The split and splitformat options take effect\n\
213
+ only for output files specified AFTER these\n\
214
+ options appear in the command line. Likewise,\n\
215
+ you may specify these several times for\n\
216
+ for different output files within the same\n\
217
+ command line. you may use as many digits in\n\
218
+ any combination you would like.\n\
219
+ (e.g. \"anaannnaana\" would be valid, but\n\
220
+ quite insane)\n\
221
+ vf=FILE verify that FILE matches the specified input\n\
222
+ verifylog=FILE send verify results to FILE instead of stderr\n\
207
223
\n\
208
224
--help display this help and exit\n\
209
225
--version output version information and exit\n\
210
226
\n\
227
+ The structure of of FORMAT may contain any valid text and special variables.\n\
228
+ The built-in variables are used the following format: #variable_name#\n\
229
+ To pass FORMAT strings to the program from a command line, it may be\n\
230
+ necessary to surround your FORMAT strings with \"quotes.\"\n\
231
+ The built-in variables are listed below:\n\
232
+ \n\
233
+ window_start The beginning byte offset of the hashwindow\n\
234
+ window_end The ending byte offset of the hashwindow\n\
235
+ block_start The beginning block (by input blocksize) of the window\n\
236
+ block_end The ending block (by input blocksize) of the hash window\n\
237
+ hash The hash value\n\
238
+ algorithm The name of the hash algorithm\n\
239
+ \n\
240
+ For example, the default FORMAT for hashformat and totalhashformat are:\n\
241
+ hashformat=\"#window_start# - #window_end#: #hash#\"\n\
242
+ totalhashformat=\"Total (#algorithm#): #hash#\"\n\
243
+ \n\
244
+ The FORMAT structure accepts the following escape codes:\n\
245
+ \\n Newline\n\
246
+ \\t Tab\n\
247
+ \\r Carriage return\n\
248
+ \\\\ Insert the '\\' character\n\
249
+ ## Insert the '#' character as text, not a variable\n\
250
+ \n\
211
251
BLOCKS and BYTES may be followed by the following multiplicative suffixes:\n\
212
252
xM M, c 1, w 2, b 512, kD 1000, k 1024, MD 1,000,000, M 1,048,576,\n\
213
253
GD 1,000,000,000, G 1,073,741,824, and so on for T, P, E, Z, Y.\n\
@@ -529,7 +569,11 @@ static void scanargs(int argc, char **argv)
529
569
if (hash_log == NULL )
530
570
syscall_error (val );
531
571
do_hash ++ ;
532
- } else if (STREQ (name , "md5log" )) {
572
+ } else if (STREQ (name , "hashformat" ))
573
+ hashformat = parse_hashformat (val );
574
+ else if (STREQ (name , "totalhashformat" ))
575
+ totalhashformat = parse_hashformat (val );
576
+ else if (STREQ (name , "md5log" )) {
533
577
hashops [MD5 ].log = fopen (val , "w" );
534
578
if (hashops [MD5 ].log == NULL )
535
579
syscall_error (val );
@@ -609,6 +653,8 @@ static void scanargs(int argc, char **argv)
609
653
} else if (STREQ (name , "hashwindow" )) {
610
654
hash_windowlen = n ;
611
655
do_hash ++ ;
656
+ } else if (STREQ (name , "statusinterval" )) {
657
+ update_thresh = n ;
612
658
} else {
613
659
fprintf (stderr , "%s: unrecognized option %s=%s" ,
614
660
program_name , name , val );
@@ -655,6 +701,13 @@ int main(int argc, char **argv)
655
701
{
656
702
int i ;
657
703
int exit_status ;
704
+ char * def_hashwin_fmt ;
705
+ char * def_totalhash_fmt ;
706
+
707
+ def_hashwin_fmt = strndup (DEFAULT_HASHWINDOW_FORMAT ,
708
+ strlen (DEFAULT_HASHWINDOW_FORMAT ));
709
+ def_totalhash_fmt = strndup (DEFAULT_TOTALHASH_FORMAT ,
710
+ strlen (DEFAULT_TOTALHASH_FORMAT ));
658
711
659
712
/* disable buffering on stderr */
660
713
setbuf (stderr , NULL );
@@ -663,6 +716,9 @@ int main(int argc, char **argv)
663
716
verify_log = stderr ;
664
717
665
718
program_name = argv [0 ];
719
+
720
+ hashformat = parse_hashformat (def_hashwin_fmt );
721
+ totalhashformat = parse_hashformat (def_totalhash_fmt );
666
722
667
723
/* Arrange to close stdout if parse_long_options exits. */
668
724
//atexit (close_stdout_wrapper);
@@ -708,7 +764,7 @@ int main(int argc, char **argv)
708
764
else if (probe == PROBE_OUTPUT )
709
765
sizeprobe (STDOUT_FILENO );
710
766
start_time = time (NULL );
711
-
767
+
712
768
if (do_verify )
713
769
exit_status = dd_verify ();
714
770
else
0 commit comments