Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GDIPlus.au3>
- #include <GUIConstantsEx.au3>
- #include <WinAPIGdi.au3>
- #include <WinAPIGdiDC.au3>
- #include <WinAPIHObj.au3>
- #include <WindowsConstants.au3>
- #include "OpenCV-Match_UDF.au3"
- HotKeySet("{ESC}","_exit")
- Func _exit()
- Exit
- EndFunc
- Global $screenDC, $gfxContext, $hDC, $hHBitmap, $buffer, $Effect1, $Effect2
- Global $hNox, $NoxPos
- Global $penRed, $penYellow, $penGreen, $penBlue
- Global $GUI, $GUI_W = 600, $GUI_H = 600
- $GUI = GUICreate("Captcha", $GUI_W, $GUI_H, 300, 300)
- GUISetState()
- WinSetOnTop($GUI, "" , true)
- __StartUp()
- _OpenCV_Startup();loads opencv DLLs
- $search = 0
- $bitmapCap = 0
- $capSize = 480
- Global $oldSlidePos[2] = [0, 0]
- Global $prevpos[2] = [0, 0]
- ;~ Global $NoxPos[4] = [0,0, @DesktopWidth, @DesktopHeight]
- Global $timeVerify = TimerInit()
- Global $timeCheck
- Global $timeRe = TimerInit()
- Global $stt = 0
- While 1
- $pCursor = MouseGetPos()
- If IsArray($pCursor) = False Then Exit
- $NoxPos = WinGetPos($hNox)
- If GUIGetMsg() = - 3 Then Exit
- _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
- $bitmap = ScreenToBitmap($screenDC, 0, 0, $NoxPos[2], $NoxPos[3])
- If $stt = 0 And TimerDiff($timeCheck) > 3000 Then $search = _MatchPicture($bitmap, "data\capcha.png", 0.80,1,500)
- If IsArray($search) Then
- $capX = $search[0] - __map(39, 0, 480, 0, $capSize)
- $capY = $search[1] - __map(315, 0, 480, 0, $capSize)
- $bitmapCap = _GDIPlus_BitmapCloneArea($bitmap, $capX, $capY, $capSize, $capSize)
- $slidepos = _Captcha_GetHidden($bitmapCap)
- $pos = BitmapFit($bitmapCap, $GUI_W, $GUI_H)
- _GDIPlus_GraphicsDrawImagePointsRect($gfxContext, $bitmapCap, $pos[0], $pos[1], $pos[0] + $pos[2], $pos[1], $pos[0], $pos[1] + $pos[3], 0, 0, $capSize, $capSize)
- _GDIPlus_GraphicsDrawRect($gfxContext, __map(14, 0, 480, 0, $GUI_W), __map(294, 0, 480, 0, $GUI_H), __map(92, 0, 480, 0, $GUI_W), __map(92, 0, 480, 0, $GUI_W), $penRed)
- If IsArray($slidepos) And $slidepos[0] = $prevpos[0] And $slidepos[1] = $prevpos[1] Then $slidepos = False
- If IsArray($slidepos) Then
- $posX = __map($slidepos[0], 0, $capSize, 0, $GUI_W)
- $posY = __map($slidepos[1], 0, $capSize, 0, $GUI_H)
- _GDIPlus_GraphicsDrawRect($gfxContext, $posX, $posY, 90, 85, $penYellow)
- _GDIPlus_GraphicsDrawLine($gfxContext, $posX, $posY, $posX, __map(340, 0, $capSize, 0, $GUI_H), $penYellow)
- _GDIPlus_GraphicsDrawLine($gfxContext, __map(60, 0, 480, 0, $GUI_W), __map(340, 0, 480, 0, $GUI_H), $posX, __map(340, 0, 480, 0, $GUI_H), $penBlue)
- EndIf
- If $stt = 0 And IsArray($slidepos) = False And TimerDiff($timeRe) > 1200 Then
- $searchRe = _MatchPicture($bitmapCap, "data\recap.png", 0.80,3,500)
- $timeRe = TimerInit()
- If IsArray($searchRe) Then
- _GDIPlus_GraphicsDrawRect($gfxContext, __map($searchRe[0], 0, $capSize, 0, $GUI_W), __map($searchRe[1], 0, $capSize, 0, $GUI_H), 50, 50, $penRed)
- ControlClick($hNox, "", "", "left", 1, $capX + $searchRe[0] + 10, $capY + $searchRe[1] + 10)
- ;~ MouseClick("left", $capX + $searchRe[0] + 10, $capY + $searchRe[1] + 10, 1, 0)
- EndIf
- EndIf
- _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
- If IsArray($slidepos) Then
- WinActivate($hNox)
- If $stt = 0 Then
- $stt = 1
- $oldSlidePos = $slidepos
- MouseMove($NoxPos[0] + $search[0], $NoxPos[1] + $search[1], 0)
- MouseDown("left")
- MouseMove($NoxPos[0] + $capX + $slidepos[0] - $capSize / 5, $NoxPos[1] + $search[1], 20)
- Else
- If $stt >= 1 And $stt <= 2 And $oldSlidePos[0] <> $slidepos[0] Then $stt += 0.1
- MouseMove($pCursor[0] + 3, $pCursor[1], 0)
- If $stt >= 2 And $oldSlidePos[0] = $slidepos[0] Then
- $stt = 0
- MouseMove($pCursor[0] -10, $pCursor[1],20)
- Sleep(500)
- MouseUp("left")
- $search = False
- $timeCheck = TimerInit()
- $prevpos = $slidepos
- EndIf
- EndIf
- Else
- If $stt >= 1 Then
- MouseMove($pCursor[0] + 3, $pCursor[1], 0)
- $stt += 0.1
- EndIf
- EndIf
- If $stt >= 1 And $pCursor[0] > $NoxPos[0] + $search[0] + $capSize - $capSize / 10 Then
- $stt = 0
- MouseMove($pCursor[0] -10, $pCursor[1],20)
- Sleep(500)
- MouseUp("left")
- $search = False
- $timeCheck = TimerInit()
- $prevpos = $slidepos
- EndIf
- Else
- If TimerDiff($timeVerify) > 5000 Then
- $searchRe = _MatchPicture($bitmap, "data\verify.png", 0.80, 1,500)
- If IsArray($searchRe) Then
- _GDIPlus_GraphicsDrawRect($gfxContext, __map($searchRe[0], 0, $NoxPos[2], 0, $GUI_W), __map($searchRe[1], 0, $NoxPos[3], 0, $GUI_H), 200, 50, $penRed)
- ControlClick($hNox, "", "", "left", 1, $searchRe[0] + 10, $searchRe[1] + 10)
- ;~ MouseClick("left", $searchRe[0] + 10, $searchRe[1] + 10, 1, 0)
- EndIf
- $timeVerify = TimerInit()
- EndIf
- $pos = BitmapFit($bitmap, $GUI_W, $GUI_H)
- _GDIPlus_GraphicsDrawImagePointsRect($gfxContext, $bitmap, $pos[0], $pos[1], $pos[0] + $pos[2], $pos[1], $pos[0], $pos[1] + $pos[3], 0, 0, $NoxPos[2], $NoxPos[3])
- _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
- EndIf
- _GDIPlus_BitmapDispose($bitmap)
- _GDIPlus_BitmapDispose($bitmapCap)
- WEnd
- Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
- Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", _
- $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
- $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0)
- If @error Then Return SetError(@error, @extended, False)
- Return $aResult[0] = 0
- EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectIA
- Func _Captcha_GetHidden($hBitmap)
- Local $RGB, $bitmapW = _GDIPlus_ImageGetWidth($hBitmap), $bitmapH = _GDIPlus_ImageGetHeight($hBitmap)
- Local $lowest = 0xFFFFFFFFffff, $lX = $bitmapW, $lY = $bitmapH, $ret[2], $prevRGB = Number("0xFFFFFFFF", 3)
- Local $threshHold = Number("0xFF2a2a2a", 3), $threshHold2 = Number("0xFFfffffe", 3), $black = Number("0xFF000000", 3), $white = Number("0xFFFFFFFF", 3)
- $hBitmap = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $bitmapW, $bitmapH)
- _GDIPlus_BitmapApplyEffect($hBitmap, $Effect1)
- _GDIPlus_BitmapApplyEffect($hBitmap, $Effect2)
- For $x = Round($bitmapW / 4.62) To $bitmapW - $bitmapW / 10 step 2
- For $y = $bitmapH / 24 To Round($bitmapH / 2.5) Step 2
- $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
- If $RGB <= $threshHold Then
- $RGB = 0
- For $i = 1 To 15
- $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $x, $y + $i)
- Next
- If $RGB / 15 < $threshHold Then
- $RGB = 0
- For $ix = 1 To 5
- $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $x + $ix, $y)
- Next
- If $RGB / 5 < $threshHold Then
- $lx = $x
- $ly = $y
- ;~ While _GDIPlus_BitmapGetPixel($hBitmap, $lx-1, $ly) < $threshHold
- ;~ $lx -= 1
- ;~ WEnd
- ;~ While _GDIPlus_BitmapGetPixel($hBitmap, $lx, $ly - 1) < $threshHold
- ;~ $ly -= 1
- ;~ WEnd
- $ret[0] = $lx
- $ret[1] = $lY
- _GDIPlus_BitmapDispose($hBitmap)
- Return $ret
- EndIf
- Else
- $y += $i - 1
- EndIf
- EndIf
- Next
- Next
- _GDIPlus_BitmapDispose($hBitmap)
- EndFunc
- Func __StartUp()
- _GDIPlus_Startup()
- $hNox = WinGetHandle("NoxPlayer")
- WinActivate($hNox)
- $screenDC = _WinAPI_GetDC($hNox)
- ;~ $screenDC = _WinAPI_GetDC(0)
- $hDC = _WinAPI_GetDC($GUI)
- $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
- $buffer = _WinAPI_CreateCompatibleDC($hDC)
- _WinAPI_SelectObject($buffer, $hHBitmap)
- $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
- _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
- _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
- $penRed = _GDIPlus_PenCreate(0xFFFF0000, 3)
- $penYellow = _GDIPlus_PenCreate(0xFFFFFF00, 3)
- $penGreen = _GDIPlus_PenCreate(0xFF00FF00, 3)
- $penBlue = _GDIPlus_PenCreate(0xFF0000FF, 10)
- $Effect1 = _GDIPlus_EffectCreateHueSaturationLightness(0, -100)
- $Effect2 = _GDIPlus_EffectCreateSharpen(0, 100)
- EndFunc
- Func BitmapFit($bitmap, $fitW, $fitH)
- Local $w = _GDIPlus_ImageGetWidth($bitmap), $new_w
- Local $h = _GDIPlus_ImageGetHeight($bitmap), $new_h
- Local $derv_w = ___positive($w - $fitW)
- Local $derv_h = ___positive($h - $fith)
- If $derv_w >= $derv_h Then
- $new_w = $fitW
- $new_h = $h / ($w / $fitW)
- $new_x = 0
- $new_y = $fitH / 2 - $new_h / 2
- Else
- $new_h = $fitH
- $new_w = $w / ($h / $fitH)
- $new_y = 0
- $new_x = $fitW / 2 - $new_w / 2
- EndIf
- Local $ret[4] = [$new_x, $new_y, $new_w, $new_h]
- Return $ret
- EndFunc
- Func ScreenToBitmap($hDC, $x, $y, $w, $h)
- Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
- Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
- _WinAPI_SelectObject($tDC, $hBMP)
- _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
- $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
- _WinAPI_DeleteObject($hBMP)
- _WinAPI_DeleteDC($tDC)
- ;~ Return $hBMP
- Return $hBitmap
- EndFunc
- Func ___positive($x)
- Return $x < 0 ? -$x : $x
- EndFunc
- Func __minmax($x, $min, $max)
- Return ($x - $min) / ($max - $min)
- EndFunc
- Func __map($x, $min1, $max1, $min2, $max2)
- If $max2 > $min2 Then
- Return __minmax($x, $min1, $max1) * ($max2 - $min2) + $min2
- Else
- Return (1 - __minmax($x, $min1, $max1)) * ($min2 - $max2) + $max2
- EndIf
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement