Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to decompile perl bytecode from perlcc -B?

Tags:

perl

I want to decompile the bytecode with deparse, then I failed. I do the following test:(perl 5.8.9)

1) make a file named t.pl with single line

    print 1;

2) compile to get plc file

    $ perl -MO=Bytecode,-H,-ot.plc t.pl

3) try to decompile

    $ perl -MO=Deparse t.plc
    use ByteLoader 0.06;
    t.plc syntax OK

4) use Concise module $ perl -MO=Concise,-exec t.plc

1  <0> enter 
2  <;> nextstate(main 174 y.pl:1) v
3  <0> pushmark s
4  <$> const(IV 1) s
5  <@> print vK
6  <@> leave[1 ref] vKP/REFC
y.plc syntax OK

with this method, we can got some valuable info, but it is hard to read.

I can not get the source code. I have searched the web, it seems that Deparse module can deparse the perlcc -B produced file.

Any idea? Thanks

refers:

http://ask.slashdot.org/story/05/11/11/0129250/protecting-perl-code

like image 848
deperl Avatar asked Nov 13 '22 10:11

deperl


1 Answers

The reason this doesn't work the obvious way is because of how Bytecode is stored. Deparse needs there to be a tree of OPs, but B::Bytecode just stores the ops in exec order without constructing the tree. It's possible to thread the op tree after Bytecode.pm constructs it, by messing about with the PL_main_root and PL_main_start pointers and then calling newPROG on them.

In short, it can be done, but not with the standard tools. You'd have to write a something to do it, and that would require a bit of a knowledge of the Perl guts.

like image 124
Simon Cozens Avatar answered Nov 15 '22 05:11

Simon Cozens