<?xml version="1.0" encoding="windows-1252"?>
<node id="707431" title="Deobfuscate code from vim" created="2008-08-28 05:53:26" updated="2008-08-28 01:53:26">
<type id="11">
note</type>
<author id="361638">
nferraz</author>
<data>
<field name="doctext">
Here's a small trick to deobfuscate code directly from vim, using B::Deparse. All you have to do is to put this in your vimrc:

&lt;code&gt;
    " Deparse obfuscated code
    nnoremap &lt;silent&gt; _d :.!perl -MO=Deparse 2&gt;/dev/null&lt;cr&gt;
    vnoremap &lt;silent&gt; _d :!perl -MO=Deparse 2&gt;/dev/null&lt;cr&gt;
&lt;/code&gt;

Now, whenever you want to deparse a portion of the code, just press _d. For example, this line:

&lt;code&gt;
    --$|&amp;&amp;s|\n|-|;
&lt;/code&gt;

Magically becomes:

&lt;code&gt;
    s/\n/-/ if --$|;
&lt;/code&gt;

I find this particularly useful when I have to work with code that abuses Perl's TIMTOWTDIness:

&lt;code&gt;
    $foo and $bar or $baz = 1;
&lt;/code&gt;

(Now imagine a three-lines long statement where the attribution comes at the end.)

Using B::Deparse, the code becomes more legible:

&lt;code&gt;
    $baz = 1 unless $foo and $bar;
&lt;/code&gt;

Unfortunatelly, B::Deparse has it own limitations; but I think this technique can be really useful in some situations.</field>
<field name="root_node">
540167</field>
<field name="parent_node">
540167</field>
</data>
</node>
