Skip to content

Instantly share code, notes, and snippets.

@m0rb
Last active September 10, 2023 22:48
Show Gist options
  • Save m0rb/fe9969a2242410c19026626880d89224 to your computer and use it in GitHub Desktop.
Save m0rb/fe9969a2242410c19026626880d89224 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
my $header = 'RIFF';
my $sbuf = 1024;
open my $file, '<', $ARGV[0] or die $!;
binmode $file;
my $i = 0;
while (<$file>) {
seek($file, $i, 0);
my $buf;
read $file, $buf, $sbuf;
my $y = index $buf, $header;
if ($y != -1) {
$i += $y + 4;
seek $file, $i, 0;
read $file, $buf, 6;
my $size = unpack("V", $buf) + 8;
seek $file, ($i - 4), 0;
read $file, $buf, $size;
open(my $out, ">", $ARGV[1]) or die $!;
print $out $buf;
close $out;
$buf = undef;
}
$i += $sbuf - length($header);
}
close $file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment