pyarmor icon indicating copy to clipboard operation
pyarmor copied to clipboard

[BUG] obscured script can not run with cygwin python

Open shaobo-zhang-senscomm opened this issue 1 year ago • 11 comments

Reproduced steps: generate scripts with “--platform windows.x86_64 --platform linux.x86_64 --platform darwin.x86_64” parameter.

Expected results: The obscured script can run in cygwin environment, cygwin python (not windows python).

Actual results: The obscured script can not run.

  File "/home/shaobo.zhang/scm-auto-obscure/CI/pyarmor_runtime_006272/__init__.py", line 49, in __pyarmor__
    return __import__(name, globals(), locals(), ['__pyarmor__'], level=1)
ModuleNotFoundError: No module named 'pyarmor_runtime_006272.py39.windows_x86_64.pyarmor_runtime'

shaobo-zhang-senscomm avatar Jun 11 '24 07:06 shaobo-zhang-senscomm

https://github.com/dashingsoft/pyarmor/discussions/1784 This is discussion. Is there any way to rebuild pyarmor_runtime.pyd for cygwin python?

shaobo-zhang-senscomm avatar Jun 11 '24 07:06 shaobo-zhang-senscomm

Does it work to create link python39.dll in cygwin?

For example,

cd /usr/bin
# please make sure `libpython3.9.dll` exists, or it may be libpython3.9m.dll
ln -s libpython3.9.dll python39.dll

It will be solution for cygwin platform

jondy avatar Jun 12 '24 07:06 jondy

hi @jondy, it can't work with "ln -s". libpython3.9.dll looks like a specific file for cygwin.

shaobo-zhang-senscomm avatar Jun 12 '24 07:06 shaobo-zhang-senscomm

Could you show cygcheck /path/to/pyarmor_runtime.pyd after create the link?

jondy avatar Jun 12 '24 07:06 jondy

shaobo.zhang@PC-SSZ060-1 /usr/bin
$ ln -s libpython3.9.dll python39.dll

shaobo.zhang@PC-SSZ060-1 /usr/bin
$ ls | grep python
libpython3.9.dll
python
python3
python3-config
python3.9-config
python3.9.exe
python39.dll

image

shaobo-zhang-senscomm avatar Jun 12 '24 07:06 shaobo-zhang-senscomm

It seems it need rebuild the extensions for cygwin.

jondy avatar Jun 12 '24 10:06 jondy

We can not rebuild python39.dll because it may need cygwin or python development environment. Could you rebuild pyarmor_runtime.pyd?

shaobo-zhang-senscomm avatar Jun 13 '24 05:06 shaobo-zhang-senscomm

I'll rebuild pyarmor_runtime.pyd and pytransform3.pyd in this month

jondy avatar Jun 13 '24 07:06 jondy

I have built dev extensions https://pyarmor.dashingsoft.com/downloads/temp/cygwin.x86_64/libs/cp3.9/pytransform3.dll https://pyarmor.dashingsoft.com/downloads/temp/cygwin.x86_64/libs/cp3.9/pyarmor_runtime.dll

Could you verify it work by cygwin python3.9:

python3.9
>>> import pytransform3

It seems my cygwin is too old to run python3.9, so I can't verify it

jondy avatar Jun 14 '24 08:06 jondy

image pytransform3 can import, but pyarmor_runtime can't import, Is that correct ?

shaobo-zhang-senscomm avatar Jun 14 '24 09:06 shaobo-zhang-senscomm

import pyarmor_runtime directly will raise python exception, it's OK.

jondy avatar Jun 14 '24 09:06 jondy

Fixed in 8.5.10

Now there is new package pyarmor.cli.core.cygwin to support Cygwin with Python 3.7~3.9 (cygwin official download site only provides Python 3.7~3.9 packages)

jondy avatar Jul 01 '24 07:07 jondy

hi @jondy There is a cygwin_x86_64 folder under pyarmor_runtime_006272/py39. But the script does not use it, it still try to find pyarmor_runtime_006272.py39.windows_x86_64. image

shaobo-zhang-senscomm avatar Jul 09 '24 07:07 shaobo-zhang-senscomm

Try to apply this patch 425164dd836ef92bf0b3ab68958e69b034b8980e

jondy avatar Jul 09 '24 07:07 jondy

Traceback (most recent call last):
  File "/home/shaobo.zhang/scm-auto-obscure/CI/start.py", line 3, in <module>
    from pyarmor_runtime_006272 import __pyarmor__
  File "/home/shaobo.zhang/scm-auto-obscure/CI/pyarmor_runtime_006272/__init__.py", line 54, in <module>
    __pyarmor__ = __pyarmor__().__pyarmor__
  File "/home/shaobo.zhang/scm-auto-obscure/CI/pyarmor_runtime_006272/__init__.py", line 53, in __pyarmor__
    return __import__(name, globals(), locals(), ['__pyarmor__'], level=1)
RuntimeError: failed to get api PyCell_Get

shaobo-zhang-senscomm avatar Jul 09 '24 07:07 shaobo-zhang-senscomm

I'll check it.

jondy avatar Jul 10 '24 07:07 jondy

I have re-written pyarmor_runtime.dll, but it still failed

Traceback (most recent call last):
  File "/home/shaobo.zhang/scm-auto-obscure/CI/start.py", line 3, in <module>
    from pyarmor_runtime_006272 import __pyarmor__
  File "/home/shaobo.zhang/scm-auto-obscure/CI/pyarmor_runtime_006272/__init__.py", line 54, in <module>
    __pyarmor__ = __pyarmor__().__pyarmor__
  File "/home/shaobo.zhang/scm-auto-obscure/CI/pyarmor_runtime_006272/__init__.py", line 53, in __pyarmor__
    return __import__(name, globals(), locals(), ['__pyarmor__'], level=1)
ImportError: No such process

shaobo-zhang-senscomm avatar Jul 10 '24 08:07 shaobo-zhang-senscomm

I build one dev extension pyarmor_runtime, please download it and overwrite the old one in the package pyarmor/cli/core/cygwin and try it

https://pyarmor.dashingsoft.com/downloads/temp/cygwin.x86_64/libs/cp3.9/pyarmor_runtime.dll

jondy avatar Jul 10 '24 08:07 jondy

Hi @jondy, I put this pyarmor_runtime.dll into ~/miniconda3/envs/py39/lib/python3.9/site-packages/pyarmor/cli/core/cygwin/x86_64 (conda envs) and python -m pyarmor.cli -d gen, then license error. I try to register machine again. Register fail. What happen?

(py39) scm@scm-station-01:~$ pyarmor reg pyarmor-key/pyarmor-device-regfile-6272.1.zip
INFO     Python 3.9.19
INFO     Pyarmor 8.5.10 (trial), 000000, non-profits
INFO     Platform linux.x86_64
INFO     register "pyarmor-key/pyarmor-device-regfile-6272.1.zip"
INFO     machine id in group license: m7ce91077065781259273ff775547a154
INFO     got machine id: m7ce91077065781259273ff775547a154
INFO     this machine id matchs group license
INFO     This license registration information:

License Type    : pyarmor-trial
License No.     : pyarmor-vax-000000
License To      :
License Product : non-profits

BCC Mode        : No
RFT Mode        : No

Notes
* Can't obfuscate big script and mix str

I upgrade pyarmor from 8.5.x t0 8.5.10. Will the machine id change while i run pyarmor reg -g 1 ?

shaobo-zhang-senscomm avatar Jul 11 '24 02:07 shaobo-zhang-senscomm

Try to remove ~/.pyarmor/.license.token

jondy avatar Jul 11 '24 07:07 jondy

it works now, thank you very much.

shaobo-zhang-senscomm avatar Jul 12 '24 08:07 shaobo-zhang-senscomm