R
Rafal Konopka
I need to search and replace some strings in a binary file. When I try
something like this the code below, it works fine. The thing is that
I'll need to use replacements that have more or fewer characters (like
150 replaced with 20, etc. I know it requires some hairy bitwise
shifts but I have no idea how to do it.
TIA,
Rafal
&edit_up('myfile');
sub edit_up {
my ($infile) = @_;
undef $/;
open(F,$infile) || die "$infile: $!";
binmode(F);
my $OUT = "test\\";
if (!-d $OUT) {mkdir($OUT,07770);}
open(OF,">$OUT" . $infile);
binmode(OF);
while (read(F, $buf, 1024)) {
$buf =~ s/\[150\]/[100]/g;
print OF $buf;
}
close(F);
close(OF);
}
something like this the code below, it works fine. The thing is that
I'll need to use replacements that have more or fewer characters (like
150 replaced with 20, etc. I know it requires some hairy bitwise
shifts but I have no idea how to do it.
TIA,
Rafal
&edit_up('myfile');
sub edit_up {
my ($infile) = @_;
undef $/;
open(F,$infile) || die "$infile: $!";
binmode(F);
my $OUT = "test\\";
if (!-d $OUT) {mkdir($OUT,07770);}
open(OF,">$OUT" . $infile);
binmode(OF);
while (read(F, $buf, 1024)) {
$buf =~ s/\[150\]/[100]/g;
print OF $buf;
}
close(F);
close(OF);
}