HMA(HideMyAss) VPN 마우스 클릭 없이 PostMessage API를 이용하여 IP 변경하기 > vb.net

본문 바로가기

vb.net

[기타] HMA(HideMyAss) VPN 마우스 클릭 없이 PostMessage API를 이용하여 IP 변경하기

회원사진
하나를하더라도최선을
2020-05-15 16:38 8,689 0

본문





    <DllImport("winmm.dll", EntryPoint:="timeGetTime")>
    Public Function timeGetTime() As UInteger
    End Function
 
    <DllImport("user32.dll", SetLastError:=True)>
    Private Function FindWindow(lpClassName As String, lpWindowName As StringAs IntPtr
    End Function
 
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)>
    Private Function FindWindowEx(ByVal parentHandle As IntPtr,
                      ByVal childAfter As IntPtr,
                      ByVal lclassName As String,
                      ByVal windowTitle As StringAs IntPtr
    End Function
 
    <DllImport("user32.dll")>
    Private Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Boolean
    End Function
 
    Private Const WM_MOUSEMOVE = &H200
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
 
    Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Integer
 
    Public Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure
 
    Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
        MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function
 
    '// Delay 함수
    Public Function Delay(ByVal Millisecond As Long) As Boolean
        Dim GoalTime As Long
        LOG("Delay ...")
        LOG("")
        GoalTime = timeGetTime() + Millisecond
        Do While (GoalTime >= timeGetTime())
            If Not isRun Then Return False
            LOG(Format((GoalTime - timeGetTime()) / 1000"0.000"& "초 남았습니다.",,, True)
            Sleep(10) : Application.DoEvents()
        Loop
        Return True
    End Function
 
    Public MainForm As Form
    Public Function LOG(ByVal value As String, Optional isEmptyLine As Boolean = False, Optional isMsgBox As Boolean = False, Optional isNoAdd As Boolean = FalseAs String
        If MainForm Is Nothing Then Return ""
        Dim LB As ListBox = CType(MainForm.Controls.Find("LOG_LIST"True).FirstOrDefault(), ListBox)
        StreamWriterString(value)
        Try
            If Not LB Is Nothing Then
                Do While LB.Items.Count > 1000
                    LB.Items.Remove(LB.Items(0))
                Loop
                If isEmptyLine Then LB.Items.Add("")
                If isNoAdd Then
                    If LB.Items.Count = 0 Then LB.Items.Add("")
                    LB.Items(LB.Items.Count - 1= value
                Else
                    LB.Items.Add(value)
                End If
                LB.SelectedIndex = LB.Items.Count - 1
            End If
            If isMsgBox Then MsgBox(value)
            Return True
        Catch ex As Exception
            el.WriteToErrorLog(ex.Message, ex.StackTrace, "LOG.ListBox")
            Return False
        Finally
        End Try
    End Function
 
    Public Sub StreamWriterString(ByVal LB As ListBox, ByVal value As String)
        Try
            Dim SUB_NAME As String = DateAndTime.Now.ToString("yyyy.MM.dd.HH")
            Using fs As FileStream = New FileStream(String.Concat("LOG\\""LOG+", SUB_NAME, ".txt"), FileMode.Append, FileAccess.Write)
                Dim s As StreamWriter = New StreamWriter(fs)
                s.WriteLine(value)
                s.Close()
                fs.Close()
            End Using
        Catch ex As Exception
            el.WriteToErrorLog(ex.Message, ex.StackTrace, "StreamWriterString.value")
        End Try
    End Sub
 
    Public Sub HMA_VPN()
        LOG("")
        Dim oldIP As String = Nothing
        Dim newIP As String = Nothing
        While oldIP Is Nothing
            oldIP = getMyIP()
            Thread.Sleep(50)
        End While
        LOG(String.Concat("Current IP Adresse : ", oldIP))
        LOG("HMA VPN 프로그램의 위치를 찿습니다.")
        Dim hWnd As IntPtr = FindWindow("AvastCefWindow""HMA VPN")
        If hWnd = 0 Then LOG("해당 프로그램이 존재하지 않습니다.") : Return
        hWnd = FindWindowEx(hWnd, 0"CefBrowserWindow""AvastChromiumWindow")
        If hWnd = 0 Then LOG("작업중 오류가 발생하였습니다.") : HMA_VPN() : Return
        hWnd = FindWindowEx(hWnd, 0"Chrome_WidgetWin_0""")
        If hWnd = 0 Then LOG("작업중 오류가 발생하였습니다.") : HMA_VPN() : Return
        hWnd = FindWindowEx(hWnd, 0"Chrome_RenderWidgetHostHWND""Chrome Legacy Window")
        If hWnd = 0 Then LOG("작업중 오류가 발생하였습니다.") : HMA_VPN() : Return
        LOG("HMA VPN 프로그램의 Window 정보를 가져옵니다.")
        Dim stRect As RECT
        GetWindowRect(hWnd, stRect)
        LOG("IP변경 버튼을 클릭합니다.")
        Dim x As Integer = (stRect.Right - stRect.Left) / 2 + 110 '// + stRect.Left
        Dim y As Integer = (stRect.Bottom - stRect.Top) / 2 + 80 '// + stRect.Top 
        '// SetCursorPos(x, y)
        Dim MW As Integer = MakeDWord(x, y)
        PostMessage(hWnd, WM_MOUSEMOVE, 0, MW)
        PostMessage(hWnd, WM_LBUTTONDOWN, 0, MW)
        PostMessage(hWnd, WM_LBUTTONUP, 0, MW)
        LOG("IP가 변경되었는지 확인합니다.")
        Delay(3000)
        Dim GoalTime = timeGetTime() + 10000
        Do While (GoalTime >= timeGetTime())
            If Not isRun Then Return
            LOG(Format((GoalTime - timeGetTime()) / 1000"0.000"& "초 남았습니다.",,, True)
            Sleep(10) : Application.DoEvents()
            newIP = Nothing
            While newIP Is Nothing And (GoalTime > timeGetTime())
                If Not isRun Then Return
                newIP = getMyIP() : If newIP = "192.168.0.1" Then newIP = Nothing
                Delay(1000)
            End While
        Loop
        LOG(String.Concat("[", IPMaxCount, "] ", oldIP, " -> ", newIP))
    End Sub

댓글목록0

등록된 댓글이 없습니다.
게시판 전체검색