gpt4 book ai didi

c# - 让 Obfuscar 避免重命名枚举类型

转载 作者:行者123 更新时间:2023-11-30 12:58:56 38 4
gpt4 key购买 nike

在使用 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
}

我的用法有误还是这是一个错误?

最佳答案

在“MarkedOnly”选项周围发现了一个错误,在混淆字段等时无法检查它。我只是在 master 分支中修复了它。

https://github.com/lextm/obfuscar

请注意,在此更改之后,“MarkedOnly”选项对其他选项是独占的。如果元素(类/枚举/方法/字段等)没有附加 Obfuscation 属性,它将保持不变。 “KeepPublicApi”和“HidePrivateApi”等设置将被忽略。

关于c# - 让 Obfuscar 避免重命名枚举类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27941234/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com