在使用Obfuscar时,我希望防止枚举类型被混淆,因为我需要原始枚举值名称。我对枚举值调用ToString(),因为它们对用户很有用。在通常的配置中,除了那些出现在带有<SkipType name="namespace.EnumType"/>元素的配置文件中的类型之外,所有类型都是模糊的,我对此感到困难。我正在求助于使用<MarkedOnly />的更为悲观的方法,它只混淆了用注释标记的内容。下面是相当小的配置文件。
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0"
sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
<Obfuscator>
<Var name="InPath"
value="\users\user\documents\visual studio 2013\projects\wpfapp\wpfapp\bin\debug" />
<Var name="OutPath"
value="\users\user\documents\visual studio 2013\projects\wpfapp\wpfapp\bin\debug" />
<Module file="$(InPath)\wpfapp.exe" />
<Var name="KeepPublicApi" value="true" />
<Var name="HidePrivateApi" value="true" />
<Var name="MarkedOnly" value="true" />
</Obfuscator>
</configuration>附加注释的代码是:
namespace WpfApp
{
public enum Category { Low, High }
[System.Reflection.Obfuscation]
public partial class MainWindow : Window
{
private ViewModel ViewModel;
public MainWindow()
{
InitializeComponent();
this.DataContext = this.ViewModel = new ViewModel();
}
private void MyButtonClick(object sender, RoutedEventArgs e)
{
this.ViewModel.Process(MyTextBox.Text);
}
}
internal class ViewModel : WpfNotifier
{
private const float DefaultKilograms = 80.0f;
private string _kilograms;
public string Kilograms // WPF binds here
{
get { return this._kilograms; }
set { this._kilograms = value; NotifyPropertyChanged(); }
}
private string _resultText;
public string ResultText // WPF binds here
{
get { return this._resultText; }
set { this._resultText = value; NotifyPropertyChanged(); }
}
internal void Process(string input)
{
float kilograms;
if (Single.TryParse(input, out kilograms))
{
Category c = (kilograms > 100.0f) ? Category.High : Category.Low;
this.ResultText = c.ToString();
}
else
{
this.Kilograms = ViewModel.DefaultKilograms.ToString();
}
}
}
public class WpfNotifier : INotifyPropertyChanged
{
[field: NonSerialized]
public event PropertyChangedEventHandler PropertyChanged; // public for interface
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
else
; // it is harmless to fail to notify before the window has been loaded and rendered
}
}
}如您所见,只有一种类型使用[System.Reflection.Obfuscation]进行注释,但是输出映射显示枚举已被重命名。枚举类型称为Category。
Renamed Types:
[WpfApp]WpfApp.Category -> [WpfApp]A.a
{
WpfApp.Category [WpfApp]WpfApp.Category WpfApp.Category::Low -> A
WpfApp.Category [WpfApp]WpfApp.Category WpfApp.Category::High -> a
System.Int32 [WpfApp]System.Int32 WpfApp.Category::value__ skipped: special name
}我的用法是错的还是这是个错误?
发布于 2015-01-17 05:14:11
在"MarkedOnly“选项周围已经发现了一个bug,在该选项中,当混淆字段等时,无法检查它。我刚把它固定在主树枝上。
https://github.com/lextm/obfuscar
请注意,在此更改之后,"MarkedOnly“选项是其他选项的独占选项。如果一个元素(类/枚举/方法/字段等)没有附加Obfuscation属性,那么它将保持不变。像"KeepPublicApi“和"HidePrivateApi”这样的设置会被忽略。
https://stackoverflow.com/questions/27941234
复制相似问题