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.46k stars 293 forks source link

[BUG] --assert-call doesn't work correctly with context managers #1827

Closed Thoufak closed 5 months ago

Thoufak commented 5 months ago

Command

pyarmor gen test.py --assert-call

Error

Traceback (most recent call last):
  File "<frozen __main__>", line 3, in <module>
  File "<frozen test>", line 9, in <module>
RuntimeError: protection exception (16777934)

test.py file

from contextlib import contextmanager

@contextmanager
def manager():
    yield None

print("Start")

with manager():
    print("It works!")
jondy commented 5 months ago

Reproduced.

Because function manager is decorated by contextmanager, so it's not obfuscated.

I need find one solution for this case.

Thanks.

jondy commented 5 months ago

Now try to exclude it by this way

$ pyarmor cfg assert.call:excludes "manager"

Refer to https://pyarmor.readthedocs.io/en/latest/tutorial/advanced.html#filter-assert-function-and-import

It's a little complicated to auto-exclude this case, so just exclude it manually. In future, when RFT mode is refined, pyarmor may exclude this case automatically.