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 は型のすべてのメンバにも適用されます。

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

使用例使用例

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

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

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

Type2MethodA メソッドは、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 クラス



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ObfuscationAttribute」の関連用語

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

   

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



ObfuscationAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2024 GRAS Group, Inc.RSS