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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
//! Raw `MethodDef` table structure with unresolved indexes and heap references.
//!
//! This module provides the [`crate::metadata::tables::methoddef::raw::MethodDefRaw`] struct, which represents method definitions
//! as stored in the metadata stream. The structure contains unresolved indexes
//! and heap references that require processing to establish complete method information
//! with parameter metadata and signature details.
//!
//! # Purpose
//! [`crate::metadata::tables::methoddef::raw::MethodDefRaw`] serves as the direct representation of `MethodDef` table entries from the
//! binary metadata stream, before parameter resolution and signature parsing. This raw format
//! is processed during metadata loading to create [`crate::metadata::method::Method`] instances with resolved
//! parameters and complete method implementation information.
//!
//! # Architecture
//!
//! The raw implementation provides the foundation for method definition parsing:
//! - **Unresolved References**: Contains raw heap indices and table references
//! - **Memory Efficiency**: Minimal footprint during initial parsing phases
//! - **Binary Format**: Direct representation of ECMA-335 table structure
//! - **Batch Processing**: Optimized for parsing multiple method entries efficiently
//!
//! # Binary Format
//!
//! Each `MethodDef` table row follows the ECMA-335 §22.26 specification:
//!
//! ```text
//! Offset | Size | Field | Description
//! -------|---------|------------|--------------------------------------------
//! 0x00 | 4 bytes | RVA | Relative virtual address of implementation
//! 0x04 | 2 bytes | ImplFlags | Method implementation attributes
//! 0x06 | 2 bytes | Flags | Method attributes and access modifiers
//! 0x08 | 2-4 | Name | String heap index for method name
//! 0x0A | 2-4 | Signature | Blob heap index for method signature
//! 0x0C | 2-4 | ParamList | Index into Param table for first parameter
//! ```
//!
//! # Processing Pipeline
//!
//! 1. **Binary Parsing**: Raw entries are read from metadata tables stream
//! 2. **Validation**: RVA, flags, and indices are validated for consistency
//! 3. **Resolution**: Heap indices are resolved to actual data values
//! 4. **Parameter Processing**: Parameter ranges are calculated and resolved
//! 5. **Signature Parsing**: Method signatures are parsed from blob heap
//! 6. **Conversion**: Raw entries are converted to owned method representations
//!
//! # Thread Safety
//!
//! All types in this module are thread-safe for concurrent read access:
//! - [`crate::metadata::tables::methoddef::raw::MethodDefRaw`] is [`std::marker::Send`] and [`std::marker::Sync`]
//! - Raw parsing operations can be performed concurrently
//! - Conversion methods are thread-safe with proper heap synchronization
//! - No shared mutable state during parsing operations
//!
//! # Integration
//!
//! This module integrates with:
//! - [`crate::metadata::tables::methoddef`] - Method definition module and owned representations
//! - [`crate::metadata::tables::param`] - Parameter table for method parameter resolution
//! - [`crate::metadata::method`] - Method definition types and containers
//! - [`crate::metadata::signatures`] - Method signature parsing and validation
use ;
use crate::;
/// Raw `MethodDef` table entry with unresolved indexes and heap references.
///
/// This structure represents a method definition as stored directly in the metadata stream.
/// All references are unresolved indexes or heap offsets that require processing during
/// metadata loading to establish complete method information with parameter metadata
/// and implementation details.
///
/// # Table Structure (ECMA-335 §22.26)
/// | Column | Size | Description |
/// |--------|------|-------------|
/// | RVA | 4 bytes | Relative virtual address of method implementation |
/// | `ImplFlags` | 2 bytes | Method implementation attributes |
/// | Flags | 2 bytes | Method attributes and access modifiers |
/// | Name | String index | Method name identifier |
/// | Signature | Blob index | Method signature (calling convention, parameters, return type) |
/// | `ParamList` | Param index | First parameter in the parameter list |
///
/// # Implementation Attributes (`ImplFlags`)
/// The `impl_flags` field contains method implementation characteristics:
/// - **Code type**: IL, native, OPTIL, or runtime implementation
/// - **Management**: Managed, unmanaged, or mixed execution model
/// - **Implementation**: Forward reference, synchronized, or no inlining flags
/// - **Security**: Security critical or transparent method marking
///
/// # Method Attributes (Flags)
/// The `flags` field contains method access and behavior modifiers:
/// - **Access**: Private, public, protected, internal visibility levels
/// - **Virtual dispatch**: Virtual, abstract, final, override, or new slot semantics
/// - **Special methods**: Constructor, property accessor, event handler, or operator
/// - **Calling convention**: Static, instance, or vararg method calling patterns
///
/// # Parameter Resolution
/// The `param_list` field provides access to method parameters:
/// - **Parameter range**: Contiguous range in the Param table for this method
/// - **Return parameter**: Special parameter at sequence 0 for return type information
/// - **Parameter metadata**: Names, types, default values, and custom attributes
/// - **Indirect access**: Optional `ParamPtr` table for parameter pointer indirection
///
/// # RVA and Implementation
///
/// The `rva` field specifies method implementation location:
/// - **Zero RVA**: Abstract methods, interface methods, or extern methods without implementation
/// - **Non-zero RVA**: Concrete methods with IL code or native implementation at specified address
/// - **Implementation Type**: Determined by combination of RVA and implementation flags
///
/// # Usage Patterns
///
/// ```rust,ignore
/// use dotscope::metadata::tables::methoddef::raw::MethodDefRaw;
/// use dotscope::metadata::streams::{Strings, Blob};
///
/// # fn process_method_entry(raw_entry: &MethodDefRaw, strings: &Strings, blob: &Blob) -> dotscope::Result<()> {
/// // Check method implementation type
/// if raw_entry.rva == 0 {
/// println!("Abstract or interface method: {}", raw_entry.rid);
/// } else {
/// println!("Concrete method at RVA: 0x{:08X}", raw_entry.rva);
/// }
///
/// // Access method name
/// let method_name = strings.get(raw_entry.name as usize)?;
/// println!("Method name: {}", method_name);
///
/// // Access method signature
/// let signature_data = blob.get(raw_entry.signature as usize)?;
/// println!("Signature has {} bytes", signature_data.len());
/// # Ok(())
/// # }
/// ```
///
/// # Thread Safety
///
/// [`MethodDefRaw`] is [`std::marker::Send`] and [`std::marker::Sync`] as it contains only primitive data types.
/// Instances can be safely shared across threads and accessed concurrently without synchronization.