Have you ever walk across a junkyard, maybe it’s for cars, maybe it’s just a dump…probably not huh…and you pick up a thing or two. Heaven forbid you land on a Picasso or something, wouldn’t that be great? Come a little closer to life, maybe you’re a BMW enthusiast, and you walk in a showroom with the latest BMW gears, how are you gonna feel? Not too bad I hope. Well that kind of experience happened to me today as I browse through the web and came across a block of code.
I’ve been doing Perl for over 12 years now, and this code blew me away… This is just an extremely clever piece of code, I salute to the original author of his work because it’s genius. Sorry I won’t tell you what it does because you probably won’t appreciate it. If you know a bit about Perl, then you can read through it and please make a comment on this blog on what your guesses are.
use strict;
use warnings;
use Compress::Zlib;
++$|;
open IN, ‘test.exe’ or die $!;
binmode IN;
read IN, my $data, 1e8;
my $piecenum=0;
my $progress = progress(length $data);
my $piecedata;
for (0..length($data)-1) {
$progress->($_);
$piecedata = uncompress(”\x78\x9c” . substr $data, $_);
if (defined $piecedata) {
print “\nPiece at $_\n”;
open OUT, sprintf(’>piece_%03d.txt’, $piecenum++) or die $!; binmode OUT;
print OUT $piecedata ^ chr(0xAA) x length $piecedata;
}
}
sub progress {
my $max = $_[0];
my $last = 0;
return sub { print $last = int(100*$_[0]/$max), “%… ” if $last != int(100*$_[0]/$max) };
}
Sorry, I apologize if I just wrote a blog post about nothing to you…
- Perl Tip on check value for numeric or non-numeric
- Somethings should be left to the professionals
- Documenting All Your Properties and DRM Formulas in Seconds
- Introduction to building a financial hierarchy in DRM – Part 2
- Building Hierarchies with Automator
- Designing User Interface
- Questions and Answers
- Remote Desktop Gives Blank Screen – Fixed!
- Tracking Changes – Part I
- Oracle’s Hyperion Data Relationship Management