2013-08-01 30 views
4

我有.NET庫的二進制文件,我必須恢復所有的源。我使用了.NET反射器,並且在大多數情況下它工作得很好。但現在我有動態類型的問題。 我有下面的代碼,我現在真的不知道如何理解它。反彙編.NET動態類型的c#庫

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 
} 
+0

http://ilspy.net/這是時間埋葬反射器... – Dennis

+2

@Dennis它正確地反彙編這種情況? - 主頁建議是「進一步的道路」 –

+1

** ilspy。net **比** CodeReflect **的效果更好,但它仍然給人難以理解的代碼 – rraszewski

回答

13

這不是你的反彙編的一個問題,它與你的期望有問題。在C#編譯器自動生成不重要的代碼量的任何情況下,反彙編程序通常都會出現崩潰。這當然是動態關鍵字的情況,編譯器會調用Microsoft.CSharp.dll中的聯編程序。而且它往往有一個很多它,動態關鍵字是一個昂貴的愛好。

的事情,反彙編不能做:

  • 收回原始源代碼註釋
  • 恢復const聲明中的原密碼
  • 恢復局部變量的名稱在你的方法
  • 乾淨編譯匿名代表
  • 乾淨地反編譯迭代器
  • 乾淨地反編譯lam bda表達式
  • 乾淨地反編譯Linq查詢解析
  • 乾淨地反編譯使用動態變量的代碼。
  • 乾淨編譯使用異步代碼/等待

lambda表達式並在2008年得到了補充的LINQ與C#3.0版,併爲即時點擊。也是Lutz Roeder決定不再想在Reflector上工作並將其賣給Redgate的那一年。時機幾乎肯定不是巧合。

上面的列表是一個體面的指導程序員關心他們的代碼反編譯。只需將這些結構添加到您的程序中,您就不必再擔心混淆器了。

同時,這當然不能幫助你恢復你的代碼。你必須親自去做,依靠你對之前看起來像什麼的記憶。當然,首先要做的是照顧可靠和可恢復的源代碼管理。這是一個你只做過一次的錯誤。

+0

真棒回答... thnks –

+0

這不是真的回答我的問題,但非常好的解釋。問題是lib不是我的,所以我不能依賴我的記憶......我只有那段代碼,我必須找到如何將它翻譯成更易於理解的代碼 – rraszewski

+0

圖書館受版權和幾乎總是隨許可協議分發。它總是說你不能做你正在做的事情,反向工程或改變代碼通常是被禁止的。檢查您獲得此庫時您同意的許可協議中擁有的權利。如果獲得源代碼不是您的權利的一部分,那麼您需要與圖書館所有者簽訂另一項協議。我們不能幫你做到這一點。 –