0

https://github.com/mono/mono/blob/master/mono/metadata/security-core-clr.cでそのコードをチェックしています。

「透過的なコードは重要なメソッドを呼び出すことができないため、指定されたメソッドをリフレクションで使用できることを確認する」ことが問題ない場合、CoreCLR は、透過的なコードがリフレクションを介して内部の透過的なメソッドまたはプロパティを呼び出すのを防ぐのはなぜですか?!

CoreCLR の詳細: http://www.mono-project.com/Moonlight2CoreCLR

/*
 * mono_security_core_clr_ensure_reflection_access_method:
 *
 *  Ensure that the specified method can be used with reflection since
 *  Transparent code cannot call Critical methods and can only call them
 *  if they are visible from it's point of view.
 *
 *  A MethodAccessException is thrown if the field is cannot be accessed.
 */
void
mono_security_core_clr_ensure_reflection_access_method (MonoMethod *method)
{
    MonoMethod *caller = get_reflection_caller ();
    /* CoreCLR restrictions applies to Transparent code/caller */
    if (mono_security_core_clr_method_level (caller, TRUE) != MONO_SECURITY_CORE_CLR_TRANSPARENT)
        return;

    if (mono_security_core_clr_get_options () & MONO_SECURITY_CORE_CLR_OPTIONS_RELAX_REFLECTION) {
        if (!mono_security_core_clr_is_platform_image (method->klass->image))
            return;
    }

    /* Transparent code cannot invoke, even using reflection, Critical code */
    if (mono_security_core_clr_method_level (method, TRUE) == MONO_SECURITY_CORE_CLR_CRITICAL) {
        mono_raise_exception (get_method_access_exception (
            "Transparent method %s cannot invoke Critical method %s.", 
            caller, method));
    }

    /* also it cannot invoke a method that is not visible from it's (caller) point of view */
    if (!check_method_access (caller, method)) {
        mono_raise_exception (get_method_access_exception (
            "Transparent method %s cannot invoke private/internal method %s.", 
            caller, method));
    }
}
4

1 に答える 1