ObfuscationAttribute 클래스

정의

어셈블리, 형식 또는 멤버에 대해 지정된 동작을 수행하도록 난독 처리 도구를 설정합니다.

public ref class ObfuscationAttribute sealed : Attribute
[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
public sealed class ObfuscationAttribute : Attribute
[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)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class ObfuscationAttribute : Attribute
[<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)>]
type ObfuscationAttribute = class
    inherit Attribute
type ObfuscationAttribute = class
    inherit Attribute
[<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)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ObfuscationAttribute = class
    inherit Attribute
Public NotInheritable Class ObfuscationAttribute
Inherits Attribute
상속
ObfuscationAttribute
특성

예제

다음 코드 예제에서는 두 가지 형식 Type1 이 있는 공용 어셈블리를 Type2보여줍니다. 어셈블리는 공용으로 처리될 어셈블리를 표시하는 어셈블리와의 ObfuscateAssemblyAttribute난독 처리로 표시됩니다(즉, AssemblyIsPrivate 속성은 false).

Type1 는 어셈블리가 난독 처리용으로 표시되어 있으므로 난독 처리로 표시됩니다. 한 멤버는 Type1 속성을 사용하여 Exclude 난독 처리에서 제외됩니다.

Type2는 난독 처리에서 제외되지만 속성false이 이므로 해당 멤버가 난독 처리 ApplyToMembers 로 표시됩니다.

메서드 Type2MethodA 속성 값 "default" Feature 으로 표시됩니다. 속성의 기본값이 이므로 난독 처리에서 제외 MethodA 를 방지 하려면 속성에 Exclude 대 한 지정 false Exclude 해야 합니다true. 난독 처리 도구는 속성이 이므로 난독 처리 StripAfterObfuscation 후 특성을 제거하면 안 됩니다 false. 이 코드 예제의 다른 모든 특성은 난독 처리 StripAfterObfuscation 후에 제거됩니다. 속성이 지정되지 않았으므로 기본값은 .입니다 true.

코드 예제에는 특성 및 해당 속성을 표시하는 코드가 포함되어 있습니다. Ildasm.exe(IL 디스어셈블러)를 사용하여 DLL을 열어 특성을 검사할 수도 있습니다.

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 특성을 사용하면 어셈블리 작성자가 이진 파일에 주석을 달 수 있으므로 난독 처리 도구가 최소한의 외부 구성으로 올바르게 처리할 수 있습니다.

중요

이 특성을 적용해도 해당 특성을 적용할 코드 엔터티가 자동으로 난독 처리되지는 않습니다. 특성을 적용하는 것은 난독 처리 도구에 대한 구성 파일을 만드는 대안입니다. 즉, 난독 처리 도구에 대한 지침만 제공합니다. 난독 처리 도구 공급업체는 여기에 설명된 의미 체계를 따르는 것이 좋습니다. 그러나 특정 도구가 Microsoft 권장 사항을 따른다는 보장은 없습니다.

특성에 ObfuscationAttribute 문자열 Feature 속성이 있습니다. 난독 처리 도구는 사용자가 액세스할 수 있는 XML 구성 파일을 사용하여 이 속성의 문자열 값을 구현하는 기능에 매핑할 수 있습니다. 두 ObfuscationAttribute 개의 기능 문자열인 "default" 및 "all"을 정의합니다. 문자열 "default"는 도구의 기본 난독 처리 기능에 매핑되어야 하며 "all"은 도구에서 지원하는 전체 난독 처리 기능 집합에 매핑되어야 합니다. 속성의 Feature 기본값은 "all"이므로 전체 난독 처리 기능 집합을 사용할 수 있습니다.

어셈블리에 적용하면 어셈블리 ObfuscationAttribute 내의 모든 형식에도 적용됩니다. 속성이 ApplyToMembers 지정되지 않았거나 설정 true되면 특성도 모든 멤버에 적용됩니다. ObfuscationAttribute 에서는 어셈블리가 퍼블릭인지 프라이빗인지 지정하지 않습니다. 어셈블리가 퍼블릭인지 프라이빗인지 지정하려면 특성을 사용합니다 ObfuscateAssemblyAttribute .

클래스 및 구조 ObfuscationAttribute 체에 적용할 때 속성이 지정되지 않았거나 설정되면 형식 ApplyToMembers 의 모든 멤버에도 true적용됩니다.

메서드, 매개 변수, 필드 및 속성에 적용하면 특성이 적용되는 엔터티에만 영향을 줍니다.

생성자

ObfuscationAttribute()

ObfuscationAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

ApplyToMembers

형식의 특성이 형식의 모든 멤버에 적용되는지 여부를 나타내는 Boolean 값을 가져오거나 설정합니다.

Exclude

난독 처리 도구가 형식 또는 멤버를 난독 처리 대상에서 제외할지 여부를 나타내는 Boolean 값을 가져오거나 설정합니다.

Feature

난독 처리 도구에서 인식한 후 처리 옵션을 지정하는 문자열 값을 가져오거나 설정합니다.

StripAfterObfuscation

난독 처리 도구가 처리 후 이 특성을 제거하는지 여부를 나타내는 Boolean 값을 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

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

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보