4

.NET ライブラリのバイナリがあり、すべてのソースを復元する必要があります。私は.NET Reflectorを使用しましたが、ほとんどの場合、非常にうまく機能します。しかし、今は動的型に問題があります。私は次のコードを持っていますが、それを理解する方法が本当にわかりません。

dynamic obj2 = component;
if (<SetValue>o__SiteContainer0<T>.<>p__Site1 == null)
{
     <SetValue>o__SiteContainer0<T>.<>p__Site1 = CallSite<Func<CallSite, object, bool>>.Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.IsTrue, typeof(RecordPropertyDescriptor<T>), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }));
}
if (<SetValue>o__SiteContainer0<T>.<>p__Site2 == null)
{
      <SetValue>o__SiteContainer0<T>.<>p__Site2 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.NotEqual, typeof(RecordPropertyDescriptor<T>), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null) }));
}
if (<SetValue>o__SiteContainer0<T>.<>p__Site1.Target(<SetValue>o__SiteContainer0<T>.<>p__Site1, <SetValue>o__SiteContainer0<T>.<>p__Site2.Target(<SetValue>o__SiteContainer0<T>.<>p__Site2, obj2[this.Name], value)))
{
    // some simple code
}

何か提案はありますか?

編集

私はilspy.netを使用しましたが、私にとってはさらに悪いです

Func<CallSite, object, bool> arg_163_0 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site1.Target;
CallSite arg_163_1 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site1;
if (RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site2 == null)
{
    RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site2 = CallSite<Func<CallSite, object, object>>.Create(Binder.UnaryOperation(CSharpBinderFlags.None, ExpressionType.Not, typeof(RecordPropertyDescriptor<T>), new CSharpArgumentInfo[]
    {
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
    }));
}
Func<CallSite, object, object> arg_15E_0 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site2.Target;
CallSite arg_15E_1 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site2;
if (RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site3 == null)
{
    RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site3 = CallSite<Func<CallSite, Type, object, object, object>>.Create(Binder.InvokeMember(CSharpBinderFlags.None, "Equals", null, typeof(RecordPropertyDescriptor<T>), new CSharpArgumentInfo[]
    {
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType | CSharpArgumentInfoFlags.IsStaticType, null),
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null)
    }));
}
Func<CallSite, Type, object, object, object> arg_159_0 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site3.Target;
CallSite arg_159_1 = RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site3;
Type arg_159_2 = typeof(object);
if (RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site4 == null)
{
    RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site4 = CallSite<Func<CallSite, object, string, object>>.Create(Binder.GetIndex(CSharpBinderFlags.None, typeof(RecordPropertyDescriptor<T>), new CSharpArgumentInfo[]
    {
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
        CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null)
    }));
}
if (arg_163_0(arg_163_1, arg_15E_0(arg_15E_1, arg_159_0(arg_159_1, arg_159_2, RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site4.Target(RecordPropertyDescriptor<T>.<SetValue>o__SiteContainer0.<>p__Site4, component, this.Name), value))))
{
    // some (not so) simple code
}
4

1 に答える 1

13

これは逆アセンブラの問題ではなく、期待の問題です。逆アセンブラーは一般に、C# コンパイラーが自明ではない量のコードを自動生成するシナリオでは機能しなくなる傾向があります。これは間違いなくdynamicキーワードの場合で、コンパイラは Microsoft.CSharp.dll のバインダーを呼び出します。そして、多くの場合、動的なキーワードは高価な趣味です.

逆アセンブラができないこと:

  • 元のソース コードのコメントを復元する
  • 元のコードで const 宣言を復元する
  • メソッド内のローカル変数の名前を回復する
  • 匿名デリゲートをきれいに逆コンパイルする
  • イテレータをきれいに逆コンパイルする
  • ラムダ式をきれいに逆コンパイルする
  • Linq クエリ内包表記をきれいに逆コンパイルする
  • 動的変数を使用するコードをきれいに逆コンパイルします。
  • async/await を使用するコードをきれいに逆コンパイルする

Lambdas と Linq は 2008 年に C# バージョン 3.0 で追加され、すぐにヒットしました。また、Lutz Roeder がこれ以上 Reflector に取り組みたくないと判断し、Redgate に売却した年でもあります。タイミングはほぼ間違いなく偶然ではありませんでした。

上記のリストは、コードを逆コンパイルすることを懸念しているプログラマーにとって適切なガイドです。これらの構成要素をプログラムに追加するだけで、難読化ツールに煩わされる必要がなくなります。

その間、これは確かにコードを回復するのに役立ちません. 以前はどのように見えたかの記憶に頼って、手動で行う必要があります。もちろん、最初に行うことは、信頼性が高く回復可能なソース管理を行うことです。それはあなたが一度だけ犯す間違いです。

于 2013-08-01T10:36:48.807 に答える