Skip to content

Commit 3be005f

Browse files
committed
新增 obfuscation-instincts.md
1 parent e994136 commit 3be005f

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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"`指令。

sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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',

0 commit comments

Comments
 (0)