Esempio n. 1
0
 def decompile_dir(self, p):
     try:
         py = decompile(p)
         with io.open(p.replace(".pyc", ".py"), "w",
                      encoding="utf-8") as output_py:
             for statement in py.statements:
                 output_py.write(str(statement) + "\r")
     except Exception as ex:
         print("Failed to decompile %s" % p)
Esempio n. 2
0
def decompile_dir(rootPath):
    pattern = '*.pyc'
    for root, dirs, files in os.walk(rootPath):
        for filename in fnmatch.filter(files, pattern):
            p = str(os.path.join(root, filename))
            try:
                py = decompile(p)
                with io.open(p.replace('.pyc', '.py'), 'w') as output_py:
                    for statement in py.statements:
                        output_py.write(str(statement) + '\r')
                print(p)
            except Exception as ex:
                print("FAILED to decompile %s" % p)
Esempio n. 3
0
def decompile_file(file_path, throw_on_error=True) -> bool:
    py = decompile(file_path)
    with io.open(file_path.replace('.pyc', '.py'), 'w') as output_py:
        success = True
        for statement in py.statements:
            try:
                output_py.write(str(statement) + '\r')
            except Exception as ex:
                print('Failed to parse statement.' + str(statement))
                print(statement.__class__)
                if throw_on_error:
                    raise ex
                success = False
    return success
 def decompile_file(cls,
                    path_to_file_for_decompile: str,
                    throw_on_error: bool = False) -> bool:
     """Decompile a python file using unpyc3."""
     _replace_characters = ()
     # print('Decompiling \'{}\''.format(path_to_file_for_decompile))
     decompiled_py = decompile(path_to_file_for_decompile)
     with io.open(path_to_file_for_decompile.replace('.pyc', '.py').replace(
             '.pyo', '.py'),
                  'w',
                  encoding="utf-8") as output_py:
         success = True
         for statement in decompiled_py.statements:
             try:
                 statement_str = str(statement)
                 for replace_char in _replace_characters:
                     statement_str = statement_str.replace(
                         replace_char, '-----')
                 output_py.write(statement_str + '\r')
             except Exception as ex:
                 try:
                     statement_for_display = statement.gen_display(
                     ) if hasattr(statement, 'gen_display') else statement
                     print(
                         f'Failed to parse statement. {statement_for_display} {ex}'
                     )
                     traceback.print_exc()
                     if throw_on_error:
                         raise ex
                     success = False
                 except Exception as ex2:
                     print(f'Another error occurred! {ex} {ex2}')
                     if throw_on_error:
                         raise ex2
                     success = False
                     continue
     return success