-
Posts
3,052 -
Joined
-
Last visited
-
Days Won
14
junkew's Achievements
-
Remap right mouse dragging as left mouse dragging?
junkew replied to VAN0's topic in AutoIt General Help and Support
https://www.autoitscript.com/autoit3/docs/libfunctions/_WinAPI_SetWindowsHookEx.htm -
DLLCall fails in AutoIt but works in VB6
junkew replied to TimRude's topic in AutoIt General Help and Support
To make it complete. The BSTR has a definition: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/automat/bstr?redirectedfrom=MSDN And some nice topic on many variable types was made by @LarsJ -
Werty reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Waiting for the fasm version and see if OP gets any version 100% running. -
Werty reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Yes offcourse 🙃🤫 -
junkew reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
@Werty tried to run your example but only get 1111 as a result for 9.png see below my reproducing script. Could not directly see why it gives 1111 instead of 9142 or was this about getting the exact $posx and $posy right Maybe I am miscalculating 100,100 for the form +16,16 for the drawImageRect. #include <GDIPlus.au3> #include <WinAPI.au3> HotKeySet("{ESC}", "_exit") ;Be sure $posx and $posy is pointing at the correct spot! Global $posx = 116 + 29 + 3, $posy = 116 + 32 + 12 , $result = "", $code[4], $capture, $pixels = DllStructCreate('dword[2816]') ;Lookup table to avoid searching Global $digit[115] = [1,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0, _ 0,0,0,0,0,0,0,0,0,0,6,0,0,0,3,2,0,0,0,0, _ 0,0,0,0,0,0,0,0,9,0,0,0,0,0,8,0,0,0,0,0, _ 0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,5] ;Test section ;-------------------------------------------------------------- $gui = GUICreate("Getnumber", 640, 480, 100, 100) GUISetState() WinWaitActive($gui); <--- necessary or screencapture fails _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($gui) $image = _GDIPlus_BitmapCreateFromFile(@UserProfileDir & "\downloads\examples\" & "9.png") _GDIPlus_GraphicsDrawImageRect($graphics, $image, 16, 16, 176, 56) Sleep(250); <------- necessary because drawimagerect() is too slow, script occasionally fails without ;-------------------------------------------------------------- ;/Test section ;~ $hDDC = _WinAPI_GetDC(0) ;should be ;~ $hDDC = _WinAPI_GetWindowDC($tool) $hDDC = _WinAPI_GetDC($gui) $hCDC = _WinAPI_CreateCompatibleDC($hDDC) $capture = _WinAPI_CreateCompatibleBitmap($hDDC, 88, 32) _WinAPI_SelectObject($hCDC, $capture) _WinAPI_BitBlt($hCDC, 0, 0, 88, 32, $hDDC, $posx, $posy, 0x00CC0020) _WinAPI_DeleteDC($hCDC) Sleep(250) local $t2 = TimerInit() $result = Getnumber($result) Consolewrite("Time: " & TimerDiff($t2) & @crlf) Consolewrite("Result: " & $result & @crlf) While 1 Sleep(10) WEnd Func Getnumber($result) Local $code[4] = [0,0,0,0], $value = 64 DllCall('gdi32.dll', 'dword', 'GetBitmapBits', 'ptr', $capture, 'dword', DllStructGetSize($pixels), 'ptr', DllStructGetPtr($pixels)) For $loop = 1 To 2816 Step 440 $code[0] += DllStructGetData($pixels, 1, $loop ) > 4278190080 ? $value:0 $code[1] += DllStructGetData($pixels, 1, $loop+29) > 4278190080 ? $value:0 $code[2] += DllStructGetData($pixels, 1, $loop+58) > 4278190080 ? $value:0 $code[3] += DllStructGetData($pixels, 1, $loop+87) > 4278190080 ? $value:0 $value /= 2 Next ;~ consolewrite($code[0] & $code[1] & $code[2] & $code[3]) Return String($digit[$code[0]]) & String($digit[$code[1]]) & String($digit[$code[2]]) & String($digit[$code[3]]) EndFunc Func _exit() _GDIPlus_Shutdown() Exit EndFunc -
junkew reacted to a post in a topic: Another bitmap brute-forcing thread
-
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
And a small explainer on what @Werty is doing (I am off some pixels but I hope @Hashim get the concept as indicated by the red dots) Zoom in on the image to see the 28 pixels used for comparison and understanding why its important to have the screenshots exactly aligned. -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
4 digits is 10.000 numbers, why try 1,000,000 times? Speed optimization. Why? In general its fun to try in AutoIt but if speed is needed switch to a compiled language _WinAPI_HashString($stringforDigit,false,2) to get a 2 byte hash, easier to compare, no clue if its faster Most likely a boundary issue? 88*32 =2816 pixels then it depends on the goal of the for loop to 2816 with step 440 if you want to hit 7 or 8 bits 1 441 881 1321 1761 2201 2602 (3003) Not sure if 7 or 8 bits make a difference in the first column of a digit. I assume 7 would be enough to have 4 digits in 28 comparisons In my example demo code I scale down to 8x8 bits Why dinner first? 😉 ... -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Just hover with au3inf over the window or control and post that info. It will help a lot if we know the name, type of control. -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Your 2nd picture you can even see better you are off a few pixels as at the right I can see pixels of the digit thats not visible. -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Your 4 is cut to early. Make sure your numbers all are same width. The matrix for 1 digit should fit 3 times for three numbers. -
junkew reacted to a post in a topic: Another bitmap brute-forcing thread
-
Werty reacted to a post in a topic: Another bitmap brute-forcing thread
-
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Regarding speed maybe it makes a difference with stretchblt directly going to a smaller size instead of bitblt Example for screenshot in a smaller size. #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Func CaptureAndResize($savePath, $newWidth, $newHeight) ; GDI+ initialiseren _GDIPlus_Startup() ; Schermresolutie ophalen Local $iScreenWidth = @DesktopWidth Local $iScreenHeight = @DesktopHeight ; HDC's ophalen Local $hDC = _WinAPI_GetDC(0) Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) ; Bitmap maken Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iScreenWidth, $iScreenHeight) Local $hOldObj = _WinAPI_SelectObject($hMemDC, $hBitmap) ; Scherminhoud kopiëren met StretchBlt (resize mogelijk) _WinAPI_StretchBlt($hMemDC, 0, 0, $newWidth, $newHeight, $hDC, 0, 0, $iScreenWidth, $iScreenHeight, $SRCCOPY) ; Screenshot opslaan als bestand _ScreenCapture_SaveImage($savePath, $hBitmap) ; Opruimen _WinAPI_SelectObject($hMemDC, $hOldObj) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) _WinAPI_ReleaseDC(0, $hDC) _GDIPlus_Shutdown() EndFunc ; Gebruik de functie om een screenshot te maken en te resizen naar 800x600 CaptureAndResize(@UserProfileDir & "\downloads\examples\" & "screenshot_resized.jpg", 800, 600) -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
Cleaned up demo script Added some choices in the GUI to play around with understanding on whats happening with bits, bytes, string 8x8 resizing to compare less bits #include <GDIPlus.au3> #include <WinAPI.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> ;~ These are the magic bytes for the 8x8 resized image to identify the numbers 0-9 ;~ You can learn them by feeding 10 images having 0-9 at the 1 position (so 2nd character as first is a space global $digits[10] = [ _ '0x0002222002000022020002220200202002002020022000202200002000222200', _ '0x0000200000222000000020000000200000022000000200000002000000222200', _ '0x0002222002000022000000220000220000002200002000002200000022222220', _ '0x0002222002000022000000220000220000002200000000202200002000222200', _ '0x0000022000002200002202000200020002000200022222200000220000002200', _ '0x0222222202000000022222000000002000000020000000202200002000222200', _ '0x0000222000220000020000000222220002222200020000202200002000222200', _ '0x0222222200000022000002000000200000002000002000000020000000200000', _ '0x0002222002000022020000220022220000222200020000202200002000222200', _ '0x0002222002000022020000220022222200222220000000200000220000220000' _ ] local $charWidth=29 ;~Important as thats the width of te consecutive digits on screen ;~ Dont move the window during analysis as then the calculation of the matrix will be off as we dont recalculate every time dim $bmpData, $w, $h, $s dim $pic[10],$BitmapFilename, $hImage, $Bmp ; Initialize GDI+ library _GDIPlus_Startup() #Region ### START Koda GUI section ### Form= $frmCompare = GUICreate("Another bitmap brute-forcing thread", 1280, 768, 193, 125) ;~ Put all the pictures on screen for $picId=0 to 9 $BitmapFilename = @UserProfileDir & "\downloads\examples\" & string($picId) & ".png" $pBitmap = _GDIPlus_BitmapCreateFromFile($BitmapFilename) $hImage=_GDIPlus_ImageLoadFromFile($BitmapFilename) $Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) ;~ $hBitmap = _GDIPlus_ImageLoadFromFile($BMPFile) $Pic[$picId] = GUICtrlCreatePic("", 32, 24+($picId*60), 100, 100, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) _WinAPI_DeleteObject(GUICtrlSendMsg($Pic[$picId], $STM_SETIMAGE, $iMAGE_BITMAP, $Bmp)) Next ;~ Box for analyzing showing the information $editBox = GuiCtrlCreateEdit("Analytics box", 450,14,700,750) GUICtrlSetFont($editBox, 8, 100, 0, "Courier New") Local $idLearnCheckbox = GUICtrlCreateCheckbox("Learn the digits", 44, 640, 125, 25) Local $idShowCheckbox = GUICtrlCreateCheckbox("Show the bits/highlight", 44, 672, 125, 25) Local $idSlowCheckbox = GUICtrlCreateCheckbox("Slow down", 44, 704, 95, 25) $ButtonAnalyze = GUICtrlCreateButton("Analyze", 44, 730, 75, 25, 0) $Button2 = GUICtrlCreateButton("Button2", 104, 730, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #region ### While the GUI ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit Case $ButtonAnalyze analyse(_IsChecked($idLearnCheckbox), _IsChecked($idShowCheckbox), _IsChecked($idSlowCheckbox)) Case $Button2 EndSwitch WEnd #EndRegion Func _IsChecked($idControlID) Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED EndFunc ;==>_IsChecked func analyse($learnTheDigits=false, $showDigits=true, $slowDown=false) ;~ local $learnTheDigits=false ;~Use this to learn the 0-9 digit magic values ;~ local $showDigits=true ;~ For showing the bits in detail to show whats happening ;~ local $slowDown=false ;~ With or without sleep waiting local $charLow=1, $charHigh=1 ;~ For learning which areas to analyse WinActivate($frmCompare) Local $wPos = WinGetPos($frmCompare) ;~ $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width $aArray[3] = Height Local $aClientSize = WinGetClientSize($frmCompare) ;~ $aArray[0] = Width of window's client area $aArray[1] = Height of window's client area Local $cLeft= ($wpos[2]-$aClientSize[0])/2 Local $cTop= ($wPos[3]-$aClientSize[1])-2 Local $bytesPerDigit = 1 ;~ could be 1 or 2 or 3 bytes for $picId=0 to 9 Local $cPos = ControlGetPos ( $frmCompare, "", $pic[$picId] ) ;~ $aArray[0] = X position ;~ $aArray[1] = Y position ;~ $aArray[2] = Width ;~ $aArray[3] = Height if ($learnTheDigits = false) Then $charLow=0 $charHigh=5 EndIf for $charId=$charlow to $charHigh ;~ Calculate the matrix where the digit is based on the control where the picture is in, as absolute coordinates so window location also in the calculation local $leftMatrix=($charId*$charWidth)+$wpos[0]+$cLeft+$cPos[0] local $rightMatrix=$charWidth+($charId*$charWidth)+$wPos[0]+$cLeft+$cPos[0] local $topMatrix= $wPos[1] + $cTop +$cPos[1] + 10 local $bottomMatrix=$wPos[1] + $cTop + $cPos[1] + $cPos[3] -2 -11 local $x, $y Local $bytesDataForDigit="", $widthMatrix=0, $heightMatrix=0, $stride=0 ;~ Func GetImageDataFromScreen($left, $right, $top, $bottom, byref $BMPDataStart, byref $Width, byRef $Height, byref $Stride, $picIdmgBytes=3) ;~Play with this to take a smaller area GetImageDataFromScreen($leftMatrix, $topMatrix, $rightMatrix, $bottomMatrix, $bytesDataForDigit, $widthMatrix, $heightMatrix, $stride, $bytesPerDigit) ;~ consolewrite(BinaryLen($bytesDataForDigit) & " " & stringlen($bytesDataForDigit) & " " & $widthMatrix & "-" & $heightMatrix & "-" & $stride &@CRLF) local $stringForDigit=string($bytesDataForDigit) if ($learnTheDigits=true) then consolewrite("'" & $stringforDigit & "', _") Else $num=getNumber($stringForDigit) consolewrite($num) EndIf if ($showDigits=true) then showDigitInEditbox($stringForDigit, $heightMatrix, $stride) ;~ Not working propertly? ;~ local $checkSum=PixelChecksum($leftMatrix, $rightMatrix , $topMatrix, $bottomMatrix, 1, 0 ,1) ;~ Just draw a redbox around what we are analysing ;~ Minus 4 just as it influences the next screenshot _Screen_DrawRect( $leftMatrix, $rightMatrix-4 , $topMatrix, $bottomMatrix) if $SlowDown then SLEEP (100) EndIf Next consolewrite(@crlf) Next EndFunc func showDigitInEditbox($stringForDigit, $heightMatrix, $stride) local $textoutput $textOutput=stringmid($stringForDigit,3) $textOutput=StringRegExpReplace($textOutput,"[0-9a-z]{8}","$0"&@CRLF) $textOutput=StringReplace($textoutput,"0",".") ;~ $textOutput=StringRegExpReplace($textOutput,"[1-9A-Za-z]+","X") ControlSetText("","",$editBox,$textOutput) EndFunc func getNumber($stringForDigit) local $num=" " for $i=0 to 9 if ($digits[$i]=$stringForDigit) then return $i next return $num EndFunc Func GetImageDataFromScreen($left, $top, $right, $bottom, byref $BMPDataStart, byref $Width, byRef $Height, byref $Stride, $picIdmgBytes=3) local $Scan0, $pixelData, $hbScreen, $pBitmap, $pBitmapCap, $handle, $bitMapdata, $pixelFormat ; Capture screen to load the bitmap to search in ;~ _ScreenCapture_Capture(@UserProfileDir & "\downloads\examples\test.png",$left, $top, $right, $bottom,False) ;~ _ScreenCapture_Capture("",$left, $top, $right, $bottom,False) $hbScreen=_ScreenCapture_Capture("",$left, $top, $right, $bottom,False) local $pBitmap1 = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen); returns memory bitmap _WinAPI_DeleteObject($hbScreen) ;release GDI bitmap resource because not needed anymore Local $pBitmap= _GDIPlus_ImageResize($pBitmap1, 8, 8) ;resize image ;~ Local $pBitmap= _GDIPlus_ImageResize($pBitmap1, 4, 4) ;resize image ;~ Local $pBitmap= _GDIPlus_ImageScale($pBitmap1, 0.15, 0.15) ;resize image ;Get $tagGDIPBITMAPDATA structure ;~ ConsoleWrite("Bitmap Width: " & _GDIPlus_ImageGetWidth($pBitmap) & @CRLF ) ;~ ConsoleWrite("Bitmap Height: " & _GDIPlus_ImageGetHeight($pBitmap) & @CRLF) ;~ 24 bits (3 bytes) or 16 bits (2 bytes) comparison or 1 byte local $iFormat=$GDIP_PXF16RGB555 if ($picIdmgBytes=1) then $iFormat=$GDIP_PXF04INDEXED if ($picIdmgBytes=2) then $iFormat=$GDIP_PXF16RGB555 if ($picIdmgBytes=3) then $iFormat=$GDIP_PXF24RGB $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $iFormat) If @ERROR Then MsgBox(0,"","Error locking region " & @error) $Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up. $Width = DllStructGetData($BitmapData, "Width");Image width - Number of pixels in one scan line of the bitmap. $Height = DllStructGetData($BitmapData, "Height");Image height - Number of scan lines in the bitmap. $PixelFormat = DllStructGetData($BitmapData, "PixelFormat");Pixel format - Integer that specifies the pixel format of the bitmap $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap. $pixelData = DllStructCreate("ubyte lData[" & (abs($Stride) * $Height) & "]", $Scan0) $BMPDataStart = $BMPDataStart & DllStructGetData($pixeldata,"lData") _GDIPlus_BitmapUnlockBits($pBitmap, $BitmapData) _GDIPlus_ImageDispose ($pBitmap) _WinAPI_DeleteObject ($pBitmap) _WinAPI_DeleteObject ($hbScreen) EndFunc;==>GetImage ; Draw rectangle on screen. Func _Screen_DrawRect($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 1) Local $hDC, $hPen, $obj_orig, $x1, $x2, $y1, $y2 $x1 = $tLeft $x2 = $tRight $y1 = $tTop $y2 = $tBottom $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, $PenWidth, $color) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) _WinAPI_DrawLine($hDC, $x1, $y1, $x2, $y1) ; horizontal to right _WinAPI_DrawLine($hDC, $x2, $y1, $x2, $y2) ; vertical down on right _WinAPI_DrawLine($hDC, $x2, $y2, $x1, $y2) ; horizontal to left right _WinAPI_DrawLine($hDC, $x1, $y2, $x1, $y1) ; vertical up on left ; clear resources _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_UIA_DrawRect -
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Hashim reacted to a post in a topic: Another bitmap brute-forcing thread
-
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
And you could offcourse build a CNN (Convolutional Neural Network)😉 https://www.linkedin.com/posts/andreashorn1_𝗧𝗵𝗶𝘀-𝗶𝘀-𝗵𝗮𝗻𝗱𝘀-𝗱𝗼𝘄𝗻-𝗼𝗻𝗲-ugcPost-7294745573667037184-cCuM?utm_source=share&utm_medium=member_desktop&rcm=ACoAAAA9u1cBwzbrqlJUhZseMBnOqHDoQcSGcpQ -
Another bitmap brute-forcing thread
junkew replied to Hashim's topic in AutoIt General Help and Support
A little hard to say as it depends on what font you have bold, italic etc. As far as I can see below is not failing at any digits. This demo script would work for any number of characters as long as you teach the system how it works with the magic strings. There are many ways to speed it up (for example by taking a smaller snapshot within the digit matrix area) Script explanation It scales the bitmap back to 8*8 = 64 bytes and just compares the string (Scaling smaller did not work with initial testing) Local $pBitmap= _GDIPlus_ImageResize($pBitmap1, 8, 8) ;resize image Get the magic numbers local $learnTheDigits=false ;~Use this to learn the 0-9 digit magic values Paste the magic lines (by just comparing the magic numbers as string, speed could be improved by comparing the binary values) if ($stringForDigit='0x00022220020000220200022202002020020020200220002022000020002222') then $num=0 if ($stringForDigit='0x00002000002220000000200000002000000220000002000000020000002222') then $num=1 if ($stringForDigit='0x00022220020000220000002200002200000022000020000022000000222222') then $num=2 if ($stringForDigit='0x00022220020000220000002200002200000022000000002022000020002222') then $num=3 if ($stringForDigit='0x00000220000022000022020002000200020002000222222000002200000022') then $num=4 if ($stringForDigit='0x02222222020000000222220000000020000000200000002022000020002222') then $num=5 if ($stringForDigit='0x00002220002200000200000002222200022222000200002022000020002222') then $num=6 if ($stringForDigit='0x02222222000000220000020000002000000020000020000000200000002000') then $num=7 if ($stringForDigit='0x00022220020000220200002200222200002222000200002022000020002222') then $num=8 if ($stringForDigit='0x00022220020000220200002200222222002222200000002000002200002200') then $num=9 Iterate 6 digits (or 7,8,9) $charHigh=5 ;~ As it starts counting from 0 Do it full speed / turning of the explainer part local $showDigits=false full script #include <GDIPlus.au3> #include <WinAPI.au3> #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ScreenCapture.au3> dim $bmpData, $w, $h, $s dim $pic[10],$BitmapFilename, $hImage, $Bmp ; Initialize GDI+ library _GDIPlus_Startup() #Region ### START Koda GUI section ### Form= $frmCompare = GUICreate("Another bitmap brute-forcing thread", 1024, 768, 193, 125) for $picId=0 to 9 $BitmapFilename = @UserProfileDir & "\downloads\examples\" & string($picId) & ".png" $pBitmap = _GDIPlus_BitmapCreateFromFile($BitmapFilename) $hImage=_GDIPlus_ImageLoadFromFile($BitmapFilename) $Bmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) ;~ $hBitmap = _GDIPlus_ImageLoadFromFile($BMPFile) ;~ ConsoleWrite("Bitmap Width: " & _GDIPlus_ImageGetWidth($pBitmap) & @CRLF ) ;~ ConsoleWrite("Bitmap Height: " & _GDIPlus_ImageGetHeight($pBitmap) & @CRLF) $Pic[$picId] = GUICtrlCreatePic("", 32, 24+($picId*60), 100, 100, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) _WinAPI_DeleteObject(GUICtrlSendMsg($Pic[$picId], $STM_SETIMAGE, $iMAGE_BITMAP, $Bmp)) Next $editBox = GuiCtrlCreateEdit("Analytics box", 250,14,700,750) GUICtrlSetFont($editBox, 8, 100, 0, "Courier New") $Button1 = GUICtrlCreateButton("Analyse", 104, 700, 75, 25, 0) $Button2 = GUICtrlCreateButton("Button2", 104, 730, 75, 25, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $picIdWidth=100 $picIdHeight=100 $picIdX=0 $picIdY=0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit Case $Button1 analyse() Case $Button2 EndSwitch WEnd func analyse() WinActivate($frmCompare) Local $wPos = WinGetPos($frmCompare) ;~ $aArray[0] = X position $aArray[1] = Y position $aArray[2] = Width $aArray[3] = Height Local $aClientSize = WinGetClientSize($frmCompare) ;~ $aArray[0] = Width of window's client area $aArray[1] = Height of window's client area Local $cLeft= ($wpos[2]-$aClientSize[0])/2 Local $cTop= ($wPos[3]-$aClientSize[1])-2 Local $bytesPerDigit = 1 ;~ could be 1 or 2 or 3 bytes for $picId=0 to 9 Local $cPos = ControlGetPos ( $frmCompare, "", $pic[$picId] ) ;~ $aArray[0] = X position ;~ $aArray[1] = Y position ;~ $aArray[2] = Width ;~ $aArray[3] = Height ;~ ;~ $tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 1 ;~ _Screen_DrawRect($wpos[0]+$cLeft+$cPos[0],$wPos[0]+$cPos[0] + $cPos[2], $wPos[1] + $cTop +$cPos[1], $wPos[1] + $cTop + $cPos[1] + $cPos[3]) local $learnTheDigits=false ;~Use this to learn the 0-9 digit magic values local $showDigits=true local $charLow=1, $charHigh=1 if ($learnTheDigits = false) Then $charLow=0 $charHigh=5 EndIf for $charId=$charlow to $charHigh local $charWidth=29 local $leftMatrix=($charId*$charWidth)+$wpos[0]+$cLeft+$cPos[0] local $rightMatrix=$charWidth+($charId*$charWidth)+$wPos[0]+$cLeft+$cPos[0] local $topMatrix= $wPos[1] + $cTop +$cPos[1] + 10 local $bottomMatrix=$wPos[1] + $cTop + $cPos[1] + $cPos[3] -2 -11 local $x, $y Local $bytesForDigit="", $widthMatrix=0, $heightMatrix=0, $stride=0 ;~ Func GetImageDataFromScreen($left, $right, $top, $bottom, byref $BMPDataStart, byref $Width, byRef $Height, byref $Stride, $picIdmgBytes=3) ;~Play with this to take a smaller area GetImageDataFromScreen($leftMatrix, $topMatrix, $rightMatrix, $bottomMatrix, $bytesForDigit, $widthMatrix, $heightMatrix, $stride, $bytesPerDigit) ;~ consolewrite(BinaryLen($bytesForDigit) & " " & stringlen($bytesForDigit) & " " & $widthMatrix & "-" & $heightMatrix & "-" & $stride &@CRLF) local $textoutput= " 0 1 2 3 4 5 6 7 8 " & @CRLF $textoutput&=" 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" & @CRLF ;~ strip 0x ;~ consolewrite(stringleft(string($bytesForDigit),20)) local $stringForDigit=string($bytesForDigit) ;~ consolewrite(binarylen($bytesforDigit) & "-" & stringlen($stringforDigit) & "-" & $stringforDigit) if ($learnTheDigits=true) then consolewrite(" if ($stringForDigit='" & $stringforDigit & "') then $num=" & $picId) Else ;~ consolewrite($bytesForDigit & @crlf) ;~ consolewrite($stringForDigit & @CRLF) ;~ local $stringLine1=stringRegExpReplace($stringForDigit,"((0+2A)|(22))","") ;~ local $count1=@extended ;~ $stringline1=stringreplace($stringLine1,"0","") ;~ local $checksum=@extended-$count1 ;~ $stringline1=stringreplace($stringLine1,"222222","") ;~ $checksum+=@extended ;~ $checksum=$checksum+stringlen($stringline1) local $num=" " ;~ if ($checksum=636) or ($checksum=653) then $num=0 ;~ if ($checksum=719) then $num=1 ;~ if ($checksum=674) then $num=2 ;~ if ($checksum=661) then $num=3 ;~ if ($checksum=666) then $num=4 ;~ if ($checksum=650) then $num=5 ;~ if ($checksum=699) or ($checksum=716) then $num=6 ;~ if ($checksum=732) or ($checksum=734) then $num=7 ;~ if ($checksum=655) then $num=8 ;~ if ($checksum=659) or ($checksum=676) then $num=9 if ($stringForDigit='0x00022220020000220200022202002020020020200220002022000020002222') then $num=0 if ($stringForDigit='0x00002000002220000000200000002000000220000002000000020000002222') then $num=1 if ($stringForDigit='0x00022220020000220000002200002200000022000020000022000000222222') then $num=2 if ($stringForDigit='0x00022220020000220000002200002200000022000000002022000020002222') then $num=3 if ($stringForDigit='0x00000220000022000022020002000200020002000222222000002200000022') then $num=4 if ($stringForDigit='0x02222222020000000222220000000020000000200000002022000020002222') then $num=5 if ($stringForDigit='0x00002220002200000200000002222200022222000200002022000020002222') then $num=6 if ($stringForDigit='0x02222222000000220000020000002000000020000020000000200000002000') then $num=7 if ($stringForDigit='0x00022220020000220200002200222200002222000200002022000020002222') then $num=8 if ($stringForDigit='0x00022220020000220200002200222222002222200000002000002200002200') then $num=9 consolewrite($num) EndIf if ($showDigits=true) then ;~ consolewrite("-" & $checksum & "-" & $stringLine1 & @CRLF) ;~ $stringLine1=StringRegExpReplace($stringLine1,"[1-9A-Za-z]+","1") ;~ For $picIdLine = 0 To $heightMatrix-1 step 2 For $picIdLine = 0 To $heightMatrix-1 ;~ From the screenshots we can ignore the first 16 bytes (remember in text its 2 characters ;~ $binaryLine=BinaryMid($bmp1Data,($picId*$BMP1LineWidth)+16,$BMP1LineWidth) ;~ and we only need 4 digits which takes about 28 characters and 1 character separator = local $stringLine=stringMid($stringForDigit,($picIdLine * ($stride * 2))+3,($stride*2)-3) ;~ Lets make it readable $stringLine=StringReplace($stringLine,"0",".") ;~ $stringLine=StringRegExpReplace($stringLine,"[0]+",".") ;~ $stringLine=StringRegExpReplace($stringLine,"[1-9A-Za-z]+","1") ;~ $stringLine=StringRegExpReplace($stringLine,"1+","x") $textoutput&=stringformat("%02i",$picIdLine) & " : " & $stringLine & @CRLF next ControlSetText("","",$editBox,$textOutput) ;~ Not working propertly? ;~ local $checkSum=PixelChecksum($leftMatrix, $rightMatrix , $topMatrix, $bottomMatrix, 1, 0 ,1) ;~ consolewrite($checksum & " - ") ;~ Minus two just as it influences the next screenshot _Screen_DrawRect( $leftMatrix, $rightMatrix-4 , $topMatrix, $bottomMatrix) ;~ if ($charId=1) then ;~ MsgBox($MB_SYSTEMMODAL, "Title", "This message box will timeout after 10 seconds or select the OK button.", 10) ;~ EndIf SLEEP (100) EndIf Next consolewrite(@crlf) Next EndFunc Func GetImageDataFromScreen($left, $top, $right, $bottom, byref $BMPDataStart, byref $Width, byRef $Height, byref $Stride, $picIdmgBytes=3) local $Scan0, $pixelData, $hbScreen, $pBitmap, $pBitmapCap, $handle, $bitMapdata, $pixelFormat ; Capture screen to load the bitmap to search in ;~ _ScreenCapture_Capture(@UserProfileDir & "\downloads\examples\test.png",$left, $top, $right, $bottom,False) ;~ _ScreenCapture_Capture("",$left, $top, $right, $bottom,False) $hbScreen=_ScreenCapture_Capture("",$left, $top, $right, $bottom,False) local $pBitmap1 = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen); returns memory bitmap _WinAPI_DeleteObject($hbScreen) ;release GDI bitmap resource because not needed anymore Local $pBitmap= _GDIPlus_ImageResize($pBitmap1, 8, 8) ;resize image ;~ Local $pBitmap= _GDIPlus_ImageScale($hBitmap, 0.5, 0.5) ;resize image ;Get $tagGDIPBITMAPDATA structure ;~ ConsoleWrite("Bitmap Width: " & _GDIPlus_ImageGetWidth($pBitmap) & @CRLF ) ;~ ConsoleWrite("Bitmap Height: " & _GDIPlus_ImageGetHeight($pBitmap) & @CRLF) ;~ 24 bits (3 bytes) or 16 bits (2 bytes) comparison if ($picIdmgBytes=1) then $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF04INDEXED) Endif if ($picIdmgBytes=2) then $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF16RGB555) ;~ $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF32ARGB) EndIf if ($picIdmgBytes=3) then $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF24RGB) ;~ $BitmapData= _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF32ARGB) endIf If @ERROR Then MsgBox(0,"","Error locking region " & @error) $Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up. $Width = DllStructGetData($BitmapData, "Width");Image width - Number of pixels in one scan line of the bitmap. $Height = DllStructGetData($BitmapData, "Height");Image height - Number of scan lines in the bitmap. $PixelFormat = DllStructGetData($BitmapData, "PixelFormat");Pixel format - Integer that specifies the pixel format of the bitmap $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap. $pixelData = DllStructCreate("ubyte lData[" & (abs($Stride) * $Height-1) & "]", $Scan0) $BMPDataStart = $BMPDataStart & DllStructGetData($pixeldata,"lData") _GDIPlus_BitmapUnlockBits($pBitmap, $BitmapData) _GDIPlus_ImageDispose ($pBitmap) _WinAPI_DeleteObject ($pBitmap) _WinAPI_DeleteObject ($hbScreen) EndFunc;==>GetImage ; Draw rectangle on screen. Func _Screen_DrawRect($tLeft, $tRight, $tTop, $tBottom, $color = 0xFF, $PenWidth = 1) Local $hDC, $hPen, $obj_orig, $x1, $x2, $y1, $y2 $x1 = $tLeft $x2 = $tRight $y1 = $tTop $y2 = $tBottom $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop) $hPen = _WinAPI_CreatePen($PS_SOLID, $PenWidth, $color) $obj_orig = _WinAPI_SelectObject($hDC, $hPen) _WinAPI_DrawLine($hDC, $x1, $y1, $x2, $y1) ; horizontal to right _WinAPI_DrawLine($hDC, $x2, $y1, $x2, $y2) ; vertical down on right _WinAPI_DrawLine($hDC, $x2, $y2, $x1, $y2) ; horizontal to left right _WinAPI_DrawLine($hDC, $x1, $y2, $x1, $y1) ; vertical up on left ; clear resources _WinAPI_SelectObject($hDC, $obj_orig) _WinAPI_DeleteObject($hPen) _WinAPI_ReleaseDC(0, $hDC) EndFunc ;==>_UIA_DrawRect