Advertisement
Guest User

Untitled

a guest
Apr 5th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 6.91 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.  
  8. HotKeySet("{ESC}","_exit")
  9. Func _exit()
  10.     Exit
  11. EndFunc
  12.  
  13. Global $screenDC, $gfxContext, $hDC, $hHBitmap, $buffer
  14. Global $penRed, $penYellow, $penGreen
  15. Global $GUI, $GUI_W = 600, $GUI_H = 600
  16. Global $screenW = @DesktopWidth, $screenH = @DesktopHeight
  17.  
  18.  
  19. $GUI = GUICreate("Captcha", $GUI_W, $GUI_H)
  20. __StartUp()
  21. GUISetState()
  22. WinSetOnTop($GUI,"", True)
  23.  
  24.  
  25. ;~ _GDIPlus_GraphicsClear($gfx)
  26. ;~ _GDIPlus_GraphicsDrawImage($gfx, _Captcha_GetHidden($img), 0, 0)
  27. ;~ Sleep(3000)
  28. ;~ MsgBox(0,"",PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x64CC02)[0])
  29.  
  30. $Effect1 = _GDIPlus_EffectCreateHueSaturationLightness(0, -100)
  31. ;~ $Effect2 = _GDIPlus_EffectCreateBrightnessContrast(0, -50)
  32. $Effect2 = _GDIPlus_EffectCreateSharpen(255, 80)
  33. ;~ _GDIPlus_EffectCreateColorBalance(
  34. $search = False
  35. While 1
  36.  
  37.     $cursor = GUIGetCursorInfo($GUI)
  38.     If GUIGetMsg() = - 3 Then Exit
  39.  
  40.     _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
  41.  
  42.     $bitmap = ScreenToBitmap($screenDC, 0, 0, @DesktopWidth, @DesktopHeight)
  43.  
  44.     If IsArray($search) = False Then $search = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x64CC02)
  45.     If IsArray(PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x64CC02)) Then
  46.  
  47.         $bitmap = _GDIPlus_BitmapCloneArea($bitmap, $search[0] - 35, $search[1] - 200, 280, 280)
  48.  
  49.         $slidepos = _Captcha_GetHidden($bitmap)
  50.         $pos = BitmapFit($bitmap, $GUI_W, $GUI_H)
  51.  
  52.         _GDIPlus_GraphicsDrawImagePointsRect($gfxContext, $bitmap, $pos[0], $pos[1], $pos[0] + $pos[2], $pos[1], $pos[0], $pos[1] + $pos[3], 0, 0, 280, 280)
  53.         _GDIPlus_GraphicsDrawRect($gfxContext, __map(5, 0, 280, 0, $GUI_W), __map(180, 0, 280, 0, $GUI_H), __map(55, 0, 280, 0, $GUI_W), __map(55, 0, 280, 0, $GUI_W), $penRed)
  54.  
  55.         If IsArray($slidepos) Then
  56.             $posX = __map($slidepos[0], 0, 280, 0, $GUI_W)
  57.             $posY = __map($slidepos[1], 0, 280, 0, $GUI_H)
  58.             _GDIPlus_GraphicsDrawRect($gfxContext, $posX, $posY, 60, 60, $penYellow)
  59.             _GDIPlus_GraphicsDrawLine($gfxContext, $posX, 0, $posX, $GUI_H, $penGreen)
  60.         EndIf
  61.  
  62.         _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
  63.         If IsArray($slidepos) Then MouseClickDrag("left", $search[0], $search[1], $search[0] + $slidepos[0] - 15, $search[1], 0)
  64.  
  65. ;~      ToolTip(Round(__map($cursor[0], 0, $GUI_W, 0, 280)) & "    " & Round(__map($cursor[1], 0, $GUI_H, 0, 280)))
  66.  
  67.  
  68.     Else
  69.  
  70.         $pos = BitmapFit($bitmap, $GUI_W, $GUI_H)
  71.         _GDIPlus_GraphicsDrawImagePointsRect($gfxContext, $bitmap, $pos[0], $pos[1], $pos[0] + $pos[2], $pos[1], $pos[0], $pos[1] + $pos[3], 0, 0, @DesktopWidth, @DesktopHeight)
  72.  
  73.         _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
  74.  
  75.     EndIf
  76.  
  77.  
  78.  
  79.     _GDIPlus_BitmapDispose($bitmap)
  80. WEnd
  81.  
  82. Func _GDIPlus_GraphicsDrawImageRectRectIA($hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight, $hImageAttributes = 0, $iUnit = 2)
  83.     Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipDrawImageRectRect", "handle", $hGraphics, "handle", $hImage, "float", $nDstX, "float", _
  84.             $nDstY, "float", $nDstWidth, "float", $nDstHeight, "float", $nSrcX, "float", $nSrcY, "float", $nSrcWidth, "float", _
  85.             $nSrcHeight, "int", $iUnit, "handle", $hImageAttributes, "int", 0, "int", 0)
  86.     If @error Then Return SetError(@error, @extended, False)
  87.     Return $aResult[0] = 0
  88. EndFunc   ;==>_GDIPlus_GraphicsDrawImageRectRectIA
  89.  
  90. Func _Captcha_GetHidden($hBitmap)
  91.  
  92.     Local $RGB, $bitmapW = _GDIPlus_ImageGetWidth($hBitmap), $bitmapH = _GDIPlus_ImageGetHeight($hBitmap)
  93.     Local $lowest = 0xFFFFFFFFffff, $lX, $lY = $bitmapH, $ret[2]
  94.     Local $threshHold = Number("0xFF101010", 3), $threshHold2 = Number("0xFFeeeeee", 3)
  95.  
  96.     _GDIPlus_BitmapApplyEffect($bitmap, $Effect1)
  97.     _GDIPlus_BitmapApplyEffect($bitmap, $Effect2)
  98.  
  99.  
  100. ;~  For $x = Round($bitmapW / 4.62) To $bitmapW  - $bitmapW / 10 step 1
  101.  
  102. ;~      For $y = $bitmapH / 24 To Round($bitmapH / 1.66) Step 1
  103.  
  104. ;~          $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
  105.  
  106. ;~          If $RGB < $lowest Then
  107. ;~              $lowest = $RGB
  108. ;~              $lX = $x
  109. ;~              $lY = $y
  110. ;~          EndIf
  111. ;~      Next
  112. ;~  Next
  113.  
  114.     For $y = $bitmapH / 24 To Round($bitmapH / 1.86) Step 1
  115.  
  116.         For $x = Round($bitmapW / 4.62) To $bitmapW  - $bitmapW / 10 step 1
  117.  
  118.             $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
  119.  
  120.             If $RGB <= $threshHold Then
  121. ;~              Exit
  122.  
  123.                 $RGB = 0
  124.                 For $i = 1 To 10
  125.  
  126.                     $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $x + $i, $y)
  127.                 Next
  128.                 $RGB /= 10
  129.                 If $RGB <= $threshHold Then
  130.  
  131.                     $RGB = 0
  132.                     For $i = Round($bitmapW / 20) + 5 To Round($bitmapW / 20) + 14
  133.  
  134.                         $RGB += _GDIPlus_BitmapGetPixel($hBitmap, $i, $y + 1)
  135.                     Next
  136.                     $RGB /= 10
  137.                     If $RGB >= $threshHold2 Then
  138.  
  139. ;~  ;~              If $i = $bitmapW / 20 + 5 Then
  140.                         $lx = $x
  141.                         $ly = $y
  142.                         $ret[0] = $lx
  143.                         $ret[1] = $lY
  144.                         Return $ret
  145.                     EndIf
  146.                 EndIf
  147.             EndIf
  148.         Next
  149.     Next
  150.  
  151.  
  152. EndFunc
  153.  
  154.  
  155. Func __StartUp()
  156.  
  157.     _GDIPlus_Startup()
  158.  
  159.     $screenDC = _WinAPI_GetDC(0)
  160.     $hDC = _WinAPI_GetDC($GUI)
  161.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
  162.  
  163.     $buffer = _WinAPI_CreateCompatibleDC($hDC)
  164.     _WinAPI_SelectObject($buffer, $hHBitmap)
  165.  
  166.     $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
  167.     _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
  168.     _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
  169.  
  170.     $penRed = _GDIPlus_PenCreate(0xFFFF0000, 3)
  171.     $penYellow = _GDIPlus_PenCreate(0xFFFFFF00, 3)
  172.     $penGreen = _GDIPlus_PenCreate(0xFF00FF00, 3)
  173. EndFunc
  174.  
  175. Func BitmapFit($bitmap, $fitW, $fitH)
  176.  
  177.     Local $w = _GDIPlus_ImageGetWidth($bitmap), $new_w
  178.     Local $h = _GDIPlus_ImageGetHeight($bitmap), $new_h
  179.     Local $derv_w = ___positive($w - $fitW)
  180.     Local $derv_h = ___positive($h - $fith)
  181.  
  182.     If $derv_w >= $derv_h Then
  183.  
  184.         $new_w = $fitW
  185.         $new_h = $h / ($w / $fitW)
  186.         $new_x = 0
  187.         $new_y = $fitH / 2 - $new_h / 2
  188.     Else
  189.         $new_h = $fitH
  190.         $new_w = $w / ($h / $fitH)
  191.         $new_y = 0
  192.         $new_x = $fitW / 2 - $new_w / 2
  193.     EndIf
  194.  
  195.  
  196.     Local $ret[4] = [$new_x, $new_y, $new_w, $new_h]
  197.  
  198.     Return $ret
  199. EndFunc
  200.  
  201. Func ScreenToBitmap($hDC, $x, $y, $w, $h)
  202.  
  203.     Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
  204.     Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
  205.     _WinAPI_SelectObject($tDC, $hBMP)
  206.     _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
  207.  
  208.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
  209.  
  210.     _WinAPI_DeleteObject($hBMP)
  211.     _WinAPI_DeleteDC($tDC)
  212. ;~     Return $hBMP
  213.     Return $hBitmap
  214. EndFunc
  215.  
  216.  
  217. Func ___positive($x)
  218.     Return $x < 0 ? -$x : $x
  219. EndFunc
  220.  
  221. Func __minmax($x, $min, $max)
  222.     Return ($x - $min) / ($max - $min)
  223. EndFunc
  224.  
  225. Func __map($x, $min1, $max1, $min2, $max2)
  226.     If $max2 > $min2 Then
  227.         Return __minmax($x, $min1, $max1) * ($max2 - $min2) + $min2
  228.     Else
  229.         Return  (1 - __minmax($x, $min1, $max1)) * ($min2 - $max2) + $max2
  230.     EndIf
  231. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement