Skip to content

Commit

Permalink
Added extra py2exe executable check.
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasb committed Apr 6, 2018
1 parent 8a7d937 commit 06d8493
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
11 changes: 9 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from distutils.core import setup
from setuptools import setup


with open('README.md') as f:
long_description = f.read()


setup(
name='unpy2exe',
version='0.3',
version='0.4',
description='Extract pyc files from py2exe executable.',
long_description=long_description,
long_description_content_type='text/markdown',
keywords=['py2exe', 'pyc', 'extract'],
author='Matias Bordese',
author_email='mbordese@gmail.com',
Expand Down
23 changes: 20 additions & 3 deletions unpy2exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,20 @@ def _get_co_from_dump(data):
return code_objects


def extract_code_objects(filename):
def check_py2exe_file(pe):
"""Check file is a py2exe executable."""
py2exe_resource = _get_scripts_resource(pe)

if py2exe_resource is None:
logging.info('This is not a py2exe executable.')
if pe.__data__.find(b'pyi-windows-manifest-filename'):
logging.info('This seems a pyinstaller executable (unsupported).')

return bool(py2exe_resource)


def extract_code_objects(pe):
"""Extract Python code objects from a py2exe executable."""
pe = pefile.PE(filename)
script_res = _get_scripts_resource(pe)
dump = _resource_dump(pe, script_res)
return _get_co_from_dump(dump)
Expand Down Expand Up @@ -157,6 +168,12 @@ def unpy2exe(filename, python_version=None, output_dir=None):
elif not os.path.exists(output_dir):
os.makedirs(output_dir)

code_objects = extract_code_objects(filename)
pe = pefile.PE(filename)

is_py2exe = check_py2exe_file(pe)
if not is_py2exe:
raise ValueError('Not a py2exe executable.')

code_objects = extract_code_objects(pe)
for co in code_objects:
dump_to_pyc(co, python_version, output_dir)

0 comments on commit 06d8493

Please sign in to comment.