mnooning has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have a rather esoteric question.

I know an expert can always find where the code exits by tracing with a hex debugger, but I am trying to hide where I exit the code at the human readable level anyway. The code snippet below works, but not if "use Tk;" is present, which it is in a number of modules the real code invokes.

I am obviously dealing with legacy code (Tk is used. ActiveState no longer supports Tk).

Is there any other way to hide an "exit;"?

How about a "die()";

use Tk; my $etriped = 'e'. 'x'. 'i'. 't'; print "1\n"; eval ("$etriped"); print "2\n"; # Reached if "use Tk;" is present.

Replies are listed 'Best First'.
Re: How to hide exit and die
by golux (Chaplain) on Jan 14, 2015 at 18:43 UTC
    Hi mnooning,

    Try "CORE::exit". For example:

    use strict; use warnings; use Tk; my $etriped = 'e' . 'x' . 'i' . 't'; print "1\n"; eval ("CORE::$etriped"); print "Error: $@\n"; print "2\n"; # Reached if "use Tk;" is present.
    say  substr+lc crypt(qw $i3 SI$),4,5
      It works! Thanks.
Re: How to hide exit and die
by Corion (Patriarch) on Jan 14, 2015 at 18:07 UTC

    Maybe Tk catches exit? You could try POSIX::exit instead.

      No, POSIX::exit did not work. golux's CORE::exit idea does though. Thanks to you both.
Re: How to hide exit and die
by QM (Parson) on Jan 15, 2015 at 14:38 UTC
    To improve your obfuscation, you could also use rot13, and undo that in the eval:
    my $etriped = 'rkvg'; $etriped =~ tr/a-zA-Z/n-za-mN-ZA-M/; eval("$etriped");

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of