ObfuscationAttribute ObfuscationAttribute ObfuscationAttribute ObfuscationAttribute Class

定義

アセンブリ、型、またはメンバーに対して指定したアクションを実行するように隠ぺいツールに指示します。Instructs obfuscation tools to take the specified actions for an assembly, type, or member.

public ref class ObfuscationAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Enum | System.AttributeTargets.Method | System.AttributeTargets.Property | System.AttributeTargets.Field | System.AttributeTargets.Event | System.AttributeTargets.Interface | System.AttributeTargets.Parameter | System.AttributeTargets.Delegate, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Delegate | System.AttributeTargets.Enum | System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Parameter | System.AttributeTargets.Property | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public sealed class ObfuscationAttribute : Attribute
type ObfuscationAttribute = class
    inherit Attribute
Public NotInheritable Class ObfuscationAttribute
Inherits Attribute
継承
ObfuscationAttributeObfuscationAttributeObfuscationAttributeObfuscationAttribute
属性

次のコード例は、2 種類のパブリック アセンブリを示しています。Type1Type2します。The following code example shows a public assembly with two types: Type1 and Type2. アセンブリを難読化は設定されています、 ObfuscateAssemblyAttribute、パブリックとして扱う場合に、アセンブリがマークされます (つまり、AssemblyIsPrivateプロパティはfalse)。The assembly is marked for obfuscation with the ObfuscateAssemblyAttribute, which marks the assembly to be treated as public (that is, the AssemblyIsPrivate property is false).

Type1 アセンブリを難読化に設定されているために、難読化にマークされます。Type1 is marked for obfuscation because the assembly is marked for obfuscation. 1 つのメンバーのType1難読化から除外を使用して、Excludeプロパティ。One member of Type1 is excluded from obfuscation, using the Exclude property.

Type2 難読化から除外されますので、そのメンバーは難読化用にマークされたが、ApplyToMembersプロパティはfalseします。Type2 is excluded from obfuscation, but its members are marked for obfuscation because the ApplyToMembers property is false.

MethodAメソッドのType2値でマークされた"default"Featureプロパティ。The MethodA method of Type2 is marked with the value "default" for the Feature property. 指定する必要があるfalseExclude除外を回避するためにプロパティMethodA難読化からための既定値、ExcludeプロパティはtrueIt is necessary to specify false for the Exclude property to avoid excluding MethodA from obfuscation, because the default for the Exclude property is true. 難読化ツールは、しない、ため、難読化した後、属性を削除する必要があります、StripAfterObfuscationプロパティはfalseします。The obfuscation tool should not strip the attribute after obfuscation because the StripAfterObfuscation property is false. 難読化後にこのコード例ではその他のすべての属性が削除されたため、StripAfterObfuscationプロパティで指定されていない、既定値ためtrueします。All the other attributes in this code example are stripped after obfuscation, because the StripAfterObfuscation property is not specified, and therefore defaults to true.

コード例には、属性とそのプロパティを表示するコードが含まれます。The code example includes code to display the attributes and their properties. DLL を開くことで、属性を確認することもできます、 Ildasm.exe (IL Disassembler)します。You can also examine the attributes by opening the DLL with the Ildasm.exe (IL Disassembler).

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 = typeof(Test).Assembly;
        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
 */
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 =GetType(Test).Assembly
        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

注釈

ObfuscationAttributeObfuscateAssemblyAttribute属性に難読化ツールが処理できるようにして正しく外部の最小構成で、バイナリの注釈を付けるアセンブリの作成者を許可します。The ObfuscationAttribute and ObfuscateAssemblyAttribute attributes allow assembly authors to annotate their binaries so that obfuscation tools can process them correctly with minimal external configuration.

重要

この属性を適用することが自動的に難読化のコード エンティティを適用します。Applying this attribute does not automatically obfuscate the code entity to which you apply it. 難読化ツールの構成ファイルを作成する代わりには、属性を適用します。Applying the attribute is an alternative to creating a configuration file for the obfuscation tool. つまり、難読化ツールについてだけで提供します。That is, it merely provides instructions for an obfuscation tool. ここで説明されているセマンティクスを難読化ツールのベンダーに従うことをお勧めします。Microsoft recommends that vendors of obfuscation tools follow the semantics described here. ただし、特定のツールが Microsoft の推奨事項に従うことの保証はありません。However, there is no guarantee that a particular tool follows Microsoft recommendations.

ObfuscationAttribute属性が文字列Featureプロパティ。The ObfuscationAttribute attribute has a string Feature property. 難読化ツールは、実装する機能に、可能であれば、ユーザーがアクセスできる XML 構成ファイルを使用して、このプロパティの文字列値をマップできます。Obfuscation tools can map the string values of this property to features they implement, preferably by using an XML configuration file that users can access. ObfuscationAttribute文字列の 2 つの機能、"default"と「すべて」を定義します。The ObfuscationAttribute defines two feature strings, "default" and "all". 文字列"default"は、ツールの既定の難読化機能にマップする必要があり、「すべて」ツールでサポートされる難読化機能の完全なセットにマップする必要があります。The string "default" should map to the default obfuscation features of a tool, and "all" should map to the complete set of obfuscation features supported by a tool. 既定値、Featureプロパティが"all"難読化機能の完全なセットを有効にします。The default value of the Feature property is "all", enabling the complete set of obfuscation features.

アセンブリに適用されるときにObfuscationAttributeアセンブリ内のすべての型にも適用されます。When applied to an assembly, ObfuscationAttribute also applies to all types within the assembly. 場合、ApplyToMembersプロパティが指定されていない、またはに設定されているtrue、すべてのメンバーもに、属性が適用されます。If the ApplyToMembers property is not specified, or is set to true, the attribute applies to all members as well. ObfuscationAttribute アセンブリがパブリックかプライベートかどうかを指定しません。ObfuscationAttribute does not specify whether an assembly is public or private. アセンブリがパブリックかプライベートかどうかを指定するには、使用、ObfuscateAssemblyAttribute属性。To specify whether an assembly is public or private, use the ObfuscateAssemblyAttribute attribute.

クラスと構造体に適用するとObfuscationAttribute場合に、型のすべてのメンバーにも適用されます、ApplyToMembersプロパティが指定されていない、またはに設定されているtrueします。When applied to classes and structures, ObfuscationAttribute also applies to all members of the type if the ApplyToMembers property is not specified, or is set to true.

メソッド、パラメーター、フィールド、およびプロパティに適用する場合、属性は適用するエンティティのみに影響します。When applied to methods, parameters, fields, and properties, the attribute affects only the entity to which it is applied.

コンストラクター

ObfuscationAttribute() ObfuscationAttribute() ObfuscationAttribute() ObfuscationAttribute()

ObfuscationAttribute クラスの新しいインスタンスを初期化します。Initializes a new instance of the ObfuscationAttribute class.

プロパティ

ApplyToMembers ApplyToMembers ApplyToMembers ApplyToMembers

型の属性が型のメンバーに適用されるかどうかを示す Boolean 値を取得または設定します。Gets or sets a Boolean value indicating whether the attribute of a type is to apply to the members of the type.

Exclude Exclude Exclude Exclude

隠ぺいツールが隠ぺいから型やメンバーを除外する必要があるのかどうかを示す Boolean 値を取得または設定します。Gets or sets a Boolean value indicating whether the obfuscation tool should exclude the type or member from obfuscation.

Feature Feature Feature Feature

隠ぺいツールによって認識され、処理オプションを指定する文字列値を取得または設定します。Gets or sets a string value that is recognized by the obfuscation tool, and which specifies processing options.

StripAfterObfuscation StripAfterObfuscation StripAfterObfuscation StripAfterObfuscation

隠ぺいツールが処理後に属性を削除する必要があるかどうかを示す Boolean 値を取得または設定します。Gets or sets a Boolean value indicating whether the obfuscation tool should remove this attribute after processing.

TypeId TypeId TypeId TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用対象

こちらもご覧ください