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>
- HotKeySet("{ESC}","_exit")
- Func _exit()
- Exit
- EndFunc
- Global $screenDC, $gfxContext, $hDC, $hHBitmap, $buffer
- Global $penRed, $penYellow, $penGreen
- Global $GUI, $GUI_W = 600, $GUI_H = 600
- Global $screenW = @DesktopWidth, $screenH = @DesktopHeight
- $GUI = GUICreate("Captcha", $GUI_W, $GUI_H)
- __StartUp()
- GUISetState()
- WinSetOnTop($GUI,"", True)
- ;~ _GDIPlus_GraphicsClear($gfx)
- ;~ _GDIPlus_GraphicsDrawImage($gfx, _Captcha_GetHidden($img), 0, 0)
- ;~ Sleep(3000)
- ;~ MsgBox(0,"",PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x64CC02)[0])
- $Effect1 = _GDIPlus_EffectCreateHueSaturationLightness(0, -100)
- ;~ $Effect2 = _GDIPlus_EffectCreateBrightnessContrast(0, -50)
- $Effect2 = _GDIPlus_EffectCreateSharpen(255, 80)
- ;~ _GDIPlus_EffectCreateColorBalance(
- $search = -1
- While 1
- $cursor = GUIGetCursorInfo($GUI)
- If GUIGetMsg() = - 3 Then Exit
- _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
- $bitmap = ScreenToBitmap($screenDC, 0, 0, @DesktopWidth, @DesktopHeight)
- $search2 = PixelSearch(0, 0, @DesktopWidth, @DesktopHeight, 0x64CC02)
- If $search = -1 And IsArray($search2) Then $search = $search2
- If IsArray($search2) Then
- $bitmap = _GDIPlus_BitmapCloneArea($bitmap, $search[0] - 35, $search[1] - 200, 280, 280)
- $slidepos = _Captcha_GetHidden($bitmap)
- $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, 280, 280)
- _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)
- If IsArray($slidepos) Then
- $posX = __map($slidepos[0], 0, 280, 0, $GUI_W)
- $posY = __map($slidepos[1], 0, 280, 0, $GUI_H)
- _GDIPlus_GraphicsDrawRect($gfxContext, $posX, $posY, 90, 80, $penYellow)
- _GDIPlus_GraphicsDrawLine($gfxContext, $posX, 0, $posX, $GUI_H, $penGreen)
- EndIf
- _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
- ;~ If IsArray($slidepos) Then MouseClickDrag("left", $search[0], $search[1], $search[0] + $slidepos[0] - 15, $search[1], 0)
- ;~ ToolTip(Round(__map($cursor[0], 0, $GUI_W, 0, 280)) & " " & Round(__map($cursor[1], 0, $GUI_H, 0, 280)))
- Else
- $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, @DesktopWidth, @DesktopHeight)
- _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
- EndIf
- _GDIPlus_BitmapDispose($bitmap)
- 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]
- Local $threshHold = Number("0xFF232323", 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 1
- For $y = $bitmapH / 24 To Round($bitmapH / 1.86) Step 5
- $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y)
- If $RGB <= $threshHold Then
- ;~ Exit
- For $i = 1 To 10
- $RGB = _GDIPlus_BitmapGetPixel($hBitmap, $x, $y + $i)
- If $RGB > $threshHold Then ExitLoop
- Next
- If $i = 10 Then
- ;~ If $ix = 5 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
- Return $ret
- ;~ EndIf
- Else
- $y += $i - 1
- EndIf
- EndIf
- Next
- Next
- EndFunc
- Func __StartUp()
- _GDIPlus_Startup()
- $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)
- 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