다음과 같이 Secret1과 같은 내부 클래스를 난독 화 (이름 바꾸기)하려면 Obfuscar가 필요합니다. 이것은 Obfuscar 운동을위한 부수적 인 public
및 internal
클래스가있는 최소한의 WPF 응용 프로그램입니다.Obfuscar로 내부 클래스 이름 바꾸기
namespace WpfApp
{
public enum Category { Low, High }
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);
var s1 = new Secret1();
s1.SecretMethod1();
var s2 = new Secret2();
s2.SecretMethod();
}
}
internal class Secret1
{
internal int SecretInt;
private float SecretFloat;
internal int SecretMethod1()
{
if (SecretMethod2() == false)
return 0;
else
return 1;
}
private bool SecretMethod2()
{
return false;
}
}
public class Secret2
{
private int SecretInt;
public int SecretMethod()
{
return this.SecretInt;
}
}
[Serializable] 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();
}
}
}
[Serializable] 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));
}
}
}
내 설정 파일은 다음과 같습니다 KeepPublicApi
을 설정
<?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="false" />
<Var name="HidePrivateApi" value="true" />
<SkipType name="WpfApp.ViewModel" skipFields="true" skipProperties="true" />
<SkipType name="WpfApp.WpfNotifier" skipFields="true" skipProperties="true" />
<SkipType name="WpfApp.Category" skipFields="true" skipProperties="true" />
</Module>
</Obfuscator>
</configuration>
모든 가능한 조합과 인이 건너 뛴 Secret1 클래스의 HidePrivateApi
결과. "Skipped"는 Obfuscar 용어로 "obfuscated"가 아닙니다. Obfuscar의 매핑 출력 추적의
<Var name="KeepPublicApi" value="true" />
<Var name="HidePrivateApi" value="false" />
Secret1 class was skipped
<Var name="KeepPublicApi" value="true" />
<Var name="HidePrivateApi" value="true" />
Secret1 class was skipped
<Var name="KeepPublicApi" value="false" />
<Var name="HidePrivateApi" value="false" />
Secret1 class was skipped
<Var name="KeepPublicApi" value="false" />
<Var name="HidePrivateApi" value="true" />
Secret1 class was skipped
두 가지 예 : 내 노트에서.
Mapping.txt에서 발췌 (= 공공 거짓 유지, 개인 = 사실 숨기) :
[WpfApp]WpfApp.Secret1 skipped: HidePrivateApi option in configuration
{
[WpfApp]WpfApp.Secret1::SecretMethod1[0]() skipped: HidePrivateApi option in configuration
[WpfApp]WpfApp.Secret1::SecretMethod2[0]() skipped: HidePrivateApi option in configuration
[WpfApp]WpfApp.Secret1::.ctor[0]() skipped: special name
System.Int32 [WpfApp]System.Int32 WpfApp.Secret1::SecretInt skipped: HidePrivateApi option in configuration
System.Single [WpfApp]System.Single WpfApp.Secret1::SecretFloat skipped: HidePrivateApi option in configuration
}
이 Mapping.txt에서 발췌 (= false를 공개 유지, 숨길 = false를 개인)
[WpfApp]WpfApp.Secret1 skipped: HidePrivateApi option in configuration
{
[WpfApp]WpfApp.Secret1::SecretMethod1[0]() skipped: HidePrivateApi option in configuration
[WpfApp]WpfApp.Secret1::SecretMethod2[0]() skipped: HidePrivateApi option in configuration
[WpfApp]WpfApp.Secret1::.ctor[0]() skipped: special name
System.Int32 [WpfApp]System.Int32 WpfApp.Secret1::SecretInt skipped: HidePrivateApi option in configuration
System.Single [WpfApp]System.Single WpfApp.Secret1::SecretFloat skipped: HidePrivateApi option in configuration
}
현실적인 응용 프로그램이이 최소한의 WPF 예제보다 크기 때문에 수용 가능한 솔루션은 소스 코드 변경을 요구해서는 안됩니다. 난 당신이주의 깊게 샘플 프로젝트를 체크 아웃 할 수 있기를 바랍니다