pyarmor icon indicating copy to clipboard operation
pyarmor copied to clipboard

[BUG] `RuntimeError: co_info inner error` when obfuscating scripts

Open ddi98 opened this issue 3 years ago • 10 comments

hi @jondy , i tried with the following command: pyarmor gen -r C:/Users/Giuseppe/Dropbox/PROGETTI_PYCHARM/FormulariTools/app.py C:/Users/Giuseppe/Dropbox/PROGETTI_PYCHARM/FormulariTools

but the following error is returned in the pyarmor.error.log file: 18088 MainProcess 2023-04-01 11:26:50,522 Traceback (most recent call last): File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 629, in main main_entry(sys.argv[1:]) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 617, in main_entry args.func(ctx, args) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 179, in cmd_gen builder.process(options, pack=args.pack) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\generate.py", line 153, in process self._obfuscate_scripts() File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\generate.py", line 118, in obfuscate_scripts code = Pytransform3.generate_obfuscated_script(self.ctx, r) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\core_init.py", line 48, in generate_obfuscated_script return m.generate_obfuscated_script(ctx, res) File "", line 719, in generate_obfuscated_script File "", line 522, in process File "", line 522, in File "", line 1812, in handle File "", line 1807, in visit File "", line 1804, in visit File "", line 1771, in patch_co_object File "", line 1756, in _check_co_info RuntimeError: co_info inner error

ddi98 avatar Apr 01 '23 14:04 ddi98

This is some code can't handled by pyarmor v8.

Check the log, it will show last handle script, a quick workaround is ignore this script, do not obfuscate it, only obfuscate all the others, the copy plain script to final output path.

In next version, when this error occurs, pyarmor will report which script and function results in this problem.

jondy avatar Apr 02 '23 00:04 jondy

thanks for the answer @jondy, how do I set the path of a script to ignore ? and in this case which script is it?

if you explain how to do it I could exclude the venv folder from obfuscation. they are libraries that are found on the net so obfuscating them would only make the code heavier

ddi98 avatar Apr 02 '23 00:04 ddi98

Upgrade Pyarmor to 8.1.dev2, exclude a script mypkg.name.py like this

pyarmor gen --exclude mypkg.name.py mypkg/

jondy avatar Apr 03 '23 00:04 jondy

16624 MainProcess 2023-04-03 14:11:22,835 Traceback (most recent call last): File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 627, in main main_entry(sys.argv[1:]) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 615, in main_entry args.func(ctx, args) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli_main_.py", line 179, in cmd_gen builder.process(options, pack=args.pack) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\generate.py", line 145, in process Pytransform3.pre_build(self.ctx) File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\core_init_.py", line 63, in pre_build return m.pre_build(ctx) File "", line 737, in pre_build File "", line 627, in build File "", line 3054, in process File "C:\Users\Giuseppe\Dropbox\PROGETTI_PYCHARM\FormulariTools\venv\lib\site-packages\pyarmor\cli\resource.py", line 107, in reparse self.mtree = ast.parse(''.join(lines), self.frozenname, 'exec') File "C:\Python37\lib\ast.py", line 35, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 2 /shelf/ ^ SyntaxError: invalid syntax

ddi98 avatar Apr 03 '23 12:04 ddi98

If it's caused by wrong usage, please read man page to understand each options of pyarmor. https://pyarmor.readthedocs.io/en/latest/reference/man.html#pyarmor-gen

The man page is complete and show how to use all the options

If your report bug, please provide more information. Here is good example, #1068

If it's a bug, I'll fix it.

There is no private support. Pyarmor is a small tool, if you understand all the options, it's easy to use.

jondy avatar Apr 03 '23 14:04 jondy

you don't provide private support even for a fee?

ddi98 avatar Apr 03 '23 14:04 ddi98

No. I'm busy on building new platforms, full test and bug fix for Pyarmor 8.

jondy avatar Apr 03 '23 14:04 jondy

OK thanks anyway. I ask you for one kindness. could you give me a practical example of how to obfuscate multiple scripts at the same time: example pyarmor gen app.py, router.py

ddi98 avatar Apr 03 '23 14:04 ddi98

This is in the description of command gen in the man page

pyarmor gen foo.py
pyarmor gen src/mypkg
pyarmor gen -r src/mypkg
pyarmor gen -r src/pkg1 src/pkg2 libs/dbpkg
pyarmor gen -r main.py src/*.py libs/utils.py libs/dbpkg

jondy avatar Apr 03 '23 14:04 jondy

when i try to obfuscate multiple scripts in my flask project i get this error if i try to start the app Process finished with exit code -1073741819 (0xC0000005) if instead I obfuscate a single script it works without problems

ddi98 avatar Apr 03 '23 15:04 ddi98