dotscope 0.7.0

A high-performance, cross-platform framework for analyzing and reverse engineering .NET PE executables
Documentation
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
//! `System.Exception` method hooks for .NET emulation.
//!
//! This module provides hook implementations for `System.Exception` constructors,
//! property getters, and methods commonly encountered during deobfuscation. Exception
//! objects store their state (message, inner exception, HResult, source) in synthetic
//! heap fields that don't collide with real metadata tokens.
//!
//! # Emulated Methods
//!
//! ## Constructors
//!
//! | Constructor | Behavior |
//! |------------|---------|
//! | `Exception..ctor()` | No-op (no message) |
//! | `Exception..ctor(string)` | Store message in synthetic field |
//! | `Exception..ctor(string, Exception)` | Store message + inner exception |
//!
//! ## Property Getters
//!
//! | Property | Behavior |
//! |----------|---------|
//! | `get_Message` | Read message field, fallback to empty string |
//! | `get_InnerException` | Read inner exception field, fallback to Null |
//! | `get_StackTrace` | Return empty string |
//! | `get_Source` | Read source field, fallback to empty string |
//! | `get_HResult` | Read HResult field, fallback to `COR_E_EXCEPTION` |
//! | `get_Data` | Return Null |
//! | `get_HelpLink` | Return Null |
//! | `get_TargetSite` | Return Null |
//!
//! ## Methods
//!
//! | Method | Behavior |
//! |--------|---------|
//! | `ToString` | Format as `"ExceptionType: message"` |
//! | `GetBaseException` | Walk inner exception chain, return deepest |

use crate::{
    emulation::{
        runtime::hook::{Hook, HookContext, HookManager, PreHookResult},
        thread::EmulationThread,
        tokens, EmValue,
    },
    Result,
};

/// Default HResult for `System.Exception` (`COR_E_EXCEPTION` = 0x80131500).
const COR_E_EXCEPTION: i32 = -2_146_233_088;

/// Registers all `System.Exception` method hooks.
pub fn register(manager: &HookManager) -> Result<()> {
    register_exception_type(manager, "System", "Exception")?;
    register_exception_type(manager, "System", "SystemException")?;
    register_exception_type(manager, "System", "ApplicationException")?;
    register_exception_type(manager, "System", "InvalidOperationException")?;
    register_exception_type(manager, "System", "ArgumentException")?;
    register_exception_type(manager, "System", "ArgumentNullException")?;
    register_exception_type(manager, "System", "ArgumentOutOfRangeException")?;
    register_exception_type(manager, "System", "FormatException")?;
    register_exception_type(manager, "System", "NotSupportedException")?;
    register_exception_type(manager, "System", "NotImplementedException")?;
    register_exception_type(manager, "System", "NullReferenceException")?;
    register_exception_type(manager, "System", "IndexOutOfRangeException")?;
    register_exception_type(manager, "System", "InvalidCastException")?;
    register_exception_type(manager, "System", "OverflowException")?;
    register_exception_type(manager, "System", "ArithmeticException")?;
    register_exception_type(manager, "System", "TypeInitializationException")?;
    register_exception_type(manager, "System", "ObjectDisposedException")?;
    register_exception_type(manager, "System.IO", "IOException")?;
    register_exception_type(manager, "System.IO", "FileNotFoundException")?;
    register_exception_type(manager, "System.Security", "SecurityException")?;
    register_exception_type(
        manager,
        "System.Security.Cryptography",
        "CryptographicException",
    )?;

    Ok(())
}

/// Registers constructor, property, and method hooks for an exception type.
fn register_exception_type(manager: &HookManager, namespace: &str, type_name: &str) -> Result<()> {
    let prefix = if namespace.is_empty() {
        type_name.to_string()
    } else {
        format!("{namespace}.{type_name}")
    };

    // .ctor (all overloads handled by arg count)
    manager.register(
        Hook::new(format!("{prefix}..ctor"))
            .match_name(namespace, type_name, ".ctor")
            .pre(exception_ctor_pre),
    )?;

    // Property getters — only register for base Exception since MemberRef declaring
    // type for derived types still resolves to "Exception" in metadata.
    if type_name == "Exception" {
        manager.register(
            Hook::new(format!("{prefix}.get_Message"))
                .match_name(namespace, type_name, "get_Message")
                .pre(exception_get_message_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_InnerException"))
                .match_name(namespace, type_name, "get_InnerException")
                .pre(exception_get_inner_exception_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_StackTrace"))
                .match_name(namespace, type_name, "get_StackTrace")
                .pre(exception_get_stack_trace_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_Source"))
                .match_name(namespace, type_name, "get_Source")
                .pre(exception_get_source_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_HResult"))
                .match_name(namespace, type_name, "get_HResult")
                .pre(exception_get_hresult_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_Data"))
                .match_name(namespace, type_name, "get_Data")
                .pre(|_ctx, _thread| PreHookResult::Bypass(Some(EmValue::Null))),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_HelpLink"))
                .match_name(namespace, type_name, "get_HelpLink")
                .pre(|_ctx, _thread| PreHookResult::Bypass(Some(EmValue::Null))),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.get_TargetSite"))
                .match_name(namespace, type_name, "get_TargetSite")
                .pre(|_ctx, _thread| PreHookResult::Bypass(Some(EmValue::Null))),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.ToString"))
                .match_name(namespace, type_name, "ToString")
                .pre(exception_to_string_pre),
        )?;

        manager.register(
            Hook::new(format!("{prefix}.GetBaseException"))
                .match_name(namespace, type_name, "GetBaseException")
                .pre(exception_get_base_exception_pre),
        )?;
    }

    Ok(())
}

/// Hook for `Exception..ctor()`, `Exception..ctor(string)`, `Exception..ctor(string, Exception)`.
///
/// Distinguishes overloads by argument count:
/// - 0 args: no-op
/// - 1 arg: store message
/// - 2 args: store message + inner exception
fn exception_ctor_pre(ctx: &HookContext<'_>, thread: &mut EmulationThread) -> PreHookResult {
    let Some(EmValue::ObjectRef(obj_ref)) = ctx.this else {
        return PreHookResult::Bypass(None);
    };

    let msg_field = tokens::exception_fields::MESSAGE;
    let inner_field = tokens::exception_fields::INNER_EXCEPTION;

    if let Some(message) = ctx.args.first() {
        try_hook!(thread
            .heap()
            .set_field(*obj_ref, msg_field, message.clone()));
    }

    if let Some(inner) = ctx.args.get(1) {
        try_hook!(thread
            .heap()
            .set_field(*obj_ref, inner_field, inner.clone()));
    }

    PreHookResult::Bypass(None)
}

/// Hook for `Exception.get_Message`.
fn exception_get_message_pre(ctx: &HookContext<'_>, thread: &mut EmulationThread) -> PreHookResult {
    if let Some(EmValue::ObjectRef(obj_ref)) = ctx.this {
        let field = tokens::exception_fields::MESSAGE;
        if let Ok(value) = thread.heap().get_field(*obj_ref, field) {
            return PreHookResult::Bypass(Some(value));
        }
    }
    // Fallback: allocate empty string
    if let Ok(href) = thread.heap().alloc_string("") {
        return PreHookResult::Bypass(Some(EmValue::ObjectRef(href)));
    }
    PreHookResult::Bypass(Some(EmValue::Null))
}

/// Hook for `Exception.get_InnerException`.
fn exception_get_inner_exception_pre(
    ctx: &HookContext<'_>,
    thread: &mut EmulationThread,
) -> PreHookResult {
    if let Some(EmValue::ObjectRef(obj_ref)) = ctx.this {
        let field = tokens::exception_fields::INNER_EXCEPTION;
        if let Ok(value) = thread.heap().get_field(*obj_ref, field) {
            return PreHookResult::Bypass(Some(value));
        }
    }
    PreHookResult::Bypass(Some(EmValue::Null))
}

/// Hook for `Exception.get_StackTrace` — returns empty string.
fn exception_get_stack_trace_pre(
    _ctx: &HookContext<'_>,
    thread: &mut EmulationThread,
) -> PreHookResult {
    if let Ok(href) = thread.heap().alloc_string("") {
        return PreHookResult::Bypass(Some(EmValue::ObjectRef(href)));
    }
    PreHookResult::Bypass(Some(EmValue::Null))
}

/// Hook for `Exception.get_Source`.
fn exception_get_source_pre(ctx: &HookContext<'_>, thread: &mut EmulationThread) -> PreHookResult {
    if let Some(EmValue::ObjectRef(obj_ref)) = ctx.this {
        let field = tokens::exception_fields::SOURCE;
        if let Ok(value) = thread.heap().get_field(*obj_ref, field) {
            return PreHookResult::Bypass(Some(value));
        }
    }
    if let Ok(href) = thread.heap().alloc_string("") {
        return PreHookResult::Bypass(Some(EmValue::ObjectRef(href)));
    }
    PreHookResult::Bypass(Some(EmValue::Null))
}

/// Hook for `Exception.get_HResult`.
fn exception_get_hresult_pre(ctx: &HookContext<'_>, thread: &mut EmulationThread) -> PreHookResult {
    if let Some(EmValue::ObjectRef(obj_ref)) = ctx.this {
        let field = tokens::exception_fields::HRESULT;
        if let Ok(value) = thread.heap().get_field(*obj_ref, field) {
            return PreHookResult::Bypass(Some(value));
        }
    }
    PreHookResult::Bypass(Some(EmValue::I32(COR_E_EXCEPTION)))
}

/// Hook for `Exception.ToString()`.
///
/// Formats as `"ExceptionType: message"` or just the type name if no message.
fn exception_to_string_pre(ctx: &HookContext<'_>, thread: &mut EmulationThread) -> PreHookResult {
    let type_name = ctx.type_name;
    let message = ctx.this.and_then(|this| {
        if let EmValue::ObjectRef(obj_ref) = this {
            let field = tokens::exception_fields::MESSAGE;
            thread.heap().get_field(*obj_ref, field).ok()
        } else {
            None
        }
    });

    let text = match message {
        Some(EmValue::ObjectRef(href)) => {
            if let Ok(msg) = thread.heap().get_string(href) {
                if msg.is_empty() {
                    type_name.to_string()
                } else {
                    format!("{type_name}: {msg}")
                }
            } else {
                type_name.to_string()
            }
        }
        _ => type_name.to_string(),
    };

    if let Ok(href) = thread.heap().alloc_string(&text) {
        return PreHookResult::Bypass(Some(EmValue::ObjectRef(href)));
    }
    PreHookResult::Bypass(Some(EmValue::Null))
}

/// Hook for `Exception.GetBaseException()`.
///
/// Walks the inner exception chain and returns the deepest non-null exception,
/// or `this` if there is no inner exception.
fn exception_get_base_exception_pre(
    ctx: &HookContext<'_>,
    thread: &mut EmulationThread,
) -> PreHookResult {
    let Some(EmValue::ObjectRef(obj_ref)) = ctx.this else {
        return PreHookResult::Bypass(Some(EmValue::Null));
    };

    let inner_field = tokens::exception_fields::INNER_EXCEPTION;
    let mut current = *obj_ref;

    // Walk up to 100 levels to prevent infinite loops
    for _ in 0..100 {
        match thread.heap().get_field(current, inner_field) {
            Ok(EmValue::ObjectRef(inner_ref)) => {
                current = inner_ref;
            }
            _ => break,
        }
    }

    PreHookResult::Bypass(Some(EmValue::ObjectRef(current)))
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::{
        emulation::runtime::hook::HookManager,
        metadata::{token::Token, typesystem::PointerSize},
        test::emulation::create_test_thread,
    };

    fn ctx<'a>(
        type_name: &'a str,
        method: &'a str,
        this: Option<&'a EmValue>,
        args: &'a [EmValue],
    ) -> HookContext<'a> {
        HookContext::new(
            Token::new(0x0A000001),
            "System",
            type_name,
            method,
            PointerSize::Bit64,
        )
        .with_this(this)
        .with_args(args)
    }

    fn make_exception(
        thread: &mut crate::emulation::thread::EmulationThread,
    ) -> crate::emulation::HeapRef {
        thread
            .heap_mut()
            .alloc_object(Token::new(0x7F01_0001))
            .unwrap()
    }

    #[test]
    fn test_register_hooks() {
        let manager = HookManager::new();
        super::register(&manager).unwrap();
        assert!(
            manager.len() >= 31,
            "Expected at least 31 hooks, got {}",
            manager.len()
        );
    }

    #[test]
    fn test_exception_ctor_no_args() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        let result = exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);
        assert!(matches!(result, PreHookResult::Bypass(None)));
    }

    #[test]
    fn test_exception_ctor_with_message() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        let msg = thread.heap_mut().alloc_string("test error").unwrap();

        let args = [EmValue::ObjectRef(msg)];
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &args), &mut thread);

        let result = exception_get_message_pre(
            &ctx("Exception", "get_Message", Some(&this), &[]),
            &mut thread,
        );
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "test error");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_ctor_with_message_and_inner() {
        let mut thread = create_test_thread();
        let outer = make_exception(&mut thread);
        let inner = make_exception(&mut thread);
        let outer_this = EmValue::ObjectRef(outer);
        let inner_this = EmValue::ObjectRef(inner);

        let msg = thread.heap_mut().alloc_string("outer").unwrap();
        let args = [EmValue::ObjectRef(msg), inner_this.clone()];
        exception_ctor_pre(
            &ctx("Exception", ".ctor", Some(&outer_this), &args),
            &mut thread,
        );

        let result = exception_get_inner_exception_pre(
            &ctx("Exception", "get_InnerException", Some(&outer_this), &[]),
            &mut thread,
        );
        assert!(matches!(result, PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) if r == inner));
    }

    #[test]
    fn test_exception_get_message_default() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result = exception_get_message_pre(
            &ctx("Exception", "get_Message", Some(&this), &[]),
            &mut thread,
        );
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_get_inner_exception_null() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result = exception_get_inner_exception_pre(
            &ctx("Exception", "get_InnerException", Some(&this), &[]),
            &mut thread,
        );
        assert!(matches!(result, PreHookResult::Bypass(Some(EmValue::Null))));
    }

    #[test]
    fn test_exception_get_stack_trace() {
        let mut thread = create_test_thread();
        let result = exception_get_stack_trace_pre(
            &ctx("Exception", "get_StackTrace", None, &[]),
            &mut thread,
        );
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_get_hresult_default() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result = exception_get_hresult_pre(
            &ctx("Exception", "get_HResult", Some(&this), &[]),
            &mut thread,
        );
        assert!(
            matches!(result, PreHookResult::Bypass(Some(EmValue::I32(v))) if v == COR_E_EXCEPTION)
        );
    }

    #[test]
    fn test_exception_get_source_default() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result = exception_get_source_pre(
            &ctx("Exception", "get_Source", Some(&this), &[]),
            &mut thread,
        );
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_to_string_with_message() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        let msg = thread.heap_mut().alloc_string("bad thing").unwrap();

        let args = [EmValue::ObjectRef(msg)];
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &args), &mut thread);

        let result =
            exception_to_string_pre(&ctx("Exception", "ToString", Some(&this), &[]), &mut thread);
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(
                &*thread.heap().get_string(r).unwrap(),
                "Exception: bad thing"
            );
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_to_string_no_message() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result =
            exception_to_string_pre(&ctx("Exception", "ToString", Some(&this), &[]), &mut thread);
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "Exception");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }

    #[test]
    fn test_exception_get_base_exception_no_inner() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        exception_ctor_pre(&ctx("Exception", ".ctor", Some(&this), &[]), &mut thread);

        let result = exception_get_base_exception_pre(
            &ctx("Exception", "GetBaseException", Some(&this), &[]),
            &mut thread,
        );
        assert!(matches!(result, PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) if r == obj));
    }

    #[test]
    fn test_exception_get_base_exception_chain() {
        let mut thread = create_test_thread();
        let deepest = make_exception(&mut thread);
        let middle = make_exception(&mut thread);
        let outer = make_exception(&mut thread);

        // Build chain: outer -> middle -> deepest
        let deepest_val = EmValue::ObjectRef(deepest);
        let middle_val = EmValue::ObjectRef(middle);
        let outer_val = EmValue::ObjectRef(outer);

        let msg = thread.heap_mut().alloc_string("d").unwrap();
        let args = [EmValue::ObjectRef(msg)];
        exception_ctor_pre(
            &ctx("Exception", ".ctor", Some(&deepest_val), &args),
            &mut thread,
        );

        let msg = thread.heap_mut().alloc_string("m").unwrap();
        let args = [EmValue::ObjectRef(msg), deepest_val.clone()];
        exception_ctor_pre(
            &ctx("Exception", ".ctor", Some(&middle_val), &args),
            &mut thread,
        );

        let msg = thread.heap_mut().alloc_string("o").unwrap();
        let args = [EmValue::ObjectRef(msg), middle_val.clone()];
        exception_ctor_pre(
            &ctx("Exception", ".ctor", Some(&outer_val), &args),
            &mut thread,
        );

        let result = exception_get_base_exception_pre(
            &ctx("Exception", "GetBaseException", Some(&outer_val), &[]),
            &mut thread,
        );
        assert!(
            matches!(result, PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) if r == deepest)
        );
    }

    #[test]
    fn test_derived_exception_ctor() {
        let mut thread = create_test_thread();
        let obj = make_exception(&mut thread);
        let this = EmValue::ObjectRef(obj);
        let msg = thread.heap_mut().alloc_string("param is null").unwrap();

        let args = [EmValue::ObjectRef(msg)];
        exception_ctor_pre(
            &ctx("ArgumentNullException", ".ctor", Some(&this), &args),
            &mut thread,
        );

        // Can still read message via base Exception getter
        let result = exception_get_message_pre(
            &ctx("Exception", "get_Message", Some(&this), &[]),
            &mut thread,
        );
        if let PreHookResult::Bypass(Some(EmValue::ObjectRef(r))) = result {
            assert_eq!(&*thread.heap().get_string(r).unwrap(), "param is null");
        } else {
            panic!("Expected Bypass with ObjectRef");
        }
    }
}