2013-04-10 27 views
9

Hei. Tôi đã đọc nguồn tin bị dịch ngược của Digi Traffic Accelerator (tôi nghĩ đó là cách tốt nhất để tìm hiểu), cho đến khi tôi nhận được một số mã không dễ hiểu! Hãy xem:Hiểu loại do trình biên dịch tạo ra trong mã được giải mã dotPeek

internal class ProxyFarm 
    { 
    private static Random rand = new Random(); 
    private static Regex UserPassAtHostPort = new Regex("\r\n    ^\r\n    (?<user>[^:]+?) : (?<pass>[^@]+?)\r\n    @\r\n    (?<host>[^:]+? (?: : \\d+)?)\r\n    $", RegexOptions.IgnorePatternWhitespace); 
    private static Regex HostPortUserPass = new Regex("\r\n    ^\r\n    (?<host>[^:]+? : \\d+) : (?<user>[^:]+?) : (?<pass>.+?)\r\n    $", RegexOptions.IgnorePatternWhitespace); 
    public const string NEW = "new"; 
    public const string ACTIVE = "active"; 
    public const string BLOCKED_BY_GOOGLE = "blocked by Google"; 
    public const string INACTIVE = "inactive"; 
    public const string CHECKING = "Checking..."; 

    static ProxyFarm() 
    { 
    } 

    public static StorageDataSet.ProxiesRow GetRandomProxy(bool WillUseRecaptcha = true) 
    { 
     // some normal code 
    } 

    public static WebProxy MakeWebProxy(StorageDataSet.ProxiesRow row) 
    { 
     // some normal code 
    } 

    public static void CheckProxy(StorageDataSet.ProxiesRow proxy) 
    { 
     // ISSUE: object of a compiler-generated type is created 
     // ISSUE: variable of a compiler-generated type 
     ProxyFarm.\u003C\u003Ec__DisplayClass5 cDisplayClass5 = new ProxyFarm.\u003C\u003Ec__DisplayClass5(); 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.proxy = proxy; 
     // ISSUE: reference to a compiler-generated field 
     if (cDisplayClass5.proxy == null) 
     return; 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.logger = LogManager.GetLogger("Program"); 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.state = new ProxyFarm.CallbackState() 
     { 
     Proxy = cDisplayClass5.proxy, 
     Google = ProxyFarm.CheckStatus.NotChecked, 
     Post = ProxyFarm.CheckStatus.NotChecked 
     }; 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r = (HttpWebRequest) WebRequest.Create("http://www.digitrafficgenerator.com/post_test.php"); 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.Method = "POST"; 
     try 
     { 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.Proxy = (IWebProxy) ProxyFarm.MakeWebProxy(cDisplayClass5.proxy); 
     } 
     catch (Exception ex) 
     { 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.logger.Warn((object) ("Invalid proxy entered: " + cDisplayClass5.proxy.Address), ex); 
     // ISSUE: reference to a compiler-generated field 
     ProxyFarm.ChangeStatus(cDisplayClass5.proxy, "inactive"); 
     return; 
     } 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.ConnectionGroupName = Guid.NewGuid().ToString(); 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.byteArray = Encoding.UTF8.GetBytes("q=test"); 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.ContentLength = (long) cDisplayClass5.byteArray.Length; 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.ContentType = "application/x-www-form-urlencoded"; 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.Referer = "http://www.digitrafficgenerator.com/post_test.php"; 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.r.Timeout = 20000; 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated method 
     IAsyncResult res = cDisplayClass5.r.BeginGetRequestStream(new AsyncCallback(cDisplayClass5.\u003CCheckProxy\u003Eb__1), (object) null); 
     // ISSUE: reference to a compiler-generated field 
     WebObject.AbortRequestAfterTimeout(res, cDisplayClass5.r); 
     try 
     { 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated method 
     // ISSUE: reference to a compiler-generated field 
     res = cDisplayClass5.r.BeginGetResponse(new AsyncCallback(cDisplayClass5.\u003CCheckProxy\u003Eb__2), (object) cDisplayClass5.r); 
     } 
     catch (Exception ex) 
     { 
     // ISSUE: reference to a compiler-generated field 
     // ISSUE: reference to a compiler-generated field 
     cDisplayClass5.logger.Info((object) ("Got an exception using " + cDisplayClass5.proxy.Address), ex); 
     } 
     // ISSUE: reference to a compiler-generated field 
     WebObject.AbortRequestAfterTimeout(res, cDisplayClass5.r); 
     HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.google.com/recaptcha/api/js/recaptcha.js"); 
     request.Method = "GET"; 
     // ISSUE: reference to a compiler-generated field 
     request.Proxy = (IWebProxy) ProxyFarm.MakeWebProxy(cDisplayClass5.proxy); 
     request.Timeout = 20000; 
     request.ConnectionGroupName = Guid.NewGuid().ToString(); 
     // ISSUE: reference to a compiler-generated method 
     WebObject.AbortRequestAfterTimeout(request.BeginGetResponse(new AsyncCallback(cDisplayClass5.\u003CCheckProxy\u003Eb__3), (object) request), request); 
    } 

    protected static void ProxyChecked(IAsyncResult result, HttpWebRequest req, ProxyFarm.CallbackState state) 
    { 
     ILog logger = LogManager.GetLogger("Program"); 
     ProxyFarm.CheckStatus checkStatus = ProxyFarm.CheckStatus.NotOk; 
     try 
     { 
     HttpWebResponse httpWebResponse = (HttpWebResponse) req.EndGetResponse(result); 
     if (req.RequestUri == httpWebResponse.ResponseUri) 
     { 
      if (httpWebResponse.StatusCode == HttpStatusCode.OK) 
      checkStatus = ProxyFarm.CheckStatus.Ok; 
     } 
     } 
     catch (Exception ex) 
     { 
     } 
     lock (state) 
     { 
     if (req.RequestUri.Authority.Contains("google.com")) 
      state.Google = checkStatus; 
     else 
      state.Post = checkStatus; 
     if (state.Post == ProxyFarm.CheckStatus.NotOk) 
     { 
      ProxyFarm.ChangeStatus(state.Proxy, "inactive"); 
      logger.Info((object) ("Marking " + state.Proxy.Address + " as inactive as it cannot POST")); 
     } 
     else if (state.Google == ProxyFarm.CheckStatus.NotOk) 
     { 
      ProxyFarm.ChangeStatus(state.Proxy, "inactive"); 
      logger.Info((object) ("Marking " + state.Proxy.Address + " as inactive as it is blocked by google")); 
     } 
     else 
     { 
      if (state.Google != ProxyFarm.CheckStatus.Ok || state.Post != ProxyFarm.CheckStatus.Ok) 
      return; 
      ProxyFarm.ChangeStatus(state.Proxy, "active"); 
     } 
     } 
    } 

    public static void ReportBrokenProxy(StorageDataSet.ProxiesRow proxy, bool recaptcha_fail = false) 
    { 
     // some normal code 
    } 

    private static void ChangeStatus(StorageDataSet.ProxiesRow Proxy, string status) 
    { 
     // some normal code 
    } 

    public enum CheckStatus 
    { 
     NotChecked, 
     Ok, 
     NotOk, 
    } 

    protected class CallbackState 
    { 
     public StorageDataSet.ProxiesRow Proxy { get; set; } 

     public ProxyFarm.CheckStatus Post { get; set; } 

     public ProxyFarm.CheckStatus Google { get; set; } 
    } 
    } 

Như bạn thấy, có vẻ như trong CheckProxy phương pháp, trình biên dịch tạo ra một kiểu mới! Bạn có bất kỳ ý tưởng những gì đang thực sự xảy ra trong phương pháp này? Làm thế nào tôi có thể hiểu được mã?

+0

Đây là sự thiếu hụt bộ giải mã, báo cáo. – usr

Trả lời

8

\u003C\u003E là các biểu thị unicode tương ứng là <>.

Các ký tự đó hợp lệ trong IL .. do đó trình biên dịch sẽ tạo các biến có tên như vậy để tránh va chạm.

Trình giải mã của bạn không biết cách chuyển đổi thành <> và không xóa các biến tạm thời.

+0

Cảm ơn bạn đã trả lời. Tôi hiểu. Vì vậy, nếu bạn muốn viết lại phương thức 'CheckProxy', bạn sẽ làm như thế nào? Ý tôi là, tại sao trình biên dịch tạo ra lớp '<> __ DisplayClass5'? Điều kiện nào làm cho trình biên dịch thực hiện công việc này? –

+1

Trình biên dịch sẽ thực hiện việc này cho những thứ như Closures, Anonymous Types hoặc khi bạn đang sử dụng một đối tượng thông qua mệnh đề 'try..finally'. Các ngữ nghĩa chính xác tôi không quen thuộc với .. tuy nhiên nó không thực sự là một vấn đề. –

3

Mở nó trong dnSpy và tìm xung quanh một phương thức phù hợp (ish). Họ sẽ theo một thứ tự khác nhưng dnSpy làm một công việc tốt để giải mã lambdas.

+0

Cảm ơn vì điều này, tôi đã có kết quả tốt hơn nhiều so với dotpeek – liammcdee

+2

Tôi đã theo dõi câu trả lời này và đã đi dnSpy, nhưng sau khi mucking xung quanh cố gắng để có được nó để xây dựng sau đó gỡ lỗi (không cố gắng xuất bản nó!) kết quả cuối cùng không rõ ràng hơn dotPeek –

Các vấn đề liên quan