in reply to Randomly mangle a binary file
You don't have to read the whole file just to modify three bytes:
#!/usr/bin/perl use strict; use warnings; use Fcntl ':seek'; die "Usage: $0 file\n" unless @ARGV == 1; my $fn = shift; my $LEN = 3; open my $fh, '+<:raw', $fn or die "$fn: D'Oh! $!\n"; my $offset = rand( -$LEN + -s $fh ); seek $fh, $offset, SEEK_SET or die "$fn: D'Oh! $!\n"; read $fh, my $cont, $LEN; seek $fh, $offset, SEEK_SET or die "$fn: D'Oh! $!\n"; print $fh $cont ^ join '', map chr( rand 0x100 ), 1 .. $LEN; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Randomly mangle a binary file
by blazar (Canon) on Sep 01, 2008 at 13:04 UTC |