Advertisement
iljimae

Change IP HMA by c#

Aug 7th, 2015
4,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.73 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Diagnostics;
  7. using System.Threading;
  8. using System.Runtime.InteropServices;
  9. using System.Net;
  10. using System.Net.NetworkInformation;
  11. using System.Net.Sockets;
  12. using System.IO;
  13. using Microsoft.Win32;
  14.  
  15. namespace VinaCaptcha
  16. {
  17.     public static class HideMyAssHandle
  18.     {
  19.         #region Windows API - user32.dll configs
  20.         [DllImport("user32.dll")]
  21.         private static extern int FindWindow(string lpClassName, String lpWindowName);
  22.  
  23.         [DllImport("user32.dll", SetLastError = true)]
  24.         private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
  25.  
  26.         [DllImport("user32.dll")]
  27.         private static extern void mouse_event(UInt32 dwFlags, UInt32 dx, UInt32 dy, UInt32 dwData, IntPtr dwExtraInfo);
  28.  
  29.         private const UInt32 MOUSEEVENTF_LEFTDOWN = 0x0002;
  30.         private const UInt32 MOUSEEVENTF_LEFTUP = 0x0004;
  31.  
  32.         [DllImport("user32.dll")]
  33.         [return: MarshalAs(UnmanagedType.Bool)] //http://msdn.microsoft.com/en-us/library/windows/desktop/ms646291(v=vs.85).aspx
  34.         private static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
  35.  
  36.         [DllImport("user32.dll")]
  37.         private static extern bool SetForegroundWindow(IntPtr hWnd);
  38.  
  39.         //const uint WM_KEYDOWN = 0x0100;
  40.         //const uint WM_KEYUP = 0x0101;
  41.         //const uint WM_CHAR = 0x0102;
  42.         //const int VK_TAB = 0x09;
  43.         //const int VK_ENTER = 0x0D;
  44.         //const int VK_UP = 0x26;
  45.         //const int VK_DOWN = 0x28;
  46.         //const int VK_RIGHT = 0x27;
  47.         //public const int WM_CLEAR = 0x0303;
  48.         private const int BN_CLICKED = 245;
  49.         private const int WM_LBUTTONDBLCLK = 0x0203;
  50.         private const int WM_SETTEXT = 0x000C;
  51.         private const int WM_PASTE = 0x0302;
  52.         [DllImport("user32.dll", EntryPoint = "SendMessageA")]
  53.         private static extern IntPtr SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, string lParam);
  54.         //[DllImport("user32.dll")]
  55.         //public static extern int SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
  56.         //[DllImport("user32.dll")]
  57.         //[return: MarshalAs(UnmanagedType.Bool)]
  58.         //static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
  59.         #endregion
  60.  
  61.         private static string AppFolder { set; get; }
  62.         private static string AppName { set; get; }
  63.         private static string AppLogFile { set; get; }
  64.  
  65.         public static string FirefoxUsed = "";
  66.  
  67.         public static bool Connect()
  68.         {
  69.             bool Connected = false;
  70.  
  71.             //Detect App Folder
  72.             AppName = "HMA! Pro VPN";
  73.             AppFolder = @"C:\Program Files (x86)\HMA! Pro VPN\bin\";
  74.             AppLogFile = AppFolder.Replace(@"\bin\", @"\log\ip_history.log");
  75.             if (File.Exists(AppFolder + AppName + ".exe") == false)
  76.             {
  77.                 AppFolder = @"C:\Program Files\HMA! Pro VPN\bin\";
  78.                 AppLogFile = AppFolder.Replace(@"\bin\", @"\log\ip_history.log");
  79.                 if (File.Exists(AppFolder + AppName + ".exe") == false)
  80.                 {
  81.                     return Connected;
  82.                 }
  83.             }
  84.  
  85.            
  86.             StartHMA:
  87.  
  88.             // Delete log file before start new connect
  89.             while (File.Exists(AppLogFile))
  90.             {
  91.                 try
  92.                 {
  93.                     File.Delete(AppLogFile);
  94.                     Thread.Sleep(1000);
  95.                 }
  96.                 catch { }
  97.             }
  98.  
  99.             // If HMA.exe exists then Disconnect
  100.             Process[] prs = Process.GetProcessesByName(AppName);
  101.             if (prs.Length > 0)
  102.             {
  103.                 if (prs[0].Responding == false)
  104.                 {
  105.                     while (prs.Length > 0)
  106.                     {
  107.                         try
  108.                         {
  109.                             prs[0].Kill();
  110.                             prs[0].Close();
  111.                         }
  112.                         catch { }
  113.                         prs = Process.GetProcessesByName(AppName);
  114.                     }
  115.                     Thread.Sleep(2000);
  116.  
  117.                     // Start HMA.exe & Connect
  118.                     Process.Start(AppFolder + AppName + ".exe");
  119.                     CheckWarningUpdate();
  120.                 }
  121.             }
  122.             // Update Registry before start HMA.exe
  123.             else
  124.             {
  125.                 //Registry.SetValue(@"HKEY_CURRENT_USER\Software\Privax\HMA! Pro VPN\Settings", "LoginID", hmaAcc[0]);
  126.                 //Registry.SetValue(@"HKEY_CURRENT_USER\Software\Privax\HMA! Pro VPN\Settings", "LoginKey", hmaAcc[1]);
  127.                 //Registry.SetValue(@"HKEY_CURRENT_USER\Software\Privax\HMA! Pro VPN\Settings", "ProtocolType2", "1");//1: OpenVPN, 2: PPTP
  128.                 //Registry.SetValue(@"HKEY_CURRENT_USER\Software\Privax\HMA! Pro VPN\Settings", "Region", hmaAcc[2]);
  129.                 Registry.SetValue(@"HKEY_CURRENT_USER\Software\Privax\HMA! Pro VPN\Settings", "LogIPHistory", "True");
  130.            
  131.                 // Start HMA.exe & Connect
  132.                 Process.Start(AppFolder + AppName + ".exe");
  133.                 CheckWarningUpdate();
  134.             }
  135.  
  136.          
  137.             // Connect
  138.             Process.Start(AppFolder + AppName + ".exe", "-disconnect");
  139.             Thread.Sleep(3000);
  140.             Process.Start(AppFolder + AppName + ".exe", "-connect");
  141.  
  142.             // Check Connected and Kill Error, Crash
  143.             for (int i = 0; i < 120; i++)
  144.             {
  145.                 Thread.Sleep(1000);
  146.  
  147.                 if (i % 5 == 0)
  148.                 {
  149.                     // Check CrashReport
  150.                     if (FindWindow(default(string), "CrashReport") > 0)
  151.                     {
  152.                         prs = Process.GetProcessesByName(AppName);
  153.                         while (prs.Length > 0)
  154.                         {
  155.                             try
  156.                             {
  157.                                 prs[0].Kill();
  158.                                 prs[0].Close();
  159.                             }
  160.                             catch { }
  161.                             prs = Process.GetProcessesByName(AppName);
  162.                         }
  163.  
  164.                         goto StartHMA;
  165.                     }
  166.                 }
  167.  
  168.                 // Check new IP Address
  169.                 if ((i > 15) && (i % 3 == 0))
  170.                 {
  171.                     if (File.Exists(AppLogFile))
  172.                     {
  173.                         Connected = true;
  174.                         break;
  175.                     }
  176.  
  177.                     //foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
  178.                     //{
  179.                     //    if ((nic.Description.Contains("TAP-Win32 Adapter V9") || nic.NetworkInterfaceType == NetworkInterfaceType.Ppp) && nic.OperationalStatus == OperationalStatus.Up)
  180.                     //    {
  181.                     //        Connected = true;
  182.                     //        break;
  183.                     //    }
  184.                     //}
  185.                     //if (Connected) break;
  186.                 }
  187.             }
  188.  
  189.             if (Connected == false)
  190.             {
  191.                 prs = Process.GetProcessesByName(AppName);
  192.                 while (prs.Length > 0)
  193.                 {
  194.                     try
  195.                     {
  196.                         prs[0].Kill();
  197.                         prs[0].Close();
  198.                     }
  199.                     catch { }
  200.                     prs = Process.GetProcessesByName(AppName);
  201.                 }
  202.             }
  203.  
  204.  
  205.             return Connected;
  206.         }
  207.  
  208.         public static void Disconnect()
  209.         {
  210.             try
  211.             {
  212.                 Process.Start(AppFolder + AppName + ".exe", "-disconnect");
  213.             }
  214.             catch { }
  215.         }
  216.  
  217.  
  218.         private static void CheckWarningUpdate()
  219.         {
  220.             for (int i = 0; i < 15; i++)
  221.             {
  222.                 Thread.Sleep(1000);
  223.  
  224.                 if (i % 3 == 0)
  225.                 {
  226.                     // Disable Warning Update new version
  227.                     int WarningBox = FindWindow(default(string), "Warning");
  228.                     if (WarningBox > 0)
  229.                     {
  230.                         try
  231.                         {
  232.                             IntPtr btnNoThanks = FindWindowEx((IntPtr)WarningBox, IntPtr.Zero, default(string), "No thanks");
  233.                             SendMessage(btnNoThanks, BN_CLICKED, IntPtr.Zero, null);
  234.                         }
  235.                         catch { }
  236.                     }
  237.                 }
  238.             }
  239.         }
  240.     }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement