Advertisement
Guest User

Untitled

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