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.45k stars 291 forks source link

Restrict Mode Examples? #280

Closed VeNoMouS closed 4 years ago

VeNoMouS commented 4 years ago

Hi @jondy,

I know your pretty busy resolving the issues that came about with 6.3.0, I was just wondering if i could get some clear proper examples of how to use the restrict modes..

What im trying to do

if i have a dir

__init__.py
packer.py

I want __init__.py to be import-able with restrict 1, but how do i then also have packer.py restrict 3 so it cant be imported outside of the __init__.py?

You doc doesn't cover proper examples things like this, it just doesn't make it clear enough , sorry

jondy commented 4 years ago

This should not be problem because the restrict mode isn't violated by the obfuscated scripts normally. Once restrict mode is violated, it may result in segmentation fault.

VeNoMouS commented 4 years ago

idealy what id love to see also happen is on restricted modules... __all__ , __getattr__ etc to be blocked, as doing it manually is tedious

ideally would love to see that automatically embedded , not just blocking on function execution

or my preference of choice... the module blocked completely from being loaded in the first place if restricted mode 4 etc... that way if you have ie config.py with variable data, you won't get any leakage ....

since you still load a restricted module... then just module.__dict__ to see the vars and values

jondy commented 4 years ago

It's complex to protect module attribute, I'll first check the source of CPython.

jondy commented 4 years ago

Found solution, please upgrade to v6.3.7. From this version the plain script couldn't visit any module attribute if this module is obfuscated with restrict mode 2, 3 or 4

VeNoMouS commented 4 years ago

omg ❤️ that is awesome, will upgrade and do my own tests, thanks @jondy

I ended up having to put my own __dir__ , __all__ , __dict__ etc and some other techniques i dont want to discuss openly ;P just stop that kinda stuff, so will be good not have to that myself ❤️

i'll let you know if i find any issues

VeNoMouS commented 4 years ago

Initial testing looks really good @jondy