我想禁用Eazfuscator.NET (程序集级别)中的“常量文字剪枝”。这怎麽可能?
背景:我们在自定义属性构造函数中使用枚举。构造函数参数的类型是object,因为属性类位于不引用包含枚举的程序集的程序集中。
在混淆之前:
[MyAttribute(MyEnum.Value3)]
public class MyClass
{
}在混淆(分解)之后:
[MyAttribute(2)]
public class MyAttribute : Attribute
{
}在属性的构造函数中,我将值转换为Enum。这将在模糊化程序集中生成异常,但不会在未混淆的变体中生成异常:
public class MyAttribute : Attribute
{
public MyAttribute(object value)
{
var x = (Enum) value; // this throws an InvalidCastException after obfuscation
}
}发布于 2020-10-01 11:00:06
这就是如何使用Eazfuscator.NET禁用枚举文字的剥离/剪裁:
[Obfuscation(Feature = "enum values pruning", Exclude = true)]
enum SampleEnum
{
None,
Digit1,
Digit2
}发布于 2016-01-29 10:58:27
我是Frans的同事,我们想到了下面的解决方案。要将整数转换回其枚举值,必须传递枚举的类型。
有什么想法吗?
myAttribute(“描述”,param1: MyOwnEnum.MyParticularEnumValue,param2: MyOwnEnum.MyParticularEnumValue2,passedType: typeof(MyOwnEnum) )
内部类myAttribute :属性{
public myAttribute(string description, object param1, object param2, Type passedType)
{
this.myAttributeDescription = description;
this.SomePropertyWhichIsAnEnum = (Enum)Enum.ToObject(passedType, param1));
this.SomeOtherPropertyWhichIsAnEnum = (Enum)Enum.ToObject(passedType, param2)
}}
发布于 2016-07-18 10:53:06
不能向Enum基类强制转换整数。
但是,您可能不需要禁用“常量文本剪枝”。可以将整数强制转换为特定的枚举类型,而不是转换为enum基类型。当枚举没有一个表示整数值的值时,这也是有效的。
[MyAttribute(MyEnum.Value3)]
public class MyClass1
{
//...
}
[MyAttribute(2)]
public class MyClass2
{
//...
}
[MyAttribute(123456)]
public class MyClass4
{
// MyEnum does not have a value with 123456
// but it still works
}
public class MyAttribute : Attribute
{
public MyAttribute(object value)
{
var x1 = (MyEnum)value; // works with enum and number
var x2 = (Enum)(MyEnum)value; // works (but why would you?)
var x3 = (Enum) value; // this throws an InvalidCastException after obfuscation
}
}https://stackoverflow.com/questions/35062165
复制相似问题