Advertisement
Guest User

Untitled

a guest
Apr 11th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.51 KB | None | 0 0
  1. #include <GDIPlus.au3>
  2. #include <GUIConstantsEx.au3>
  3. #include <WinAPIGdi.au3>
  4. #include <WinAPIGdiDC.au3>
  5. #include <WinAPIHObj.au3>
  6. #include <WindowsConstants.au3>
  7. #include "OpenCV-Match_UDF.au3"
  8.  
  9. HotKeySet("{ESC}","_exit")
  10. Func _exit()
  11.     Exit
  12. EndFunc
  13.  
  14. Global $screenDC, $gfxContext, $hDC, $hHBitmap, $buffer, $Effect1, $Effect2
  15. Global $hNox, $NoxPos
  16. Global $penRed, $penYellow, $penGreen, $penBlue
  17. Global $GUI, $GUI_W = 600, $GUI_H = 600
  18.  
  19.  
  20. $GUI = GUICreate("Captcha", $GUI_W, $GUI_H, 300, 300)
  21. GUISetState()
  22. WinSetOnTop($GUI, "" , true)
  23.  
  24. __StartUp()
  25. _OpenCV_Startup();loads opencv DLLs
  26. $search = 0
  27. $bitmapCap = 0
  28. $capSize = 480
  29. Global $oldSlidePos[2] = [0, 0]
  30. Global $prevpos[2] = [0, 0]
  31. ;~ Global $NoxPos[4] = [0,0, @DesktopWidth, @DesktopHeight]
  32. Global $timeVerify = TimerInit()
  33. Global $timeCheck
  34. Global $timeRe = TimerInit()
  35. Global $stt = 0
  36.  
  37. While 1
  38.  
  39.     $pCursor = MouseGetPos()
  40.     If IsArray($pCursor) = False Then Exit
  41.     $NoxPos = WinGetPos($hNox)
  42.     If GUIGetMsg() = - 3 Then Exit
  43.  
  44.     _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
  45.  
  46.     $bitmap = ScreenToBitmap($screenDC, 0, 0, $NoxPos[2], $NoxPos[3])
  47.  
  48.  
  49.     If $stt = 0 And TimerDiff($timeCheck) > 3000 Then $search = _MatchPicture($bitmap, "data\capcha.png", 0.80,1,500)
  50.  
  51.     If IsArray($search) Then
  52.         $capX = $search[0] - __map(39, 0, 480, 0, $capSize)
  53.         $capY = $search[1] - __map(315, 0, 480, 0, $capSize)
  54.  
  55.         $bitmapCap = _GDIPlus_BitmapCloneArea($bitmap, $capX, $capY, $capSize, $capSize)
  56.  
  57.         $slidepos = _Captcha_GetHidden($bitmapCap)
  58.         $pos = BitmapFit($bitmapCap, $GUI_W, $GUI_H)
  59.  
  60.         _GDIPlus_GraphicsDrawImagePointsRect($gfxContext, $bitmapCap, $pos[0], $pos[1], $pos[0] + $pos[2], $pos[1], $pos[0], $pos[1] + $pos[3], 0, 0, $capSize, $capSize)
  61.         _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)
  62.  
  63.         If IsArray($slidepos) And $slidepos[0] = $prevpos[0] And $slidepos[1] = $prevpos[1] Then $slidepos = False
  64.  
  65.         If IsArray($slidepos) Then
  66.  
  67.             $posX = __map($slidepos[0], 0, $capSize, 0, $GUI_W)
  68.             $posY = __map($slidepos[1], 0, $capSize, 0, $GUI_H)
  69.             _GDIPlus_GraphicsDrawRect($gfxContext, $posX, $posY, 90, 85, $penYellow)
  70.             _GDIPlus_GraphicsDrawLine($gfxContext, $posX, $posY, $posX, __map(340, 0, $capSize, 0, $GUI_H), $penYellow)
  71.             _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)
  72.         EndIf
  73.  
  74.  
  75.         If $stt = 0 And IsArray($slidepos) = False And TimerDiff($timeRe) > 1200 Then
  76.             $searchRe = _MatchPicture($bitmapCap, "data\recap.png", 0.80,3,500)
  77.             $timeRe = TimerInit()
  78.  
  79.             If IsArray($searchRe) Then
  80.                 _GDIPlus_GraphicsDrawRect($gfxContext, __map($searchRe[0], 0, $capSize, 0, $GUI_W), __map($searchRe[1], 0, $capSize, 0, $GUI_H), 50, 50, $penRed)
  81.                 ControlClick($hNox, "", "", "left", 1, $capX + $searchRe[0] + 10, $capY + $searchRe[1] + 10)
  82. ;~              MouseClick("left", $capX + $searchRe[0] + 10, $capY + $searchRe[1] + 10, 1, 0)
  83.             EndIf
  84.         EndIf
  85.  
  86.         _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
  87.  
  88.         If IsArray($slidepos) Then
  89.             WinActivate($hNox)
  90.  
  91.             If $stt = 0 Then
  92.                 $stt = 1
  93.                 $oldSlidePos = $slidepos
  94.                 MouseMove($NoxPos[0] + $search[0], $NoxPos[1] + $search[1], 0)
  95.                 MouseDown("left")
  96.                 MouseMove($NoxPos[0] + $capX + $slidepos[0] - $capSize / 5, $NoxPos[1] + $search[1], 20)
  97.             Else
  98.  
  99.                 If $stt >= 1 And $stt <= 2 And $oldSlidePos[0] <> $slidepos[0] Then $stt += 0.1
  100.  
  101.                 MouseMove($pCursor[0] + 3, $pCursor[1], 0)
  102.  
  103.                 If $stt >= 2 And $oldSlidePos[0] = $slidepos[0] Then
  104.                     $stt = 0
  105.                     MouseMove($pCursor[0] -10, $pCursor[1],20)
  106.                     Sleep(500)
  107.                     MouseUp("left")
  108.                     $search = False
  109.                     $timeCheck = TimerInit()
  110.                     $prevpos = $slidepos
  111.                 EndIf
  112.             EndIf
  113.  
  114.         Else
  115.             If $stt >= 1 Then
  116.                 MouseMove($pCursor[0] + 3, $pCursor[1], 0)
  117.                 $stt += 0.1
  118.             EndIf
  119.         EndIf
  120.  
  121.         If $stt >= 1 And $pCursor[0] > $NoxPos[0] + $search[0] + $capSize - $capSize / 10 Then
  122.             $stt = 0
  123.             MouseMove($pCursor[0] -10, $pCursor[1],20)
  124.             Sleep(500)
  125.             MouseUp("left")
  126.             $search = False
  127.             $timeCheck = TimerInit()
  128.             $prevpos = $slidepos
  129.         EndIf
  130.  
  131.  
  132.     Else
  133.  
  134.         If TimerDiff($timeVerify) > 5000 Then
  135.             $searchRe = _MatchPicture($bitmap, "data\verify.png", 0.80, 1,500)
  136.  
  137.             If IsArray($searchRe) Then
  138.  
  139.                 _GDIPlus_GraphicsDrawRect($gfxContext, __map($searchRe[0], 0, $NoxPos[2], 0, $GUI_W), __map($searchRe[1], 0, $NoxPos[3], 0, $GUI_H), 200, 50, $penRed)
  140.                 ControlClick($hNox, "", "", "left", 1, $searchRe[0] + 10, $searchRe[1] + 10)
  141. ;~              MouseClick("left", $searchRe[0] + 10, $searchRe[1] + 10, 1, 0)
  142.             EndIf
  143.             $timeVerify = TimerInit()
  144.         EndIf
  145.  
  146.         $pos = BitmapFit($bitmap, $GUI_W, $GUI_H)
  147.         _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])
  148.  
  149.         _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
  150.  
  151.     EndIf
  152.  
  153.  
  154.  
  155.     _GDIPlus_BitmapDispose($bitmap)
  156.     _GDIPlus_BitmapDispose($bitmapCap)
  157. WEnd
  158.  
  159. Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
  160.     Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", _
  161.             $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
  162.             $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0)
  163.     If @error Then Return SetError(@error, @extended, False)
  164.     Return $aResult[0] = 0
  165. EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectIA
  166.  
  167. Func _Captcha_GetHidden($hBitmap)
  168.  
  169.     Local $RGB, $bitmapW = _GDIPlus_ImageGetWidth($hBitmap), $bitmapH = _GDIPlus_ImageGetHeight($hBitmap)
  170.     Local $lowest = 0xFFFFFFFFffff, $lX = $bitmapW, $lY = $bitmapH, $ret[2], $prevRGB = Number("0xFFFFFFFF", 3)
  171.     Local $threshHold = Number("0xFF2a2a2a", 3), $threshHold2 = Number("0xFFfffffe", 3), $black = Number("0xFF000000", 3), $white = Number("0xFFFFFFFF", 3)
  172.  
  173.     $hBitmap = _GDIPlus_BitmapCloneArea($hBitmap, 0, 0, $bitmapW, $bitmapH)
  174.     _GDIPlus_BitmapApplyEffect($hBitmap, $Effect1)
  175.     _GDIPlus_BitmapApplyEffect($hBitmap, $Effect2)
  176.  
  177.     For $x = Round($bitmapW / 4.62) To $bitmapW - $bitmapW / 10 step 2
  178.  
  179.         For $y = $bitmapH / 24 To Round($bitmapH / 2.5) Step 2
  180.  
  181.             $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
  182.  
  183.             If $RGB <= $threshHold Then
  184.                 $RGB = 0
  185.                 For $i = 1 To 15
  186.                     $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $x, $y + $i)
  187.                 Next
  188.  
  189.                 If $RGB / 15 < $threshHold Then
  190.  
  191.                     $RGB = 0
  192.                     For $ix = 1 To 5
  193.                         $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $x + $ix, $y)
  194.                     Next
  195.  
  196.                     If $RGB / 5 < $threshHold Then
  197.                         $lx = $x
  198.                         $ly = $y
  199. ;~                      While _GDIPlus_BitmapGetPixel($hBitmap, $lx-1, $ly) < $threshHold
  200. ;~                          $lx -= 1
  201. ;~                      WEnd
  202. ;~                      While _GDIPlus_BitmapGetPixel($hBitmap, $lx, $ly - 1) < $threshHold
  203. ;~                          $ly -= 1
  204. ;~                      WEnd
  205.                         $ret[0] = $lx
  206.                         $ret[1] = $lY
  207.                         _GDIPlus_BitmapDispose($hBitmap)
  208.                         Return $ret
  209.                     EndIf
  210.                 Else
  211.                     $y += $i - 1
  212.                 EndIf
  213.  
  214.             EndIf
  215.         Next
  216.     Next
  217.     _GDIPlus_BitmapDispose($hBitmap)
  218. EndFunc
  219.  
  220.  
  221. Func __StartUp()
  222.  
  223.     _GDIPlus_Startup()
  224.  
  225.     $hNox = WinGetHandle("NoxPlayer")
  226.     WinActivate($hNox)
  227.     $screenDC = _WinAPI_GetDC($hNox)
  228. ;~     $screenDC = _WinAPI_GetDC(0)
  229.     $hDC = _WinAPI_GetDC($GUI)
  230.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
  231.  
  232.     $buffer = _WinAPI_CreateCompatibleDC($hDC)
  233.     _WinAPI_SelectObject($buffer, $hHBitmap)
  234.  
  235.     $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
  236.     _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
  237.     _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
  238.  
  239.     $penRed = _GDIPlus_PenCreate(0xFFFF0000, 3)
  240.     $penYellow = _GDIPlus_PenCreate(0xFFFFFF00, 3)
  241.     $penGreen = _GDIPlus_PenCreate(0xFF00FF00, 3)
  242.     $penBlue = _GDIPlus_PenCreate(0xFF0000FF, 10)
  243.  
  244.     $Effect1 = _GDIPlus_EffectCreateHueSaturationLightness(0, -100)
  245.     $Effect2 = _GDIPlus_EffectCreateSharpen(0, 100)
  246. EndFunc
  247.  
  248. Func BitmapFit($bitmap, $fitW, $fitH)
  249.  
  250.     Local $w = _GDIPlus_ImageGetWidth($bitmap), $new_w
  251.     Local $h = _GDIPlus_ImageGetHeight($bitmap), $new_h
  252.     Local $derv_w = ___positive($w - $fitW)
  253.     Local $derv_h = ___positive($h - $fith)
  254.  
  255.     If $derv_w >= $derv_h Then
  256.  
  257.         $new_w = $fitW
  258.         $new_h = $h / ($w / $fitW)
  259.         $new_x = 0
  260.         $new_y = $fitH / 2 - $new_h / 2
  261.     Else
  262.         $new_h = $fitH
  263.         $new_w = $w / ($h / $fitH)
  264.         $new_y = 0
  265.         $new_x = $fitW / 2 - $new_w / 2
  266.     EndIf
  267.  
  268.  
  269.     Local $ret[4] = [$new_x, $new_y, $new_w, $new_h]
  270.  
  271.     Return $ret
  272. EndFunc
  273.  
  274. Func ScreenToBitmap($hDC, $x, $y, $w, $h)
  275.  
  276.     Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
  277.     Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
  278.     _WinAPI_SelectObject($tDC, $hBMP)
  279.     _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
  280.  
  281.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
  282.  
  283.     _WinAPI_DeleteObject($hBMP)
  284.     _WinAPI_DeleteDC($tDC)
  285. ;~     Return $hBMP
  286.     Return $hBitmap
  287. EndFunc
  288.  
  289.  
  290. Func ___positive($x)
  291.     Return $x < 0 ? -$x : $x
  292. EndFunc
  293.  
  294. Func __minmax($x, $min, $max)
  295.     Return ($x - $min) / ($max - $min)
  296. EndFunc
  297.  
  298. Func __map($x, $min1, $max1, $min2, $max2)
  299.     If $max2 > $min2 Then
  300.         Return __minmax($x, $min1, $max1) * ($max2 - $min2) + $min2
  301.     Else
  302.         Return  (1 - __minmax($x, $min1, $max1)) * ($min2 - $max2) + $max2
  303.     EndIf
  304. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement