dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.

Home Page:http://pyarmor.dashingsoft.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] PyArmor 8 registration on VM: SystemError: <built-in function init_ctx> returned a result with an exception set

Kevin-Faeh opened this issue · comments

The registration of a PyArmor Pro license does not work on a Windows 11 VM with PyArmor V 8.5.8.
The Exception is: RuntimeError: Incorrect function. See the details below.
The registration works on a Windows 11 laptop but not on a virtual machine.
To note: the registration of an older PyArmor license with PyArmor version 7.7.4 does work without issues on the VM.

(The license id is replaced by XXXX)

$ pyarmor -d reg pyarmor-regfile-XXXX.zip
INFO     Python 3.10.10
INFO     Pyarmor 8.5.8 (trial), 000000, non-profits
INFO     Platform windows.x86_64
DEBUG    native platform windows.amd64
DEBUG    home path: C:\Users\LabAdmin\.pyarmor
INFO     register "pyarmor-regfile-XXXX.zip"
DEBUG    extracting license.lic
DEBUG    extracting .pyarmor_capsule.zip
INFO     update license token
DEBUG    unknown error, please check pyarmor.error.log
ERROR    <built-in function init_ctx> returned a result with an exception set
ERROR    something is wrong
*=============================================================*
*  Please check                                               *
*   
https://pyarmor.readthedocs.io/en/latest/questions.html
  *
*  or run `pyarmor man` to find solutions quickly             *
*                                                             *
*  It's recommand to report issue by `pyarmor man` in order   *
*  to provide necessary information, and avoid dupcliated     *
*  issues or unclear question.                                *
*=============================================================*

Content of the created error log file:

8924 MainProcess 2024-05-28 10:52:44,263
RuntimeError: Incorrect function.
 
 
The above exception was the direct cause of the following exception:
 
Traceback (most recent call last):
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\__main__.py", line 764, in main
    main_entry(sys.argv[1:])
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\__main__.py", line 752, in main_entry
    return args.func(ctx, args)
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\__main__.py", line 313, in cmd_reg
    reg.register_regfile(regfile)
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\register.py", line 210, in register_regfile
    self.update_token()
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\register.py", line 117, in update_token
    Pytransform3.init(self.ctx)
  File "C:\BA\_work\_tool\Python\3.10.10\x64\lib\site-packages\pyarmor\cli\core\__init__.py", line 100, in init
    m.init_ctx(ctx)
SystemError: <built-in function init_ctx> returned a result with an exception set

Is it possible that the init_ctx function tries to read out some machine information that are not available in the VM setup?
Thank you for your help!

First make sure this VM could visit internet
Then check the extension works by running the following command in the VM container:

python3
>>> from pyarmor.cli.core import pytransform3

If it doesn't work, make sure there is python310.dll in the dll load path.

Or check it by

dumpbin /dependents \path\to\pytransform3.pyd

Hi Jondy, thank you for your quick response!
The VM has internet access.
The extension works and pytranform3 can be imported.
Here also the output of dumbin:

(venv) PS C:\Users\LabAdmin\Downloads\test> ."C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\dumpbin.exe" /dependents "venv\Lib\site-packages\pyarmor\cli\core\pytransform3.pyd"
Microsoft (R) COFF/PE Dumper Version 14.29.30154.0
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file venv\Lib\site-packages\pyarmor\cli\core\pytransform3.pyd

File Type: DLL

  Image has the following dependencies:

    python310.dll
    ADVAPI32.dll
    IPHLPAPI.DLL
    KERNEL32.dll
    msvcrt.dll
    USER32.dll
    WS2_32.dll

  Summary

        1000 .CRT
        7000 .bss
        1000 .data
        1000 .edata
        3000 .idata
        2000 .pdata
        C000 .rdata
        1000 .reloc
       5E000 .text
        1000 .tls
        2000 .xdata

When debugging the module on the VM, I can see that the exception is raised inside the "init_ctx" function of the pytransform3 (Line 100, pyarmor\cli\core_init_.py)
The only thing that I can see is that before the init_ctx call, the ctx.license_info is the trial license, but after the init_ctx call (although it raises an exception) it contains our license. So the exception occurs after the license readout.
Is there a way how we can provide you more information?

I build new one at
https://pyarmor.dashingsoft.com/downloads/temp/windows/x86_64/py310/pytransform3.pyd

Replace VM venv\Lib\site-packages\pyarmor\cli\core\pytransform3.pyd with this one

And try it again.

This new one will be released in next version 8.5.9

Hi Jondy,

Thank you very much, this worked.
Looking forward to the next release!