1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//! `System.Reflection` method hooks for the CIL emulator.
//!
//! This module provides comprehensive hook implementations for the .NET reflection
//! subsystem, enabling the emulator to handle runtime type inspection, member lookup,
//! dynamic method invocation, and assembly/module metadata queries. These capabilities
//! are essential for deobfuscation analysis because obfuscators use reflection
//! extensively to hide control flow and data dependencies from static analysis.
//!
//! # Module Organization
//!
//! The reflection hooks are split across four submodules by functional area:
//!
//! | Module | Description |
//! |--------|-------------|
//! | [`types`] | `System.Type` properties and methods, `Object.GetType`, `Activator`, delegates, custom attributes |
//! | [`methods`] | `MethodBase`/`MethodInfo` invocation and metadata, `DynamicMethod`/`ILGenerator` |
//! | [`members`] | `FieldInfo`, `PropertyInfo`, `ParameterInfo`, and `MemberInfo` operations |
//! | [`modules`] | `Module`, `Assembly`, `ModuleHandle`, `Debugger`, `StackFrame` |
//!
//! Shared helper functions used across submodules (e.g., token extraction, type
//! normalization, value boxing/unboxing) are defined in [`helpers`] and
//! re-exported as `pub(crate)`.
//!
//! # Deobfuscation Use Cases
//!
//! ## Dynamic Method Resolution
//!
//! ```csharp
//! // Common obfuscation pattern — encrypted token resolved at runtime
//! Module mod = typeof(Program).Module;
//! MethodBase method = mod.ResolveMethod(encryptedToken ^ key);
//! method.Invoke(null, new object[] { args });
//! ```
//!
//! ## Type-Based Dispatch
//!
//! ```csharp
//! // CFF state machine querying type metadata
//! Type t = Type.GetTypeFromHandle(handle);
//! MethodInfo decrypt = t.GetMethod("Decrypt");
//! string result = (string)decrypt.Invoke(null, new object[] { data });
//! ```
//!
//! ## Delegate Proxy Construction
//!
//! ```csharp
//! // DynamicMethod-based delegate proxy (e.g., ConfuserEx reference proxy)
//! var dm = new DynamicMethod("proxy", returnType, paramTypes, module, true);
//! var il = dm.GetILGenerator();
//! il.Emit(OpCodes.Ldarg_0);
//! il.Emit(OpCodes.Call, targetMethodInfo);
//! il.Emit(OpCodes.Ret);
//! var del = dm.CreateDelegate(delegateType);
//! ```
//!
//! # Hook Registration
//!
//! All 120 hooks are registered by the [`register`] function, which delegates to
//! qualified paths in the submodules (e.g., `types::type_get_method_pre`).
//!
//! # Limitations
//!
//! - All returned reflection objects are **symbolic** (fake tokens on the heap)
//! - `Invoke` dispatches to the emulator's method execution, not real .NET execution
//! - Field values come from the emulator's heap/static storage, not real memory
//! - Method resolution does not validate generic constraints
pub use ;
use crate::;
/// Hook for object reference equality comparison (`op_Equality`).
///
/// Used for `MethodBase.op_Equality`, `MethodInfo.op_Equality`, `Assembly.op_Equality`,
/// and similar reference-type comparison operators. Compares by heap reference identity:
/// two non-null references are equal iff they point to the same heap object.
pub
/// Hook for object reference inequality comparison (`op_Inequality`).
///
/// Used for `MethodBase.op_Inequality`, `MethodInfo.op_Inequality`, `Assembly.op_Inequality`,
/// and similar reference-type comparison operators.
pub
/// Registers all reflection method hooks with the given hook manager.
///
/// Delegates to each submodule's `register()` function to install the complete
/// set of reflection hooks. See module documentation for the full list of
/// 120 hooks covering `Type`, `MethodBase`, `FieldInfo`, `PropertyInfo`,
/// `Module`, `Assembly`, `DynamicMethod`, delegates, and diagnostics.
///
/// # Arguments
///
/// * `manager` - The [`HookManager`] to register hooks with