I am decrypting a pyc file to py using uncompyle6
The python version was 3.7.7
import os
import uncompyle6
file_directory = 'E:\ABCD\EFGH'
for directory_path, b, file_names in os.walk(file_directory):
for file_name in file_names:
if not file_name.endswith('.pyc'):
continue
file_path = directory_path + '/' + file_name
original_file_name = file_name.split('.')[0]
original_file_path = directory_path + '/' + original_file_name + '.py'
with open(original_file_path, 'w') as f:
uncompyle6.decompile_file(file_path, f)
the size of .pyc file is 31 kb (PYC file available here)
But I am getting this error.
Exception in ifelsestmt '>' not supported between instances of 'str' and 'int'
rule: ifelsestmt ::= testexpr stmts jf_cfs \e_else_suite_opt \e_opt_come_from_except
offsets 7582_7584 .. 7664_0
None
File "C:\Users\hp\Anaconda3\lib\site-packages\uncompyle6\parsers\reducecheck\ifelsestmt.py", line 176, in ifelsestmt
if last_token == "COME_FROM" and tokens[first].offset > last_token.attr:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\uncompyle6\parsers\parse37base.py in reduce_is_invalid(self, rule, ast, tokens, first, last)
1204 if fn:
-> 1205 return fn(self, lhs, n, rule, ast, tokens, first, last)
1206 except:
~\Anaconda3\lib\site-packages\uncompyle6\parsers\reducecheck\ifelsestmt.py in ifelsestmt(self, lhs, n, rule, ast, tokens, first, last)
175 last_token = tokens[last]
--> 176 if last_token == "COME_FROM" and tokens[first].offset > last_token.attr:
177 if self.version < 3.0 and self.insts[self.offset2inst_index[last_token.attr]].opname != "SETUP_LOOP":
TypeError: '>' not supported between instances of 'str' and 'int'
ParserError: --- This code section failed: ---
L. 3 0 LOAD_CONST 0
2 LOAD_CONST None
4 IMPORT_NAME os
6 STORE_NAME os
L.1779 21036_21038 LOAD_CODE <code_object clear>
21040_21042 LOAD_STR 'clear'
21044 MAKE_FUNCTION_0 'Neither defaults, keyword-only args, annotations, nor closures'
21046_21048 STORE_NAME clear
L.1785 21050_21052 LOAD_NAME clear
21054 CALL_FUNCTION_0 0 ''
21056 POP_TOP
Parse error at or near `COME_FROM' instruction at offset 7664
As the PYC file can not be edited in any text editor,
How to rectify this?
with
you still get an error? could you print the output oforiginal_file_path
? I think the you mix-up the path separator:file_directory
is Windows style but forfile_path
you use a Linux style. Use theos.path.join
module to avoid cross-platform problems – cards