From: hyoon at bigfoot.com (Hoon Yoon)
Date: Fri, 16 Apr 1999 14:12:30 -0400
Subject: restore sources from PYC [Q]
References: <000101be879c$8aed0670$6eba0ac8@kuarajy.infosys.com.ar> <m3aew9njhp.fsf@atrus.jesus.cam.ac.uk>
Message-ID: <37177D8E.FF43BF65@bigfoot.com>
Content-Length: 2440
X-UID: 134                                                  

Hi,

What happens if you do NOT want your pyc codes to be reverse engineered?
Can you prevent someone from doing this type of rev eng?
Some members in my IT committee always have a problem with this ability
and often used as excuse to kill any new tech adoption.

Michael Hudson wrote:
> 
> "Bruno Mattarollo" <brunomadv at ciudad.com.ar> writes:
> > Hi!
> >
> >       By mistake I am unable to find the PY files (source) from a project I was
> > working on. I only have the PYC files... Is there a way to recover the
> > sources from the PYC? I only need my sources, I don't give a d... for the
> > comments...
> 
> Well.... The pyc files are marshalled code objects (after an eight
> byte header), and there's the standard module dis which can
> disassemble code objects, from which you could have a stab at
> rewriting your code. You certainly wouldn't *want* to do it this way.
> 
> It would probably be within the bounds of possibility to write a
> decompiler, though unless you've lost a vast heap of code this is
> going to be a much bigger project than rewriting your code.
> 
> Anyway, if it helps, here's a function that'll pull the code out of a
> .pyc file and disassemble that code:
> 
> def dis_pyc(pyc_name):
>     import marshal,dis
>     file=open(pyc_name,'rb')
>     file.read(8)
>     code=marshal.load(file)
>     did.dis(code)
> 
> (NB: This isn't much use because defined functions and classes are in
> their own code objects stored as constants - they're still accessible,
> in code.co_consts, but this code doesn't go looking for them)
> 
> >       TIA
> >
> > /B
> >
> > Bruno Mattarollo <bruno at gaiasur.com.ar>
> > ... proud to be a PSA member <http://www.python.org/psa>
> 
> Good luck!
> 
> Michael

-- 
*****************************************************************************
S. Hoon Yoon (Quant) Merrill Lynch Equity Trading, 
yelled at yahoo.com hoon at bigfoot.com(w)
"Miracle is always only few standard deviations away, but so is
catastrophe."
* Expressed opinions are often my own, but NOT my employer's.
"I feel like a fugitive from the law of averages."    Mauldin
*****************************************************************************
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vcard.vcf
Type: text/x-vcard
Size: 202 bytes
Desc: Card for Hoon Yoon
URL: <http://mail.python.org/pipermail/python-list/attachments/19990416/3699902e/attachment.vcf>


