Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl - Opcode to source code?

Is there a way to create perl source code, if I have the opcode?

For example

perl -MO=Concise -e "print 123"

will output the opcode:

6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 -e:1) v:{ ->3
5     <@> print vK ->6
3        <0> pushmark s ->4
4        <$> const[IV 123] s ->5

I would like to reverse this somehow.

like image 871
Blub Avatar asked Dec 23 '14 22:12

Blub


1 Answers

If by "have the opcode", you mean "have the opcode tree"

While B::Concise tries to give an accurate representation of the opcode tree, B::Deparse takes the opcode tree and produces source code from it.

$ perl -MO=Deparse -e'$x && print'
print $_ if $x;
-e syntax OK

It's quite good, though there are some limitations.

If by "have the opcode", you mean "have the output of B::Concise"

Given that B::Concise tries to be very complete, it might be possible, but I think some information is missing. I'm pretty sure there's nothing that tries to do this on CPAN, since I've never heard of blead breaking it (something you would expect to happen regularly).

like image 152
ikegami Avatar answered Nov 09 '22 08:11

ikegami