Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #70566
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail |
|---|---|
| From | Gregory Ewing <greg.ewing@canterbury.ac.nz> |
| Newsgroups | comp.lang.python |
| Subject | Re: retrieve source code from code object as returned by compile() |
| Date | Thu, 24 Apr 2014 17:53:38 +1200 |
| Lines | 31 |
| Message-ID | <brrn75Fh59nU1@mid.individual.net> (permalink) |
| References | <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | individual.net KuOCd28ZZicfq59r9Wef5gmjcB94oxIwZMorlaGtlSOVqKoXHC |
| Cancel-Lock | sha1:VrC5H2M7yaY2fesecP8jrGAULD4= |
| User-Agent | Mozilla Thunderbird 1.0.5 (Macintosh/20050711) |
| X-Accept-Language | en-us, en |
| In-Reply-To | <4dfca89b-82c6-42f4-aedb-2fe82a7f7dc1@googlegroups.com> |
| Xref | csiph.com comp.lang.python:70566 |
Show key headers only | View raw
Justin Ezequiel wrote:
> Using "Easy Python Decompiler" I am able to get the source for the imported
> modules. Using "Resources Viewer" from PlexData and some code I am able to
> retrieve the code object. I am however stumped as to how to retrieve the
> source from this code object.
Easy Python Decompiler should be able to do that, but you
may need to delve into its innards a bit to find an entry
point where you can feed in a code object.
Alternatively you could create a .pyc file out of the code
object and then use Easy Python Decompiler on that. The
following snippet of code should do that:
import marshal
import py_compile
import time
with open('output.pyc', 'wb') as fc:
fc.write('\0\0\0\0')
py_compile.wr_long(fc, long(time.time()))
marshal.dump(codeobject, fc)
fc.flush()
fc.seek(0, 0)
fc.write(py_compile.MAGIC)
(Taken from:
http://stackoverflow.com/questions/8627835/generate-pyc-from-python-ast)
--
Greg
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
retrieve source code from code object as returned by compile() Justin Ezequiel <justin.ezequiel@gmail.com> - 2014-04-23 17:58 -0700
Re: retrieve source code from code object as returned by compile() Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-24 17:53 +1200
Re: retrieve source code from code object as returned by compile() Justin Ezequiel <justin.ezequiel@gmail.com> - 2014-04-24 19:50 -0700
Re: retrieve source code from code object as returned by compile() Amirouche Boubekki <amirouche.boubekki@gmail.com> - 2014-04-25 18:34 +0200
Re: retrieve source code from code object as returned by compile() Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-04-26 12:03 +1200
csiph-web