Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Deobfuscator: the struggle for light!

by Sigmund (Pilgrim)
on Aug 22, 2001 at 17:36 UTC ( #106944=snippet: print w/replies, xml ) Need Help??
Description: please look at comments for description. maybe this is not the right place where to post, but it would be indelicate to post it in obfuscation section, and, 'cos it works and it's "warning proof" and "strict proof" i decided to post here.
i would be glad to receive help from guys interested in developing such a tool, and so,
thanks in advance.

#!/usr/bin/perl -w
# This is the first attempt to write something useful to break all tho
# wonderful pieces-of-art that obfuscated code represents. How do they
+ work?
# How can i read them more easily? Is this Reverse Engineering? I just
# started learning Perl and Obfuscation, and i wanted something to hel
+p when
# learning from others' scripts. ASCII-art-formatted scripts are reall
+y hard
# to read. this crumb of code helps a little, and I look for help to i
# it. For instance, it should detect and properly format regular expre
# which do not use regular "/" and hopefully better format loops!
# And finally, how may the "enlightenment" come from "obfuscation" ?
# Follow the light, and leave the Dark Side! ;-)
# (by the way, there's always something fascinating in darkness...
# i like obfu!!! ;-P )

use strict;
use vars '$output','$line';
$output = $ARGV[0].".deobfu";
open (INF, "< $ARGV[0]");
open (OUF, "> $output");
while (<INF>)
    $line .= $_;
    $line =~ s/\#(^\!).*\n//g;
$line =~ s/ +/ /g;
$line =~ s/\t+/\t/g;
$line =~ s/\n//g;
$line =~ s/use /\nuse /g;
$line =~ s/(qq)([\W])(\w*)([\W])/\"$3\"/g;
$line =~ s/(q)([\W])(\w*)([\W])/\'$3\'/g;
$line =~ s/\;/\;\n/g;
$line =~ s/([\{||\}])/\n$1\n/g;

print OUF $line;
close (INF);
close (OUF);
Replies are listed 'Best First'.
Re: Deobfuscator: the struggle for light!
by bikeNomad (Priest) on Aug 22, 2001 at 23:18 UTC
    You might like to look at perltidy, which is smart enough not to mess with important whitespace.
Re: Deobfuscator: the struggle for light!
by Cirollo (Friar) on Aug 22, 2001 at 22:03 UTC
    A nice effort. I think this has been tried before, but I don't know the node offhand. Maybe it was a discussion on scripts to make scripts more obfuscated instead of vice versa.

    But, remember that many obfu's depend on their whitespace, since you're blindly collapsing it down. For example, just try to run Camel Code after it's been sent through your script. Or, see what happens to Things are not what they seem like.. Test this on a few of BooK or Erudil's obfuscations and I bet they will break too.

    The best obfuscations abuse the more exotic features of the language, which makes them that much harder to deconstruct.

    Also, you might have better luck if you try to run scripts through B::Deparse, by running perl -MO=Deparse >

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://106944]
[Corion]: libpg_query
[Corion]: ... and I think "porting" it basically means (re)implementing a C preprocessor and feeding that one with the appropriate #defines for the platforms, and/or providing stub implementations for OS-specific functions that the query parser really wants to call
[erix]: ah, interesting. Well, sounds like a good start..
[Corion]: In the long run, obviously, the parser wouldn't need/call OS-specific stuff anyway, but we're a long way from that :D
[Corion]: erix: Yeah - I think basically the solution should be a "fake_os.h", which implements just enough stub routines for any OS to make the compilation of the parser pass. But for that, the complete (relevant) source code needs to be extracted, and the ...
[Corion]: ... Ruby script only extracts parts of the source code as Windows-specific files aren't considered relevant
[erix]: you got your work cut out for the hoidays :)
[erix]: +l

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2018-07-23 11:36 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (464 votes). Check out past polls.