Jump to content

Detect Flash Videos (browser independent)


Recommended Posts

Hi,

I am trying to detect whenever a flash video is played in any browser. Background is some kind of parental control but for myself :)

It does not have to be 100% deterministic. But I would like to collect some ideas from you.

Is there an interface to the flash-player itself that one can query?

Or some place where such videos get cached?

I really have no idea at the moment, and any approach is welcome :)

 

kind regards

Blues

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

The best way I can think of doing such a thing is to monitor the process for Flash plugin memory usage for changes. For this, you would use ProcessGetStats. Looking at my Task Manager, I see that the Flash plugin uses it's exact version as part of the process name, so for that you will probably need to use ProcessList to search for part of the name (FlashPlayerPlugin) to find the exact name of the process.

Hope this helps...

Link to comment
Share on other sites

A little code to show the Flash processes and their memory usage (press ESC to exit):

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

$pList = ProcessList()
$Form1 = GUICreate("Form1", 347, 204)
$ListView1 = GUICtrlCreateListView("PID|Memory", 8, 8, 330, 190)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100)
GUISetState(@SW_SHOW)

HotKeySet("{ESC}", "Terminate")

Do
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
        Exit
    EndIf

    Dim $flashPIDs[1]
    $j = 1
    For $i = 1 To $pList[0][0]
        If StringInStr($pList[$i][0], "FlashPlayerPlugin") Then
            $flashPIDs[0] = $j
            $j += 1
            ReDim $flashPIDs[$j]
            $flashPIDs[$j - 1] = $pList[$i][1]
        EndIf
    Next

    For $i = 1 To $flashPIDs[0]
        $pStats = ProcessGetStats($flashPIDs[$i])
        GUICtrlCreateListViewItem ($flashPIDs[$i] & "|" & $pStats[0], $ListView1 )
    Next
    Sleep(1000)
    _GUICtrlListView_DeleteAllItems($ListView1)
Until $nMsg = $GUI_EVENT_CLOSE

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

hello abberration

Basicly it is a very elegant idea. But unfortunately there seems to be no separate process for the flashplayer in all browsers ( at least not in internetExplorer and Chrome )

Here is an approach to c# detecting the plugin by some code I do not really understand:

http://stackoverflow.com/questions/16528812/detecting-if-an-internet-explorer-process-is-running-flash-player

...but its a general flash-detection which can be a small commercial and not really a flash movie

 

Any other ideas? Thank you

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

@junkew

Thank you. Yes this will do the job. Its a bit oversensitive but for me its ok. If one wants to detect it more accurately,

watching the threads of the browsers is needed. This is to much work for now:

Here is the "isFlashPlayerActive" UDF for all those procrastinators out there :)

#include <WinAPI.au3>
#include <array.au3>
#AutoIt3Wrapper_UseX64=n    ; bei 32bit Prozessen

; TEST
HotKeySet("{ESC}", "_Exit")
Func _Exit()
    Exit
EndFunc


While Sleep( 1000 )
    ConsoleWrite(  isFlashPlayerActive() & @LF  )
WEnd



Func isFlashPlayerActive( $checkChrome = 1 , $checkFirefox = 1 , $checkInternetExplorer = 1 )
; Author: Andreas Karlsson (monoceres) & ProgAndy & Bluesmaster


    Static $hPsapi    = DllOpen("Psapi.dll")


    ; 1 - CHROME
    if $checkChrome Then

        $tModulesStruct   = DllStructCreate("hwnd [200]")
        Local $SIZEOFHWND = DllStructGetSize($tModulesStruct) / 200

        Local $aReturn[1]
        $aProcessList = ProcessList( "chrome.exe" )

        For $iProcessList = 1 To $aProcessList[0][0]  ; iterate Processes with the same name

            $hProcess = _WinAPI_OpenProcess(BitOR(0x0400, 0x0010), False, $aProcessList[$iProcessList][1] )    ;  $PROCESS_QUERY_INFORMATION = 0x0400  |  $PROCESS_VM_READ = 0x0010
            If Not $hProcess Then Return SetError(1, 0, -1)
            $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", DllStructGetSize($tModulesStruct), "dword*", "")
            If $aCall[4] > DllStructGetSize($tModulesStruct) Then
                $tModulesStruct = DllStructCreate("hwnd [" & $aCall[4] / $SIZEOFHWND & "]")
                $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", $aCall[4], "dword*", "")
            EndIf
            Local $aReturnTemp[$aCall[4] / $SIZEOFHWND]
            For $i = 0 To UBound( $aReturnTemp ) - 1

                $aCall = DllCall($hPsapi, "dword", "GetModuleFileNameExW", "ptr", $hProcess, "ptr", DllStructGetData($tModulesStruct, 1, $i + 1), "wstr", "", "dword", 65536 )
                $aCall[3] =  StringRegExp( $aCall[3] , "[^\\]+\.[^\\]+$", 1)[0]  ; Restpfad entfernen
                $aReturnTemp[$i] = $aCall[3]

            Next

            _ArrayConcatenate( $aReturn , $aReturnTemp )
        Next

        _WinAPI_CloseHandle($hProcess)

        if _ArraySearch( $aReturn , "pepflashplayer.dll" ) <> -1 Then Return 1   ; dont check the other browsers if flash found

    EndIf



    ; 2 - FIREFOX
    if $checkFirefox Then

        Dim $flashPIDs[1]
        $j = 1
        $pList = ProcessList()
        For $i = 1 To $pList[0][0]
            If StringInStr($pList[$i][0], "FlashPlayerPlugin") Then
                $flashPIDs[0] = $j
                $j += 1
                ReDim $flashPIDs[$j]
                $flashPIDs[$j - 1] = $pList[$i][1]
            EndIf
        Next

        $totalFlashMem = 0
        For $i = 1 To $flashPIDs[0]
            $pStats = ProcessGetStats($flashPIDs[$i])
            $totalFlashMem += $pStats[0] / 1024 / 1024
        Next

        if $totalFlashMem > 50 Then Return 2

    EndIf



    ; 3 - INTERNET EXPLORER
    if $checkChrome Then

        $tModulesStruct   = DllStructCreate("hwnd [200]")
        Local $SIZEOFHWND = DllStructGetSize($tModulesStruct) / 200

        Local $aReturn[1]
        $aProcessList = ProcessList( "iexplore.exe" )

        For $iProcessList = 1 To $aProcessList[0][0]  ; iterate Processes with the same name

            $hProcess = _WinAPI_OpenProcess(BitOR(0x0400, 0x0010), False, $aProcessList[$iProcessList][1] )    ;  $PROCESS_QUERY_INFORMATION = 0x0400  |  $PROCESS_VM_READ = 0x0010
            If Not $hProcess Then Return SetError(1, 0, -1)
            $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", DllStructGetSize($tModulesStruct), "dword*", "")
            If $aCall[4] > DllStructGetSize($tModulesStruct) Then
                $tModulesStruct = DllStructCreate("hwnd [" & $aCall[4] / $SIZEOFHWND & "]")
                $aCall = DllCall($hPsapi, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($tModulesStruct), "dword", $aCall[4], "dword*", "")
            EndIf
            Local $aReturnTemp[$aCall[4] / $SIZEOFHWND]
            For $i = 0 To UBound( $aReturnTemp ) - 1

                $aCall = DllCall($hPsapi, "dword", "GetModuleFileNameExW", "ptr", $hProcess, "ptr", DllStructGetData($tModulesStruct, 1, $i + 1), "wstr", "", "dword", 65536 )
                $aCall[3] =  StringRegExp( $aCall[3] , "[^\\]+\.[^\\]+$", 1)[0]  ; Restpfad entfernen
                $aReturnTemp[$i] = $aCall[3]

            Next

            _ArrayConcatenate( $aReturn , $aReturnTemp )
        Next

        _WinAPI_CloseHandle($hProcess)

        if _ArraySearch( $aReturn , "flash.ocx" ) <> -1 Then Return 3   ; dont check the other browsers if flash found

    EndIf


    Return False

EndFunc

isFlashPlayerActive.au3

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...