Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I don't seem to have the time these days to do really involved obfus like I used to, but I thought it would be fun to pass along some of the neat things I've learned while writing them. Tonight's tricks illustrate some oddities you can take advantage of when naming subs, so here's a short illustration:

# a little tricky print "\ntrick one\n"; sub ::0 { print "::0 called\n" } %42->(); # a little more tricky, think about implicit return values print "\ntrick two\n"; sub :: { print ":: called\n" } sub ::1{ print "::1 called\n" } ::->(); # and think about evaluation order print "\ntrick three\n"; sub _ {print "_ called\n"} _ _ -> (); # another trick that eliminates white space in sub declarations print "\ntrick four\n"; sub'x{print "x called\n"} x;
Take special note of the '::' function, it has an odd characteristic in that it doesn't get shown by Deparse in most perl versions (or any?). That makes it a great place to hide stuff that might become too obvious under Deparse. Now, a very simple Japh that demonstrates these all use toghther:
sub _ { print "perl "; ::->() } sub :: { print "hacker\n"} sub ::1 { _ print "another "} sub ::0 { print "just " } 1->(%1->());
Of course, you have to go to greater lengths in the sub bodies than I did in the above for the output to be suprising to anyone, but I think the '1->(%1->())' line makes it suffuciently interesting to figure out.

Finally, sometimes messing with the sysbol table in this manner exposes even deeper mysteries to exploit...
Contemplate why the below causes an endless loop just by re-ordering two of the subs...
Note: May not behave the same on all perl versions. Please post your version/platform if the below does not recurse?
sub :: { print "hacker\n"} sub _ { print "perl "; ::->() } sub ::1 { _ print "another "} sub ::0 { print "just " } 1->(%1->());
Try deparsing the two versions and observing the difference.

Well, I hope this has been interesting and possibly leads some others to investigate oddities in how the symbol table behaves. If there's interest, I may post a few other interesting tricks I picked up another time.

-- So prophesied the shakespearean monkeys, and so it shall be.

In reply to old obfu tricks revealed by Felonious

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (4)
    As of 2021-02-28 20:00 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found