我怎样才能保护我的私人funcs中对反射执行?我的、中对、反射、私人

2023-09-03 00:52:14 作者:数学给个机会

见状后:请访问修饰符影响也反映

我试图用这个,但它不工作:

我如何从执行我的私有方法prevent反思?

解决方案

如果有人能目前使用反射在你的私有方法,那么他们已经有足够的存取回避你自己的方式放置任何东西。用更少的信任运行可能是一种选择,但是这仅仅是prevent之类的插件,从有太大出入 - 它不会停止与(比如说)管理员访问中,谁可以简单地提升访问权限的用户

如果你不想code运行时,不要把它放在恶意用户的物理距离;保持在web服务或类似。任何code可用的用户可直接使用,或间接地通过反编译它(和deobfuscating它,如果需要的话)。你可以使用一些技巧,以自己的方式来获得的(通过堆栈跟踪等检查来电),但不会阻止别人来决定。

新未成年人保护法来啦 保护孩子,这件事越早做越好

After seeing this: Do access modifiers affect reflection also?

I tried using this, but it doesn't work:

How can I prevent reflection from executing my private methods?

解决方案

If someone can currently use reflection on your private methods, then they already have enough access to sidestep anything else you place in their way. Running with less trust may be an option, but that is only to prevent things like plugins from having too much access - it won't stop a user with (say) admin access to the box, who can simply elevate the access.

If you don't want code running, don't put it in physical reach of the malicious user; keep it at a web-service or similar. Any code available to a user can be used directly, or indirectly by decompiling it (and deobfuscating it if needed). You can use some tricks to get in their way (checking the caller via the stacktrace etc), but that will not stop someone determined.