dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.
http://pyarmor.dashingsoft.com
Other
3.43k stars 289 forks source link

Seg fault on Mac and error charmap on windows #131

Closed cypri99 closed 4 years ago

cypri99 commented 5 years ago

Hello, 4 days ago obfuscating with pyarmor was working good but now I get several errors: On MAC I get seg fault 11 after obuscating everything. I trried to run the script in anaconda and it's telling me ImportError: cannot import name (/Users/cmartini/opt/anaconda3/lib/python3.7/site-packages/scripts/init.py) So I tried to obfuscate it in Windows but I get the error ERROR 'charmap' codec can't decode byte 0x81 in position 3223: character maps to <undefined> I also tried to enable Disable advanced mode if required but I still get the same issue. My python version is 3.7.4. Thanks for your help

jondy commented 5 years ago

Specify source encode to fix codec issue in Windows, refer to https://pyarmor.readthedocs.io/en/latest/questions.html#xxx-codec-can-t-decode-byte-0xxx

About seg fault on Mac, does the command pyarmor obfuscate crash, or failed as running the obfuscated scripts? If the command obfuscate works, try to run the obfuscate script with -d, for example

python -d obf_script.py

It will show more information.

cypri99 commented 4 years ago

Hello, sorry I didn't receive the notification , but I was able to fix it with

!/usr/bin/env python

-- coding: utf-8 --

and using anaconda as an environment.

Now I'm facing other issues with pyinstaller: ImportError: cannot import name 'ImageToTextTask' from 'python3_anticaptcha' and I did specify it in my hidden imports in the main.spec file

jondy commented 4 years ago

First make sure pyinstaller could pack the script successfully, then pass these extra options by -e to pyarmor pack. For example,

pyarmor pack --clean -e " --hidden-import xxxx" main.py

Note that option --clean will overwrite the original main.spec file.

cypri99 commented 4 years ago

after doing this command I get this error

pyarmor pack --clean -e "--onefile --hidden-import beautifulsoup4 --hidden-import cloudscraper --hidden-import colorama --hidden-import coloredlogs --hidden-import dhooks --hidden-import fake_useragent --hidden-import faker --hidden-import js2py --hidden-import lxml --hidden-import names --hidden-import Brotli --hidden-import ntplib --hidden-import polling --hidden-import psutil --hidden-import python3_anticaptcha --hidden-import python_anticaptcha --hidden-import pytz --hidden-import pyyaml --hidden-import yaml --hidden-import requests --hidden-import verboselogs" main.py
Traceback (most recent call last):
  File "dist\obf\dist\main.py", line 3, in <module>
  File "<frozen main>", line 3, in <module>
RuntimeError: Check restrict mode failed
[10724] Failed to execute script main
jondy commented 4 years ago

Try to disable restrict mode like this:

pyarmor pack --clean -e " xxxxx" -x " --restrict 0" main.py
cypri99 commented 4 years ago

Still getting the same after adding -x " --restrict 0"

Traceback (most recent call last):
  File "dist\obf\dist\main.py", line 3, in <module>
  File "<frozen main>", line 3, in <module>
RuntimeError: Check restrict mode failed
[10868] Failed to execute script main
cypri99 commented 4 years ago

this is the main spec I was using earlier if it can help debug

block_cipher = None

added_files = [
         ('pyinstaller_assets/license.lic', '.'), 
         ('pyinstaller_assets/_pytransform.dll', '.'),
         ('pyinstaller_assets/pytransform.key', '.'),
         ('pyinstaller_assets/pytransform.py', '.'),
         ('config/*.txt', 'config' ),
         ('config/accounts/*.txt', 'config/accounts' ),
         ('config/log/*.txt', 'config/log' ),
         ('config/instagram/*.txt', 'config/instagram' ),
         ('config/images/*.txt', 'config/images' ),
         ('config/verification/*.txt', 'config/verification' ),
         ('static/*.py', 'static'),
         ('scripts/*.py', 'scripts'),
         ('helpers/*.py', 'helpers'),
         ('config/*.py', 'config'),
         ('config/config.yaml', 'config'),
         ('run.py', '.'),
         ]

a = Analysis(['main.py'],
             pathex=['.'],
             binaries=[],
             datas=added_files,
             hiddenimports=['beautifulsoup4', 'cloudscraper', 'colorama', 'coloredlogs', 'dhooks', 'fake_useragent', 'faker', 'js2py', 'lxml', 'names', 'ntplib', 'polling', 'psutil', 'python3_anticaptcha', 'python_anticaptcha', 'pytz', 'yaml', 'pyyaml', 'requests', 'verboselogs'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )
jondy commented 4 years ago

But it's strange that it still complaint Check restrict mode failed after restrict mode is disable. How about reboot system to make sure no cached files are used.

cypri99 commented 4 years ago

Okay I finally made it work, it was hell haha but pyinstaller doesn't find every file in site-packages from python so I had to add the pat from every packages I was using. Thanks for your help

cypri99 commented 4 years ago

hello, I'm actually still getting the error with seg fault 11 on python 3.7.4

I did try to enable line 202 in pytransform but I still get the same issue.

jondy commented 4 years ago

If pyarmor is not latest, upgrade it to latest version.

If segment fault as running pyarmor, run pyarmor with debug option -d to get more information

pyarmor -d obfuscate --recurisve foo.py
PYTHONDEBUG=y pyarmor -d obfuscate --recurisve foo.py

If segment fault as running obfuscated scripts

python -d obf_foo.py
Or
PYTHONDEBUG=y python obf_foo.py

There also will be a log file pytransform.log generated in the current path, upload it here.