[BUG] `ERROR AST node column range (0, 43) for line range (-995, -994) is not valid`
error log
The error came up during obfuscating with hooks for python 3.12.4. Got:
$ pyarmor -d gen -O obf main.py
INFO Python 3.12.4
INFO Pyarmor 8.5.9 (trial), 000000, non-profits
INFO Platform linux.x86_64
DEBUG native platform linux.x86_64
DEBUG home path: /home/ubuntu/.pyarmor
DEBUG command options: {'output': 'obf', 'no_runtime': False, 'inputs': ['main.py']}
DEBUG install plugin: CodesignPlugin
DEBUG install plugin: DarwinUniversalPlugin
INFO search inputs ...
INFO find script main.py
INFO find 1 top resources
INFO start to generate runtime files
INFO target platforms {'linux.x86_64'}
DEBUG got /usr/local/lib/python3.12/site-packages/pyarmor/cli/core/pyarmor_runtime.so
INFO write obf/pyarmor_runtime_000000/pyarmor_runtime.so
DEBUG patching runtime data at 772480
DEBUG patch runtime file OK
DEBUG call post runtime plugin <class 'pyarmor.cli.plugin.CodesignPlugin'>
INFO generate runtime files OK
INFO start to obfuscate scripts
INFO process resource "main"
INFO obfuscating file main.py
DEBUG process inline marker
DEBUG parse script
DEBUG process co
DEBUG install runtime hook
DEBUG unknown error, please check pyarmor.error.log
ERROR AST node column range (0, 43) for line range (-995, -994) is not valid
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. *
*=============================================================*
project content
for project like this:
$ tree -a
.
├── .pyarmor
│ └── hooks
│ └── main.py
├── main.py
└── obf
containing following files:
# main.py
if __name__ == '__main__':
print(f'Hello world.')
#./.pyarmor/hooks/main.py
from pyarmor_runtime_000000 import __pyarmor__
def _pyarmor_check_worldtime(host, path):
from http.client import HTTPSConnection
expire = __pyarmor__(1, None, b'keyinfo', 1)
conn = HTTPSConnection(host)
conn.request("GET", path)
res = conn.getresponse()
if res.code == 200:
data = res.read()
s = data.find(b'"unixtime":')
n = data.find(b',', s)
current = int(data[s + 11:n])
if current > expire:
raise RuntimeError('license is expired')
else:
raise RuntimeError('got network time failed')
_pyarmor_check_worldtime('worldtimeapi.org', '/api/timezone/Europe/Paris')
detailed err log
# pyarmor.error.log
76 MainProcess 2024-06-21 09:03:10,891
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/__main__.py", line 764, in main
main_entry(sys.argv[1:])
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/__main__.py", line 752, in main_entry
return args.func(ctx, args)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/__main__.py", line 244, in cmd_gen
builder.process(options)
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/generate.py", line 191, in process
self._obfuscate_scripts()
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/generate.py", line 144, in _obfuscate_scripts
code = self._generate_obfuscated_script(r)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/generate.py", line 104, in _generate_obfuscated_script
return Pytransform3.generate_obfuscated_script(self.ctx, res)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/core/__init__.py", line 89, in generate_obfuscated_script
return m.generate_obfuscated_script(ctx, res)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<maker>", line 713, in generate_obfuscated_script
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/__init__.py", line 16, in process
return meth(self, res, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<maker>", line 535, in process
File "/usr/local/lib/python3.12/site-packages/pyarmor/cli/resource.py", line 158, in recompile
self.mco = compile(mtree, self.frozenname, 'exec', optimize=optimize)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: AST node column range (0, 53) for line range (-997, -983) is not valid
what works
obfuscating works for dummy hook like this
print('hook')
pyarmor man
pyarmor man does not work
ubuntu@3f54636d3814:~/workspace$ pyarmor man
INFO Python 3.12.4
INFO Pyarmor 8.5.9 (trial), 000000, non-profits
INFO Platform linux.x86_64
ERROR No module named 'pyarmor.man'
ERROR something is wrong
*=============================================================*
* Please enable debug option `-d` to run it again *
* pyarmor -d gen options ... *
* *
* Then check console log to find more information *
* *
* Please also check *
* https://pyarmor.readthedocs.io/en/latest/questions.html *
* or run `pyarmor man` to find solutions quickly *
*=============================================================*
ubuntu@3f54636d3814:~/workspace$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ubuntu/.local/bin
ubuntu@3f54636d3814:~/workspace$ ls -la /home/ubuntu/.local/bin
total 12
drwxr-xr-x 2 ubuntu ubuntu 4096 Jun 21 09:17 .
drwxr-xr-x 4 ubuntu ubuntu 4096 Jun 21 09:17 ..
-rwxr-xr-x 1 ubuntu ubuntu 213 Jun 21 09:17 pyarmor-man
Please debug hook script ./.pyarmor/hooks/main.py as normal script, make sure it could be compiled by Python interpreter.
This script cames from pyarmor documentation
https://pyarmor.readthedocs.io/en/latest/tutorial/customization.html#using-hook-to-check-network-time-by-other-service
Anyway I got same error using below hook. Which works when used as plain script.
import os
from datetime import datetime
directory = "/tmp"
filepath = os.path.join(directory, str(datetime.now().strftime('%Y-%m-%d')))
with open(filepath, 'w') as file:
pass
print(f"Empty file created: {filepath}")
Reproduced in Python 3.11+, it will be fixed in next release.
Here is pre-release https://pyarmor.dashingsoft.com/downloads/temp/pyarmor-8.5.10.zip
Fixed in 8.5.10