Advertisement
Guest User

Untitled

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