|
|
|
| Rit.pl - Restore Interpreted Tabulation of a Bleached Program | |
One of the more interesting problems I faced with this program was how to deal with the licensing, since my program is clearly based on Damian's original Bleach.pm. I found that Damian's Bleach.pm module uses the Artistic License, which has this statement:
3.You may otherwise modify your copy of this Package in any way, provided that you insert a prominent
notice in each changed file stating how and when you changed that file, and provided that you do at least
ONE of the following:
a.place your modifications in the Public Domain or otherwise make them Freely Available, such as by
posting said modifications to Usenet or an equivalent medium, or placing the modifications on a
major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your
modifications in the Standard Version of the Package.
So I figured that I can put this code here as long as I make my program
Freely Available under the Artistic License. Feel free to contact me if
you think I got this wrong.Here is my code:
#!/usr/bin/perl
#
# Program to restore a bleached Perl program.
#
# Copyright (c) 2001, Tom Anderson. All Rights Reserved.
# This module is free software. It may be used, redistributed
# and/or modified under the terms of the Perl Artistic License
# (see http://www.perl.com/perl/misc/Artistic.html)
#
# Based on Bleach.pm, Copyright (c) 2001, Damian Conway
# This program is available at http://tomacorp.com/perl/rit/index.html
#
use Getopt::Std;
getopt('f:');
our $opt_f;
if ($opt_f eq "")
{
print "Usage: Rit.pl -f bleached_code.pl\n";
exit
}
open(FN, $opt_f) or die "Can't open $opt_f";
my $tie = " \t"x8;
sub whiten { local $_ = unpack "b*", pop; tr/01/ \t/; s/(.{9})/$1\n/g; $tie.$_ }
sub brighten { local $_ = pop; s/^$tie|[^ \t]//g; tr/ \t/01/; pack "b*", $_}
sub dirty { $_[0] =~ /\S/ }
sub dress { $_[0] =~ /^$tie/ }
(my $shirt = join "", ) =~ s/.*^\s*use\s+Bleach\s*;\n//sm;
print brighten $shirt;
To see what this program is good for, first get Bleach.pm from CPAN and try it out. After using Bleach.pm in a small test program, examine the source code of your program. It will have been changed in a way that hides the source code. Rit.pl restores the hidden source code to its former visibility. I wrote Rit.pl because I like the bleach module, but I feared that I might accidentally lose some source code when I used it. I thought to myself, "I should delete this from my system. But I how can I bear to delete Damian's code?" So I wrote Rit.pl to make the effects of Bleach.pm reversible.
To write this program I traced the execution of Bleach.pm with the excellent ptkdb perl debugger, and found a critical spot in the code where I could insert a print statement to make the program do almost exactly what I wanted. With a little more effort I had Rit.pl.
Using the debugger this way is a generally useful technique for adding functionality to perl programs, especially ones that you don't understand.
![]()