Discussion:
How to decompile an exe file compiled by py2exe?
Leo Jay
2005-09-24 13:29:30 UTC
Permalink
Thanks for all of your replies.

but my problem is not how to decompile .pyo or .pyc files.

i used py2exe to compile my source file `hjparser.py' into
`hjparser.exe' and other files. but i deleted the `hjparser.py' file
by misoperation.(of cause, i tried to recover, but failed)

I opened the `hjparser.exe' file in UltraEdit(a hex editor), and found
some partial statements and comments but not complete.

so, my problem is i'm sure that the source code is in `hjparser.exe'
but i don't know how to decompile the executable file `hjparser.exe'
into `hjparser.py',
i don't care about how to decompile .pyo or .pyc files.

Thanks
It is - py2exe embeds python bytecodes. It seems it does it in the
"library.zip" file (if I'm reading
http://starship.python.net/crew/theller/moin.cgi/Py2Exe correctly).
Bytecode files extracted should be decompilable to something resembling
original python code by a python decompiler (quick Googling finds
"decompyle": http://www.crazy-compilers.com/).
--
http://mail.python.org/mailman/listinfo/python-list
--
Best Regards,
Leo Jay
Leo Jay
2005-09-24 06:47:25 UTC
Permalink
Dear All,

I lost my source code because of my incaution.
so anyone can tell me how to decompile the exe file compiled by py2exe?

Thanks.

--
Best Regards,
Leo Jay
Ivan Voras
2005-09-24 11:05:20 UTC
Permalink
interpreter. This is based on the assumption that py2exe really
generates a pure exe and not an exe that interprets bytecode python.
be that the case, it may yield decent results, but ugly nontheless.
It is - py2exe embeds python bytecodes. It seems it does it in the
"library.zip" file (if I'm reading
http://starship.python.net/crew/theller/moin.cgi/Py2Exe correctly).
Bytecode files extracted should be decompilable to something resembling
original python code by a python decompiler (quick Googling finds
"decompyle": http://www.crazy-compilers.com/).
A.B., Khalid
2005-09-24 12:42:30 UTC
Permalink
Post by Leo Jay
Dear All,
I lost my source code because of my incaution.
so anyone can tell me how to decompile the exe file compiled by py2exe?
Thanks.
--
Best Regards,
Leo Jay
In older versions of py2exe (haven't tried it for new ones) I only had
to drag the py2exe created file to my zip archiever program window.
That somehow got the program to treat the py2exe application as a zip
archieve effectively decompressing it right there in the window of the
program. This enabled me to extract the files if I wish to do so to any
place I want.

This is also valid, I noted, for the binary distributions created for
windows by the distutils.
Thomas Jollans
2005-09-24 08:07:55 UTC
Permalink
Post by Leo Jay
Dear All,
I lost my source code because of my incaution.
so anyone can tell me how to decompile the exe file compiled by py2exe?
Thanks.
--
Best Regards,
Leo Jay
If you find a program that de-compiles exe to python, it will most
likely use very ugly, c-like python because a microchip is no python
interpreter. This is based on the assumption that py2exe really
generates a pure exe and not an exe that interprets bytecode python.
be that the case, it may yield decent results, but ugly nontheless.

It might better to re-write it...
John J. Lee
2005-09-25 15:06:44 UTC
Permalink
Leo Jay <python.leojay at gmail.com> writes:
[...]
Post by Leo Jay
I opened the `hjparser.exe' file in UltraEdit(a hex editor), and found
some partial statements and comments but not complete.
so, my problem is i'm sure that the source code is in `hjparser.exe'
but i don't know how to decompile the executable file `hjparser.exe'
into `hjparser.py',
[...]

Unfortunately, things we're sure of are not always true. But you
could try asking on the relevant mailing list for py2exe, making sure
to say some nice things about Thomas Heller at the same time ;-)

Personally, if the source were valuable to me, I would stop using my
hard drive immediately and pay a company to try to recover it, perhaps
making a direct copy of my HDD first using a low level copy command
like dd, so I had my other data to continue working with (though of
course, I'd hope I would have a restorable backup if it were
valuable).


John
Chris Lambacher
2005-09-26 15:43:55 UTC
Permalink
Post by Leo Jay
Thanks for all of your replies.
but my problem is not how to decompile .pyo or .pyc files.
Eventually that is what the problem will become. hjparser.exe is a python
interpreter that runs a python module that it extracts from itself. In other
words there are two steps to this. Step one is to extract the .pyc file that
is embedded in hjparser.exe. The second step is to decompile the .pyc into
something that resembles your original file.

You may have some luck determining how to extract the .pyc file by examining
the source for py2exe, either for the creation of the exe or the exe itself.

-Chris
Post by Leo Jay
i used py2exe to compile my source file `hjparser.py' into
`hjparser.exe' and other files. but i deleted the `hjparser.py' file
by misoperation.(of cause, i tried to recover, but failed)
I opened the `hjparser.exe' file in UltraEdit(a hex editor), and found
some partial statements and comments but not complete.
so, my problem is i'm sure that the source code is in `hjparser.exe'
but i don't know how to decompile the executable file `hjparser.exe'
into `hjparser.py',
i don't care about how to decompile .pyo or .pyc files.
Thanks
It is - py2exe embeds python bytecodes. It seems it does it in the
"library.zip" file (if I'm reading
http://starship.python.net/crew/theller/moin.cgi/Py2Exe correctly).
Bytecode files extracted should be decompilable to something resembling
original python code by a python decompiler (quick Googling finds
"decompyle": http://www.crazy-compilers.com/).
--
http://mail.python.org/mailman/listinfo/python-list
--
Best Regards,
Leo Jay
--
http://mail.python.org/mailman/listinfo/python-list
Jean-François Doyon
2005-09-24 13:41:00 UTC
Permalink
Last I looked, py2exe only kept the byte-compiiled versions of your
files, and not the raw source.

py2exe is just an archive, you can open it up in WinZip for example
and see your .pyc/pyo files.

That gets you part of the way there ... Then you would need to find a
way to "disassemble" the byte-code.

There's this:

http://docs.python.org/lib/module-dis.html

and

http://users.cs.cf.ac.uk/J.P.Giddy/python/decompiler/decompiler.html

for inspiration ...

Doesn't look easy though.

J.F.
Post by Leo Jay
Dear All,
I lost my source code because of my incaution.
so anyone can tell me how to decompile the exe file compiled by py2exe?
Thanks.
--
Best Regards,
Leo Jay
Peter
2005-09-24 15:39:59 UTC
Permalink
Post by Leo Jay
Thanks for all of your replies.
but my problem is not how to decompile .pyo or .pyc files.
i used py2exe to compile my source file `hjparser.py' into
`hjparser.exe' and other files. but i deleted the `hjparser.py' file
by misoperation.(of cause, i tried to recover, but failed)
Have you tried downloading a file recovery tool? e.g. something here:
http://www.pcworld.com/downloads/collection/0,collid,1295,00.asp

If you havn't, you might want to try that.
I would recommend getting one for a floppy, though, as installing a
program may overwrite the deleted data, making it nearly impossable to
recover (at least without some kind of microscope to view the markings
on the pins of your harddrive, but lets not get into that...).
Post by Leo Jay
I opened the `hjparser.exe' file in UltraEdit(a hex editor), and found
some partial statements and comments but not complete.
so, my problem is i'm sure that the source code is in `hjparser.exe'
but i don't know how to decompile the executable file `hjparser.exe'
into `hjparser.py',
Unfortuanatly i don't know how you would go about doing that.
Post by Leo Jay
i don't care about how to decompile .pyo or .pyc files.
Well, Python compiles .py into .pyc files when it runs them, so you may
have a .pyc on your computer, that you didnt delete, so you may want to
check into that, also.
Post by Leo Jay
Thanks
It is - py2exe embeds python bytecodes. It seems it does it in the
"library.zip" file (if I'm reading
http://starship.python.net/crew/theller/moin.cgi/Py2Exe correctly).
Bytecode files extracted should be decompilable to something resembling
original python code by a python decompiler (quick Googling finds
"decompyle": http://www.crazy-compilers.com/).
--
http://mail.python.org/mailman/listinfo/python-list
--
Best Regards,
Leo Jay
HTH,
Peter

Continue reading on narkive:
Loading...