File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # ObfuscationInstincts
2+
3+ ` Obfuz.ObfuscationInstincts ` 类提供一些特殊函数,可以获得混淆相关的元数据信息。
4+
5+ ## Instinct 函数
6+
7+ | 函数名| 描述|
8+ | -| -|
9+ | FullNameOf| 返回某个类型混淆前的反射全名,即等价于混淆前` typeof(T).FullName ` 的返回值。如` ObfuscationInstincts.FullNameOf<cfg.Item>() ` 返回` cfg.Item ` |
10+ | NameOf| 返回某个类型混淆前的反射名,即等价于混淆前` typeof(T).Name ` 的返回值。如` ObfuscationInstincts.FullNameOf<cfg.Item>() ` 返回` Item ` |
11+
12+ Instinct函数的泛型参数不支持** 未实例化** 的泛型参数,如:
13+
14+ ``` csharp
15+
16+ class A
17+ {
18+
19+ }
20+
21+ class TestInstinct
22+ {
23+
24+ public static string GetNameBeforeObfusaction <T >()
25+ {
26+ return ObfuscationInstincts .NameOf <T >();
27+ }
28+
29+ public static void Test ()
30+ {
31+ // 正确用法
32+ // s1的值为 A
33+ var s1 = ObfuscationInstincts .NameOf <A >();
34+
35+ // 正确用法
36+ // s2的值为 List`1
37+ var s2 = ObfuscationInstincts .NameOf <List <int >>();
38+
39+ // 错误用法
40+ // s3 的值等于T,而不会是A
41+ var s3 = GetNameBeforeObfusaction <A >();
42+ }
43+ }
44+
45+
46+ ```
47+
48+ ## 实现原理
49+
50+ 在混淆的早期阶段,Obfuz会扫描代码中出现的Instinct函数,将它替换为合适的值或者代码。
51+
52+ 例如,Obfuz扫描所有函数体,如果出现` ObfuscationInstincts.NameOf<YourClass>() ` 这样的函数调用,则移除该函数调用,替换为` ldstr "YourClass" ` 指令。
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ const sidebars: SidebarsConfig = {
5555 'manual/method-body-obfuscation' ,
5656 'manual/obfuscation-pass' ,
5757 'manual/customattributes' ,
58+ 'manual/obfuscation-instincts' ,
5859 'manual/symbol-obfuscation' ,
5960 'manual/const-encryption' ,
6061 'manual/field-encryption' ,
You can’t perform that action at this time.
0 commit comments