-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdd_hack.pl
executable file
·50 lines (42 loc) · 1.13 KB
/
dd_hack.pl
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
#!/usr/bin/env perl
use warnings;
use strict;
#
# If only dd was a tiny bit more flexible.
# Alternatively, if only ddrescue was a tiny bit less rigid
#
use IO::File;
sub main() {
my $inname = shift @ARGV || die "need infile";
my $outname = shift @ARGV || die "need outfile";
my $offset = shift @ARGV || die "need offset";
my $count = shift @ARGV || die "need count";
my $in = IO::File->new($inname, O_RDONLY);
if (!defined($in)) {
warn("Could not open $inname\n");
exit(1);
}
my $out = IO::File->new($outname, O_WRONLY|O_CREAT);
if (!defined($out)) {
warn("Could not open $outname\n");
exit(1);
}
# possibly convert from hex
$offset = eval $offset;
$count = eval $count;
printf("Reading 0x%x bytes at 0x%x\n", $count, $offset);
my $errors =0;
while($count) {
$in->seek($offset,SEEK_SET);
my $c = chr(0xff);
my $r = $in->sysread($c,1);
if (!$r || $r!=1) {
$errors++;
}
$out->syswrite($c,1);
$count--;
$offset++;
}
printf("Encountered $errors errors\n");
}
main();