ObfuscationAttributeとは? わかりやすく解説

ObfuscationAttribute クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

アセンブリ、型、またはメンバに対して指定したアクションを実行するように隠ぺいツールに指示します。

名前空間: System.Reflection
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class
 Or AttributeTargets.Struct Or AttributeTargets.Enum
 Or AttributeTargets.Method Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Event
 Or AttributeTargets.Interface Or AttributeTargets.Parameter Or AttributeTargets.Delegate, AllowMultiple:=True, Inherited:=False)> _
<ComVisibleAttribute(True)> _
Public NotInheritable Class
 ObfuscationAttribute
    Inherits Attribute
Dim instance As ObfuscationAttribute
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Parameter|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false)] 
[ComVisibleAttribute(true)] 
public sealed class ObfuscationAttribute :
 Attribute
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Method|AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Event|AttributeTargets::Interface|AttributeTargets::Parameter|AttributeTargets::Delegate,
 AllowMultiple=true, Inherited=false)] 
[ComVisibleAttribute(true)] 
public ref class ObfuscationAttribute sealed
 : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Parameter|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false) */ 
/** @attribute ComVisibleAttribute(true) */ 
public final class ObfuscationAttribute extends
 Attribute
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Parameter|AttributeTargets.Delegate,
 AllowMultiple=true, Inherited=false) 
ComVisibleAttribute(true) 
public final class ObfuscationAttribute extends
 Attribute
解説解説

ObfuscationAttribute 属性および ObfuscateAssemblyAttribute 属性を使用すると、アセンブリ作成者はバイナリに注釈を付けることができるため、最小の外部構成により隠ぺいツールでバイナリを正しく処理できます。

メモ重要 :

この属性を適用しても、属性を適用するコード エンティティの隠ぺいが自動的に行われるわけではありません。この属性の適用は、隠ぺいツールの構成ファイルを作成する代わりとして行われます。つまり、隠ぺいツールに対する指示を出すだけです。Microsoft では、隠ぺいツールの販売元が次に説明するセマンティクスに従うことを推奨しています。ただし、特定のツールが Microsoft の推奨するセマンティクスに従っているという保証はありません。

ObfuscationAttribute 属性には、文字列型の Feature プロパティが存在します。隠ぺいツールは、このプロパティの文字列値を、実装する機能に割り当てることができます。この割り当ては、できるだけユーザーがアクセスできる XML 構成ファイルを使用して行います。ObfuscationAttribute は、"default" と "all" という 2 つの機能文字列を定義します。文字列 "default" は、ツールの既定の隠ぺい機能に割り当て、"all" は、ツールでサポートされているすべての隠ぺい機能に割り当てる必要があります。Feature プロパティの既定値は "all" で、すべての隠ぺい機能を有効にします。

ObfuscationAttribute をアセンブリに適用すると、アセンブリ内のすべての型にも適用されます。ApplyToMembers プロパティが指定されていない場合や true に設定されている場合、属性はすべてのメンバにも適用されます。ObfuscationAttribute は、アセンブリがパブリックとプライベートのどちらであるかは指定しません。アセンブリがパブリックとプライベートのどちらであるかを指定するには、ObfuscateAssemblyAttribute 属性を使用します。

クラスおよび構造体に適用すると、ApplyToMembers プロパティが指定されていない場合や true に設定されている場合、ObfuscationAttribute は型のすべてのメンバにも適用されます。

メソッド、パラメータ、フィールド、およびプロパティに適用すると、この属性は適用対象のエンティティにのみ影響します。

使用例使用例

Type1 と Type2 という 2 つの型を使用するパブリック アセンブリのコード例を次に示します。アセンブリは ObfuscateAssemblyAttribute で隠ぺいを行うようにマークされています。これにより、アセンブリはパブリックとして処理されるようにマークされます (つまり、AssemblyIsPrivate が false です)。

アセンブリが隠ぺいを行うようにマークされているので、Type1 も隠ぺいを行うようにマークが付けられています。Exclude プロパティを使用して、Type1 の 1 つのメンバが隠ぺいから除外されています。

Type2 は隠ぺいから除外されていますが、ApplyToMembers プロパティが false であるため、そのメンバは隠ぺいを行うようにマークが付けられています。

Type2 の MethodA メソッドは、Feature プロパティの値 "default" でマークされています。Exclude プロパティの既定値が true であるため、Exclude プロパティに false を指定して、MethodA が隠ぺいから除外されないようにする必要があります。StripAfterObfuscation プロパティが false であるため、隠ぺいツールは隠ぺい後に属性を削除しません。StripAfterObfuscation プロパティが指定されておらず、そのため既定値の true に設定されているため、このコード例の他のすべての属性は隠ぺい後に削除されます。

コード例には、属性とそのプロパティを表示するコードが含まれています。MSIL 逆アセンブラ (Ildasm.exe) で DLL を開くことによって、属性を調べることもできます。

Imports System
Imports System.Reflection

' Mark this public assembly for obfuscation.
<Assembly: ObfuscateAssemblyAttribute(False)>

' This class is marked for obfuscation, because the assembly
' is marked.
Public Class Type1

    ' Exclude this method from obfuscation. The default value
    ' of the Exclude property is True, so it is not necessary
    ' to specify Exclude:=True, although spelling it out makes
    ' your intent clearer.
    <ObfuscationAttribute(Exclude:=True)> _
    Public Sub MethodA()
    End Sub

    ' This member is marked for obfuscation because the class
    ' is marked.
    Public Sub MethodB()
    End Sub

End Class

' Exclude this type from obfuscation, but do not apply that
' exclusion to members. The default value of the Exclude 
' property is True, so it is not necessary to specify 
' Exclude:=True, although spelling it out makes your intent 
' clearer.
<ObfuscationAttribute(Exclude:=True, ApplyToMembers:=False)> _
Public Class Type2

    ' The exclusion of the type is not applied to its members,
    ' however in order to mark the member with the "default"
 
    ' feature it is necessary to specify Exclude:=False,
    ' because the default value of Exclude is True. The tool
    ' should not strip this attribute after obfuscation.
    <ObfuscationAttribute(Exclude:=False, _
        Feature:="default", StripAfterObfuscation:=False)>
 _
    Public Sub MethodA()
    End Sub

    ' This member is marked for obfuscation, because the 
    ' exclusion of the type is not applied to its members.
    Public Sub MethodB()
    End Sub

End Class

' This class only exists to provide an entry point for the
' assembly and to display the attribute values.
Friend Class Test

    Public Shared Sub Main()

        ' Display the ObfuscateAssemblyAttribute properties
        ' for the assembly.        
        Dim assem As [Assembly] = Assembly.GetExecutingAssembly()
        Dim assemAttrs() As Object
 = _
            assem.GetCustomAttributes( _
                GetType(ObfuscateAssemblyAttribute), _
                False)

        For Each a As Attribute
 In assemAttrs
            ShowObfuscateAssembly(CType(a, ObfuscateAssemblyAttribute))
        Next

        ' Display the ObfuscationAttribute properties for each
        ' type that is visible to users of the assembly.
        For Each t As Type
 In assem.GetTypes()
            If t.IsVisible Then
                Dim tAttrs() As Object
 = _
                    t.GetCustomAttributes( _
                        GetType(ObfuscationAttribute), _
                        False)

                For Each a As
 Attribute In tAttrs
                    ShowObfuscation(CType(a, ObfuscationAttribute), _
                        t.Name)
                Next

                ' Display the ObfuscationAttribute properties
                ' for each member in the type.
                For Each m As
 MemberInfo In t.GetMembers()
                    Dim mAttrs() As Object
 = _
                        m.GetCustomAttributes( _
                            GetType(ObfuscationAttribute), _
                            False)

                    For Each a As
 Attribute In mAttrs
                        ShowObfuscation(CType(a, ObfuscationAttribute), _
                            t.Name & "." &
 m.Name)
                    Next
                Next
            End If
        Next
    End Sub

    Private Shared Sub ShowObfuscateAssembly(
 _
        ByVal ob As ObfuscateAssemblyAttribute)
        
        Console.WriteLine(vbCrLf & "ObfuscateAssemblyAttribute
 properties:")
        Console.WriteLine("   AssemblyIsPrivate: "
 _
            & ob.AssemblyIsPrivate)
        Console.WriteLine("   StripAfterObfuscation: "
 _
            & ob.StripAfterObfuscation)

    End Sub

    Private Shared Sub ShowObfuscation(
 _
        ByVal ob As ObfuscationAttribute, _
        ByVal target As String)
        
        Console.WriteLine(vbCrLf _
            & "ObfuscationAttribute properties for: "
 _
            & target)
        Console.WriteLine("   Exclude: " & ob.Exclude)
        Console.WriteLine("   Feature: " & ob.Feature)
        Console.WriteLine("   StripAfterObfuscation: "
 _
            & ob.StripAfterObfuscation)
        Console.WriteLine("   ApplyToMembers: " &
 ob.ApplyToMembers)

    End Sub
End Class

' This code example produces the following output:
'
'ObfuscateAssemblyAttribute properties:
'   AssemblyIsPrivate: False
'   StripAfterObfuscation: True
'
'ObfuscationAttribute properties for: Type1.MethodA
'   Exclude: True
'   Feature: all
'   StripAfterObfuscation: True
'   ApplyToMembers: True
'
'ObfuscationAttribute properties for: Type2
'   Exclude: True
'   Feature: all
'   StripAfterObfuscation: True
'   ApplyToMembers: False
'
'ObfuscationAttribute properties for: Type2.MethodA
'   Exclude: False
'   Feature: default
'   StripAfterObfuscation: False
'   ApplyToMembers: True
using System;
using System.Reflection;

// Mark this public assembly for obfuscation.
[assembly:ObfuscateAssemblyAttribute(false)]

// This class is marked for obfuscation, because the assembly
// is marked.
public class Type1
{

    // Exclude this method from obfuscation. The default value
    // of the Exclude property is true, so it is not necessary
    // to specify Exclude=True, although spelling it out makes
    // your intent clearer.
    [ObfuscationAttribute(Exclude=true)]
    public void MethodA() {}

    // This member is marked for obfuscation because the class
    // is marked.
    public void MethodB() {}
}

// Exclude this type from obfuscation, but do not apply that
// exclusion to members. The default value of the Exclude 
// property is true, so it is not necessary to specify 
// Exclude=true, although spelling it out makes your intent 
// clearer.
[ObfuscationAttribute(Exclude=true, ApplyToMembers=false)]
public class Type2
{

    // The exclusion of the type is not applied to its members,
    // however in order to mark the member with the "default"
 
    // feature it is necessary to specify Exclude=false,
    // because the default value of Exclude is true. The tool
    // should not strip this attribute after obfuscation.
    [ObfuscationAttribute(Exclude=false, Feature="default",
 
        StripAfterObfuscation=false)]
    public void MethodA() {}

    // This member is marked for obfuscation, because the 
    // exclusion of the type is not applied to its members.
    public void MethodB() {}

}

// This class only exists to provide an entry point for the
// assembly and to display the attribute values.
internal class Test
{

    public static void Main()
    {

        // Display the ObfuscateAssemblyAttribute properties
        // for the assembly.        
        Assembly assem = Assembly.GetExecutingAssembly();
        object[] assemAttrs = assem.GetCustomAttributes(
            typeof(ObfuscateAssemblyAttribute), false);

        foreach( Attribute a in assemAttrs
 )
        {
            ShowObfuscateAssembly((ObfuscateAssemblyAttribute) a);
        }

        // Display the ObfuscationAttribute properties for each
        // type that is visible to users of the assembly.
        foreach( Type t in assem.GetTypes()
 )
        {
            if (t.IsVisible)
            {
                object[] tAttrs = t.GetCustomAttributes(
                    typeof(ObfuscationAttribute), false);

                foreach( Attribute a in tAttrs
 )
                {
                    ShowObfuscation(((ObfuscationAttribute) a),
                        t.Name);
                }

                // Display the ObfuscationAttribute properties
                // for each member in the type.
                foreach( MemberInfo m in t.GetMembers()
 )
                {
                    object[] mAttrs = m.GetCustomAttributes(
                        typeof(ObfuscationAttribute), false);

                    foreach( Attribute a in
 mAttrs )
                    {
                        ShowObfuscation(((ObfuscationAttribute) a), 
                            t.Name + "." + m.Name);
                    }
                }
            }
        }
    }

    private static void
 ShowObfuscateAssembly(
        ObfuscateAssemblyAttribute ob)
    {
        Console.WriteLine("\r\nObfuscateAssemblyAttribute properties:");
        Console.WriteLine("   AssemblyIsPrivate: {0}", 
            ob.AssemblyIsPrivate);
        Console.WriteLine("   StripAfterObfuscation: {0}",
            ob.StripAfterObfuscation);
    }

    private static void
 ShowObfuscation(
        ObfuscationAttribute ob, string target)
    {
        Console.WriteLine("\r\nObfuscationAttribute properties for:
 {0}",
            target);
        Console.WriteLine("   Exclude: {0}", ob.Exclude);
        Console.WriteLine("   Feature: {0}", ob.Feature);
        Console.WriteLine("   StripAfterObfuscation: {0}",
            ob.StripAfterObfuscation);
        Console.WriteLine("   ApplyToMembers: {0}", ob.ApplyToMembers);
    }
}

/* This code example produces the following output:

ObfuscateAssemblyAttribute properties:
   AssemblyIsPrivate: False
   StripAfterObfuscation: True

ObfuscationAttribute properties for: Type1.MethodA
   Exclude: True
   Feature: all
   StripAfterObfuscation: True
   ApplyToMembers: True

ObfuscationAttribute properties for: Type2
   Exclude: True
   Feature: all
   StripAfterObfuscation: True
   ApplyToMembers: False

ObfuscationAttribute properties for: Type2.MethodA
   Exclude: False
   Feature: default
   StripAfterObfuscation: False
   ApplyToMembers: True
 */
継承階層継承階層
System.Object
   System.Attribute
    System.Reflection.ObfuscationAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ObfuscationAttribute メンバ
System.Reflection 名前空間
ObfuscateAssemblyAttribute クラス

ObfuscationAttribute コンストラクタ


ObfuscationAttribute プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

ObfuscationAttribute クラス
System.Reflection 名前空間
ObfuscateAssemblyAttribute クラス

ObfuscationAttribute メソッド


パブリック メソッドパブリック メソッド

  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
参照参照

関連項目

ObfuscationAttribute クラス
System.Reflection 名前空間
ObfuscateAssemblyAttribute クラス

ObfuscationAttribute メンバ

アセンブリ、型、またはメンバに対して指定したアクションを実行するように隠ぺいツールに指示します。

ObfuscationAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ObfuscationAttribute ObfuscationAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
参照参照

関連項目

ObfuscationAttribute クラス
System.Reflection 名前空間
ObfuscateAssemblyAttribute クラス



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ObfuscationAttribute」の関連用語

ObfuscationAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ObfuscationAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS