ObfuscationAttribute Osztály
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Utasítja az akadálymentesítő eszközöket, hogy hajtják végre a megadott műveleteket egy szerelvényhez, típushoz vagy taghoz.
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
- Öröklődés
- Attribútumok
Példák
Az alábbi példakód egy nyilvános szerelvényt mutat be két típussal: Type1 és Type2. A szerelvény ObfuscateAssemblyAttributea nyilvánosként kezelendő szerelvényt jelöli (azaz a AssemblyIsPrivate tulajdonság az false).
Type1 eltömítésre van jelölve, mert a szerelvény elfedésre van megjelölve. Az egyik tag Type1 ki van zárva az elfedésből a Exclude tulajdonság használatával.
Type2kizárásra kerül, de tagjai eltömítésre vannak megjelölve, mert a ApplyToMembers tulajdonság .false
A MethodA metódus Type2 a tulajdonság értékével "default"Feature van megjelölve. Meg kell adnifalse, hogy a Exclude tulajdonság ne zárja ki MethodA az eltömítést, mert a tulajdonság Excludealapértelmezett értéke .true Az elhomályosító eszköznek nem szabad elfednie az attribútumot az elfedés után, mert a tulajdonság az StripAfterObfuscationfalse. A példakód összes többi attribútuma elfedés után megszűnik, mert a StripAfterObfuscation tulajdonság nincs megadva, ezért alapértelmezés szerint a következő lesz true.
A példakód tartalmazza az attribútumok és tulajdonságaik megjelenítésére szolgáló kódot. Az attribútumok vizsgálatához nyissa meg a DLL-t a Ildasm.exe (IL Disassembler) segítségével.
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
Megjegyzések
Az ObfuscationAttribute és ObfuscateAssemblyAttribute az attribútumok lehetővé teszik a szerelvény-szerzők számára a bináris fájlok megjegyzését, hogy az obfuscation-eszközök minimális külső konfigurációval megfelelően dolgozhassák fel őket.
Important
Az attribútum alkalmazása nem teszi automatikusan elhomályosítani azt a kódentitást, amelyre alkalmazza. Az attribútum alkalmazása alternatíva egy konfigurációs fájl létrehozására az obfuscation eszközhöz. Vagyis csupán útmutatást nyújt egy elfedő eszközhöz. Microsoft javasolja, hogy az obfuscation-eszközök gyártói kövessék az itt leírt szemantikát. Azonban nincs garancia arra, hogy egy adott eszköz Microsoft javaslatokat követ.
Az ObfuscationAttribute attribútum egy sztringtulajdonságú Feature . Az obfuscation-eszközök a tulajdonság sztringértékeit leképezhetik az általuk implementálható funkciókra, lehetőleg egy olyan XML-konfigurációs fájl használatával, amelyhez a felhasználók hozzáférhetnek. Ez ObfuscationAttribute két funkciósztringet határoz meg, az "alapértelmezett" és az "összes" karakterláncot. Az "alapértelmezett" sztringnek le kell képeznie az eszköz alapértelmezett obfuscation funkcióit, az "összes" pedig az eszköz által támogatott elfedő funkciók teljes készletére kell megfeleltetnie. A tulajdonság alapértelmezett értéke az Feature "összes", amely lehetővé teszi az elfedési funkciók teljes készletét.
Szerelvényre alkalmazva a szerelvényen ObfuscationAttribute belüli összes típusra is vonatkozik. Ha a ApplyToMembers tulajdonság nincs megadva vagy be van állítva true, az attribútum az összes tagra is érvényes.
ObfuscationAttribute nem adja meg, hogy egy szerelvény nyilvános vagy privát-e. Annak megadásához, hogy egy szerelvény nyilvános vagy privát-e, használja az ObfuscateAssemblyAttribute attribútumot.
Osztályokra és struktúrákra alkalmazva a típus összes tagjára is vonatkozik, ObfuscationAttribute ha a ApplyToMembers tulajdonság nincs megadva, vagy be van állítva true.
Metódusokra, paraméterekre, mezőkre és tulajdonságokra alkalmazva az attribútum csak azt az entitást érinti, amelyre alkalmazva van.
Konstruktorok
| Name | Description |
|---|---|
| ObfuscationAttribute() |
Inicializálja a ObfuscationAttribute osztály új példányát. |
Tulajdonságok
| Name | Description |
|---|---|
| ApplyToMembers |
Lekéri vagy beállít egy Boolean értéket, amely jelzi, hogy egy típus attribútuma a típus tagjaira vonatkozik-e. |
| Exclude |
Lekéri vagy beállít egy Boolean értéket, amely jelzi, hogy az obfuscation eszköznek ki kell-e zárnia a típust vagy tagot az eltolásból. |
| Feature |
Lekéri vagy beállít egy sztringértéket, amelyet az obfuscation eszköz felismer, és amely megadja a feldolgozási beállításokat. |
| StripAfterObfuscation |
Lekéri vagy beállít egy Boolean értéket, amely jelzi, hogy az obfuscation eszköznek el kell-e távolítania ezt az attribútumot a feldolgozás után. |
| TypeId |
Ha származtatott osztályban implementálják, ehhez egy egyedi azonosítót Attributekap. (Öröklődés forrása Attribute) |
Metódusok
| Name | Description |
|---|---|
| Equals(Object) |
Olyan értéket ad vissza, amely jelzi, hogy ez a példány egyenlő-e egy adott objektummal. (Öröklődés forrása Attribute) |
| GetHashCode() |
A példány kivonatkódját adja vissza. (Öröklődés forrása Attribute) |
| GetType() |
Lekéri az Type aktuális példányt. (Öröklődés forrása Object) |
| IsDefaultAttribute() |
Ha egy származtatott osztályban felül van bírálva, azt jelzi, hogy a példány értéke-e a származtatott osztály alapértelmezett értéke. (Öröklődés forrása Attribute) |
| Match(Object) |
Származtatott osztály felülírásakor egy olyan értéket ad vissza, amely jelzi, hogy ez a példány egy adott objektummal egyenlő-e. (Öröklődés forrása Attribute) |
| MemberwiseClone() |
Az aktuális Objectpéldány sekély másolatát hozza létre. (Öröklődés forrása Object) |
| ToString() |
Az aktuális objektumot jelképező sztringet ad vissza. (Öröklődés forrása Object) |
Explicit interfész-implementációk
| Name | Description |
|---|---|
| _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Névkészletet képez le a küldési azonosítók megfelelő készletére. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Lekéri egy objektum típusadatait, amelyek a felület típusadatainak lekérésére használhatók. (Öröklődés forrása Attribute) |
| _Attribute.GetTypeInfoCount(UInt32) |
Lekéri az objektumok által biztosított típusinformációs felületek számát (0 vagy 1). (Öröklődés forrása Attribute) |
| _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Hozzáférést biztosít az objektumok által közzétett tulajdonságokhoz és metódusokhoz. (Öröklődés forrása Attribute) |