Jump to content

ame1011

Active Members
  • Posts

    246
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

ame1011's Achievements

Polymath

Polymath (5/7)

0

Reputation

  1. I implemented the code above. The size of the images using my initial method (SaveToFile, FileRead, HTTPPost, FileDelete) are ~75-100KB. The size of the images using this binary method are ~200KB and they also do not work. When viewing them in windows, I get an error "Windows Photo Viewer can't open this picture because the file appears to be damaged, corrupted, or is too large". Any ideas?
  2. Thanks for responding UEZ. Post image looks like this: Func PostImage($iLoc, $img) Local $sChunk, $s_Data local $path = "sr_images_" & @YEAR & "_" & @MON & "/" & $user & "/" & StringLeft($iLoc, 11) local $file = StringRight($iLoc, 7) $hOpen = _WinHttpOpen("ImageUpload_"&$user&"_"&$iLoc) $hConnect = _WinHttpConnect($hOpen, $sURL) $hRequest = _WinHttpOpenRequest($hConnect, "POST", $sPURL) $sData = "" $sData &= '----------darker' & @CRLF $sData &= 'Content-Disposition: form-data; name="path"' & @CRLF & @CRLF $sData &= $path & @CRLF $sData &= '----------darker' & @CRLF $sData &= 'Content-Disposition: form-data; name="file_name"' & @CRLF & @CRLF $sData &= $file & @CRLF $sData &= '----------darker' & @CRLF $sData &= 'Content-Disposition: form-data; name="image"; filename="'&$file&'"' & @CRLF $sData &= 'Content-Type: image/jpg' & @CRLF & @CRLF $sData &= $img & @CRLF $sData &= '----------darker' & @CRLF _WinHttpSendRequest($hRequest, "Content-Type: multipart/form-data; boundary=--------darker", Binary($sData)) _WinHttpReceiveResponse($hRequest) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) EndFunc Am I not converting the bitmap properly with the following lines? $hbitmap = _ScreenCapture_Capture('', $iScreenCapDimensions[1] , $iScreenCapDimensions[2], $iScreenCapDimensions[3], $iScreenCapDimensions[4]) $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbitmap) $graphics = _GDIPlus_ImageGetGraphicsContext($bitmap) $resizedbitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $graphics) $graphics2 = _GDIPlus_ImageGetGraphicsContext($resizedbitmap) _GDIPLUS_GraphicsSetInterpolationMode($graphics2, $InterpolationModeHighQualityBicubic) _GDIPlus_GraphicsDrawImageRect($graphics2, $bitmap, 0, 0, $iWidth, $iHeight) $bImage = _GDIPlus_SaveImage2BinaryString($resizedbitmap) I would like to keep these settings (width, height, interpolationMode, etc.) when I transfer the image via http
  3. Hi, What I would like to accomplish is to take a screenshot and upload it to a remote php file via _winHTTP. Previously, we were taking the screenshots and saving them to a network folder. However, we would now like to alter this so that it posts the information instead through win http. Please see the following code sample (note it does NOT run, it's just for reference). $hbitmap = _ScreenCapture_Capture('', $iScreenCapDimensions[1] , $iScreenCapDimensions[2], $iScreenCapDimensions[3], $iScreenCapDimensions[4]) _SavehBitmapEx($hbitmap, 100000000, _WinAPI_GetSystemMetrics(78), _WinAPI_GetSystemMetrics(79)) Func _SavehBitmapEx($hbitmap, $iID, $iWidth, $iHeight) Local $save_result = true $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbitmap) $graphics = _GDIPlus_ImageGetGraphicsContext($bitmap) $resizedbitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $graphics) $graphics2 = _GDIPlus_ImageGetGraphicsContext($resizedbitmap) _GDIPLUS_GraphicsSetInterpolationMode($graphics2, $InterpolationModeHighQualityBicubic) _GDIPlus_GraphicsDrawImageRect($graphics2, $bitmap, 0, 0, $iWidth, $iHeight) ;;; - CODE THAT REQUIRES UPDATE Local $locImgFile = "C:\temp\" & _GetImageFolderPathFromId($iID, '') $save_result = _GDIPlus_ImageSaveToFile($resizedbitmap, $locImgFile) ;saves to temp file PostImage(_GetImageFolderPathFromId($iID, '/'), FileRead($locImgFile)) ;file reads image and uploads to http server FileDelete($locImgFile) ;deletes image when done ;;; - END CODE THAT REQUIRES UPDATE _GDIPlus_GraphicsDispose($graphics) _GDIPlus_GraphicsDispose($graphics2) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_BitmapDispose($resizedbitmap) return $save_result EndFunc ;==>_SavehBitmapEx Func _GetImageFolderPathFromId($id, $sep = '\') Local $aLastImageSplit $aLastImageSplit = StringSplit(String($id), '') $return = $aLastImageSplit[1] & $aLastImageSplit[2] & $aLastImageSplit[3] & $sep & _ $aLastImageSplit[4] & $aLastImageSplit[5] & $aLastImageSplit[6] & $sep & _ $aLastImageSplit[7] & $aLastImageSplit[8] & $aLastImageSplit[9] & $sep & _ $aLastImageSplit[10] & $aLastImageSplit[11] & $aLastImageSplit[12] & '.jpg' return $return EndFunc Func _GDIPlus_SaveImage2BinaryString($hBitmap, $iQuality = 100) ;coded by Andreik, modified by UEZ Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg") Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) Local $pEncoder = DllStructGetPtr($tGUID) Local $tParams = _GDIPlus_ParamInit(1) Local $tData = DllStructCreate("int Quality") DllStructSetData($tData, "Quality", $iQuality) ;quality 0-100 Local $pData = DllStructGetPtr($tData) _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) Local $pParams = DllStructGetPtr($tParams) Local $hStream = DllCall("ole32.dll", "uint", "CreateStreamOnHGlobal", "ptr", 0, "bool", True, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/ms864401.aspx If @error Then Return SetError(1, 0, 0) $hStream = $hStream[3] DllCall($ghGDIPDll, "uint", "GdipSaveImageToStream", "ptr", $hBitmap, "ptr", $hStream, "ptr", $pEncoder, "ptr", $pParams) _GDIPlus_BitmapDispose($hBitmap) Local $hMemory = DllCall("ole32.dll", "uint", "GetHGlobalFromStream", "ptr", $hStream, "ptr*", 0) ;http://msdn.microsoft.com/en-us/library/aa911736.aspx If @error Then Return SetError(2, 0, 0) $hMemory = $hMemory[2] Local $iMemSize = _MemGlobalSize($hMemory) Local $pMem = _MemGlobalLock($hMemory) $tData = DllStructCreate("byte[" & $iMemSize & "]", $pMem) Local $bData = DllStructGetData($tData, 1) Local $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data;ptr") Local $aCall = DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, "dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221473(v=vs.85).aspx _MemGlobalFree($hMemory) Return $bData EndFunc ;==>_GDIPlus_SaveImage2BinaryString The above method works but I would like to change it. It saves a temp jpg, file reads it, uploads to server and deletes the temp file. I would like to utilize the "_GDIPlus_SaveImage2BinaryString" method instead rather than using a temp file. Changing: ;;; - CODE THAT REQUIRES UPDATE Local $locImgFile = "C:\temp\" & _GetImageFolderPathFromId($iID, '') $save_result = _GDIPlus_ImageSaveToFile($resizedbitmap, $locImgFile) ;saves to temp file PostImage(_GetImageFolderPathFromId($iID, '/'), FileRead($locImgFile)) ;file reads image and uploads to http server FileDelete($locImgFile) ;deletes image when done ;;; - END CODE THAT REQUIRES UPDATE To: ;;; - CODE THAT REQUIRES UPDATE PostImage(_GetImageFolderPathFromId($iID, '/'), _GDIPlus_SaveImage2BinaryString($resizedbitmap)) ;sends binary image to server directly ;;; - END CODE THAT REQUIRES UPDATE Does NOT work. Anyone have any ideas? Thanks in advance.
  4. We need more specifics here. When the page finishes loading, are these items also loaded with the page? (i.e. Are they loaded normally or via ajax) Are you waiting for the objects to load/exist or are you waiting for them to become 'enabled' from a 'disabled' state?
  5. We use a script that I created at work that runs overnight on several virtual machines. The issue is that if the internet "flickers" or is temporarily disconnected in the middle of the script, the program crashes with an object error. I have created a custom event handler for the IE automation library to combat this. However, in order to check the error flag, I would have to add an "if" statement or a function after every object-related call to check or errors. There are hundreds upon hundreds of object actions and adding a line of code after each one seems "clunky". Consider the following code: Global $oIE = _IECreate("Google.com", 0, 1, 1, 1) _IEErrorHandlerRegister("_IEErrorHandler") $result = main() if $result == "" Then ConsoleWrite("success" & @CRLF) Else ConsoleWrite("failed at step: " & $result & @CRLF) EndIf func main() if step1() == false then return "1" if step2() == false then return "2" if step3() == false then return "3" if step4() == false then return "4" if step5() == false then return "5" if step6() == false then return "6" if step7() == false then return "7" if step8() == false then return "8" if step9() == false then return "9" if step10() == false then return "10" return True EndFunc ;example step func step2() ;throughout this function there are error checks that return false if the step failed ;if step has not errors until the end, it succeeded and returns true $oIE.document.action1 $oIE.document.action2 $oIE.document.action3 $oIE.document.action4 $oIE.document.action5 ;... $oIE.document.action100 return True EndFunc func _IEErrorHandler() ; do something on oIE errors EndFunc Let's say there is a COM object error for IE on line 35 ("$oIE.document.action3"). How do I make the script return false on step2() immediately without putting an if statement after each one of those 100 actions (note that each action can have a COM object failure).
  6. Hi, I'm just wondering if AutoIt has an event that is run at every line in the script that I can use to run custom code. Thanks!
  7. Using modified code from the page linked by junkew, I have the following code: #include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> #include <ScreenCapture.au3> ; quick and dirty.... Global $stride, $ptr, $pixeldata global $bitmapfile1, $width1, $height1, $stride1, $pbitmap1 global $bitmapfile2, $width2, $height2, $stride2, $pbitmap2 local $numberdiff = 0 _ScreenCapture_SetJPGQuality(20) $pic1 = _ScreenCapture_Capture() Sleep(1000) $pic2 =_ScreenCapture_Capture() $timer = TimerInit() _GDIPlus_Startup() $pixelstruct1 = getbmpdata($pic1, $width1, $height1, $stride1, $pbitmap1) $pixelstruct2 = getbmpdata($pic2, $width2, $height2, $stride2, $pbitmap2) $length = DllStructGetSize($pixelstruct1) for $i=1 to $length $diff=dllstructgetdata($pixelstruct1,1,$i)-dllstructgetdata($pixelstruct2,1,$i) if $diff<>0 Then $numberdiff+=1 next ConsoleWrite(@CRLF & "Timer Diff: " & TimerDiff($timer)/1000 & " seconds." & @CRLF & "Difference: " & $numberdiff & @CRLF) _GDIPlus_Shutdown() Func getbmpdata($bmpfile, ByRef $width, ByRef $height, ByRef $stride, Byref $pbitmap) ;returns a struct with the data of the pixel $pbitmap = _GDIPlus_BitmapCreateFromHBITMAP($bmpfile) $BitmapData = _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF24RGB) 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. $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap. $pixeldata = DllStructCreate("ubyte[" & (Abs($stride) * ($height)) & "]", $Scan0) $BMPData = DllStructGetData($pixeldata, 1) _WinAPI_DeleteObject($pbitmap) _GDIPlus_BitmapUnlockBits($pBitmap, $BmpData) return $pixeldata EndFunc ;==>getbmpdata Unfortunately this takes 14 seconds for a full-screen screenshot. I know I can reduce this by adding a 'Step' in the for loop, however I'd like to exhaust all other options before I do this. Basically, I'm looking to only save a screenshot if it is different from the last. Perhaps I'm looking at this the wrong way? Rather than comparing images maybe ignore images taken when windows is not doing any kind of window redraws? Anyone have any ideas?
  8. As for the return type: I'm happy with any numeric value. I would determine a 'threshold' by trial and error and I would compare future images to ensure that they are over the threshold.
  9. Thanks! This is exactly what I needed. As for title changed, that is handled by the REDRAW event.
  10. Hi, I'm looking for a fast way to compare 2 hbitmap objects that are being returned by _ScreenCapture_Capture. All I need is a function with 2 input variables (the 2 hbitmaps) that returns a number that indictates the difference in the images. I've seen some examples of bitblt and prospeed but most is either image search or the input is vastly different than what I'm looking for. To be honest dll calls are a bit over my head. Can anyone point me in the right direction to either find/create a function like the one stated above? Thanks in advance
  11. Hi, Currently I'm creating a script for my workplace that monitors window titles and saves them to a local file. Every 10 minutes this local file is uploaded to an external server using http post. The logic of the script is as follows: Get window titles using WinListIf WinList titles are not in 'current_window_titles' array, add them, log an event in the fileIf window titles array has an entry that is not in WinList, remove it from current open windows as it is probably closedAs you can see, I want to log every time a new window title appears - this happens when a new window is open or changed (i.e. a different website is visited) My code works fine for a few hours but I notice it will eventually break and log all windows every iteration of the loop My main question is: is there a WinAPI function somewhere that will fire an event every time a window is opened or it's title has changed? I would think that this method would be better. If not, I've considered changing the 'current_window_titles' array so that it keeps track of window titles that have been opened in the last minute or two. If, after 1 or 2 minutes it is no longer open, remove it from the list. Anyone have any thoughts on this? Code below.. #include <Array.au3> #include "WinHttp.au3" Global $current_open_windows[1] $current_open_windows[0] = "TEMP_WINDOW_NAME" Global $excluded = GetExlusionList() Global $log_dir = '' Global $upload_frequency = 10 Global $latest_file_name = $log_dir & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & "_window_log.txt" Global $file = FileOpen($latest_file_name, 1) Global $timer = TimerInit() while 1 local $winList = WinList() local $winTitle local $winHandle local $search1 local $search2 local $is_complete_2 _ArraySort($current_open_windows) ;if enough time has elapsed: upload old file (if size > 0), reset timer, create a new file if TimerDiff($timer) >= 1000*60*$upload_frequency Then FileClose($file) if FileGetSize($latest_file_name) == 0 Then FileDelete($latest_file_name) Else HttpPostFile() EndIf $timer = TimerInit() $latest_file_name = $log_dir & @YEAR & @MON & @MDAY & "_" & @HOUR & @MIN & @SEC & "_window_log.txt" $file = FileOpen($latest_file_name, 1) EndIf ;go through current open windows, add it to array if not in array For $i = 1 to $winList[0][0] If $winList[$i][0] <> "" AND IsVisible($winList[$i][1]) Then $winTitle = $winList[$i][0] $winHandle = $winList[$i][1] $search = _ArrayBinarySearch($current_open_windows, $winTitle) $search2 = _ArrayBinarySearch($excluded, $winTitle) if $search >= 0 Then ;do nothing since item is already in array Elseif $search == -1 AND $search2 == -1 Then _ArrayAdd($current_open_windows, $winTitle) FileWriteLine($file, @YEAR &"-"& @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "***" & $winTitle) EndIf EndIf Next while 1 $is_complete_2 = True ;go through array, if window found that isn't in current open windows, remove it For $i = 0 to UBound($current_open_windows) - 1 Step 1 $search = _ArraySearch($winList, $current_open_windows[$i]) if $search >= 0 Then ;do nothing since array item is in current window list Else ;delete element and start loop again since order of array elements has changed ConsoleWrite($current_open_windows[$i] & " is no longer open and will be deleted" & @CRLF) _ArrayDelete($current_open_windows, $i) $is_complete_2 = False ExitLoop EndIf Next if $is_complete_2 == True Then ExitLoop WEnd sleep(50) WEnd
  12. I've tried _ScreenCapture_SetBMPFormat and the image size of BMP's are higher than quality 10 JPGs even at the lowest setting. Also, the images must be saved 'as-is' ie. outside of zipped archives. I'll have to look at stretch bit and clone area
  13. Hi, I have the following code: #include <ScreenCapture.au3> GLobal $last_image_id = 0 Global $iVScrWidth=_WinAPI_GetSystemMetrics(78) Global $iVScrHeight=_WinAPI_GetSystemMetrics(79) _ScreenCapture_SetJPGQuality(10) $timer = TimerInit() while 1 sleep (50) if TimerDiff($timer) >= 500 Then $last_image_id = $last_image_id + 1 _ScreenCapture_Capture(@ScriptDir & "\" & $last_image_id & ".jpg", ($iVScrWidth/2) * -1 , 0, $iVScrWidth/2, $iVScrHeight) exit $timer =TimerInit() EndIf WEnd What this code does is take 2 screenshots every second of our 2 monitor desktop setup with the right monitor being the main one. Eventually I'll add in options where the user can select 1 monitor setups and 2 monitor setups with the main monitor being on different sides. What I'm trying to do is the following: get a reference to the HBITMAT instead of saving it to file (this is easy)Reduce the width/height of the image by ~50%Reduce the number of colors in the image?These modifications are all geared toward reducing the file size of the images as they're all in 1920x1080. Maybe someone has a better suggestion than the 3 points above? Can anyone point me in the right direction? I've looked into this and all I've been able to find is complex win_api calls and the like.
  14. in b4 Valik. hacker related profile pic: check requesting suspicious functionality: check script kiddie-like screen name: check we have a winner here
  15. I added some comments from above, i'm not sure how to comment it better than that. edit: I also added a consolewrite above, you should be able to see what's going on by running that script
×
×
  • Create New...