Page 4 of 5

Posted: Thu Dec 25, 2008 6:22 pm
by Sparkie
For the lastest version of Opera (9.63), you can try catching className$ = "OpWindow". For Chrome I'd have to install it and take a closer look. I have no time right now but maybe later next month I'll see what I can do. :wink:

Posted: Thu Dec 25, 2008 6:56 pm
by besko
Read Browser URL (IE, Firefox,Opera,Chrome)

My Code

Code: Select all

#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A

;################
; Convert to BSTR
;################
; Thanks to freak for this one
Procedure.l ASCIItoBSTR(asciiString$)
  Protected result = 0
  CompilerIf #PB_Compiler_Unicode
  result = SysAllocString_(@asciiString$)
  CompilerElse
  Protected *buff = AllocateMemory(Len(asciiString$)*2 + 2)
  If *buff
    PokeS(*buff, asciiString$, -1, #PB_Unicode)
    result = SysAllocString_(*buff)
    FreeMemory(*buff)
  EndIf
  CompilerEndIf
  ProcedureReturn result
EndProcedure

;################
; Set Hook
;################
Procedure WinEventFunc(HookHandle.l, hEvent.l, hwnd.l, idObject.l, idChild.l, idEventThread.l, dwmsEventTime.l)
  Protected *objectIa.IAccessible
  Static previousUrl$
  Select hEvent
    Case #EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE
      className$ = Space(256)
      GetClassName_(hwnd, @className$, 256)
      If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "OpWindow" Or className$ = "Chrome_AutocompleteEditView" Or className$ = "Chrome_XPFrame" 
        If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
          v.VARIANT\vt = #VT_I4
          v\lVal = #CHILDID_SELF
          If *objectIa\get_accRole(v, @v) = #S_OK
            If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
              v\vt = #VT_I4
              v\lVal = #CHILDID_SELF
              url$ = Space(#MAX_PATH)
              bstr = ASCIItoBSTR(Space(#MAX_PATH))
              If *objectIa\get_accValue(v, @bstr) = #S_OK
                len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
                url$ = Space(len)
                WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)   
                If previousUrl$ <> url$ And url$ <> ""
                  AddGadgetItem(1, -1, url$)
                  previousUrl$ = url$
                EndIf
              EndIf
            EndIf
            *objectIa\Release()
          EndIf
        EndIf
      EndIf
  EndSelect
EndProcedure

;################
; Main Window
;################
If OpenWindow(0, 0, 0, 500, 400, "Read Browser URL", #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0))
  CoInitialize_(0);
  hdll = OpenLibrary(0, "Oleacc.dll")
  EditorGadget(1, 10, 15, 480, 380)
  ;...Set event hook
  eHook = SetWinEventHook_(#EVENT_OBJECT_FOCUS, #EVENT_OBJECT_VALUECHANGE, #Null, @WinEventFunc(), 0, 0, #WINEVENT_OUTOFCONTEXT | #WINEVENT_SKIPOWNPROCESS)
  Repeat
    event = WaitWindowEvent()
  Until event = #PB_Event_CloseWindow
  ;...Cleanup
  CoUninitialize_()
  If eHook
    UnhookWinEvent_(eHook)
  EndIf
  If hdll
    CloseLibrary(0)
  EndIf
EndIf
End

Posted: Thu Dec 25, 2008 6:59 pm
by besko
And how can i Hook Url?
And How Hook www.google.com or Urls List and then do something?

Posted: Mon Feb 02, 2009 2:35 pm
by ar-s
Great Coding guys ! :D

Re: Firefox, mozilla based browser URL

Posted: Mon Dec 06, 2010 10:05 pm
by fizix
I'm sorry to resurrect an old thread but I'm trying to turn Besko's code in to a DLL that can have a hwnd passed to it. What am I doing wrong?

DLL Code:

Code: Select all

#CHILDID_SELF = 0
#WINEVENT_OUTOFCONTEXT = 0
#WINEVENT_SKIPOWNPROCESS = $2
#EVENT_OBJECT_FOCUS = $8005
#EVENT_OBJECT_VALUECHANGE = $800E
#ROLE_SYSTEM_DOCUMENT = $F
#ROLE_SYSTEM_PANE = $10
#ROLE_SYSTEM_TEXT = $2A

Global globurl$

;################
; Convert to BSTR
;################
; Thanks to freak for this one
Procedure.l ASCIItoBSTR(asciiString$)
  Protected result = 0
  CompilerIf #PB_Compiler_Unicode
  result = SysAllocString_(@asciiString$)
  CompilerElse
  Protected *buff = AllocateMemory(Len(asciiString$)*2 + 2)
  If *buff
    PokeS(*buff, asciiString$, -1, #PB_Unicode)
    result = SysAllocString_(*buff)
    FreeMemory(*buff)
  EndIf
  CompilerEndIf
  ProcedureReturn result
EndProcedure

;################
; Set Hook
;################
Procedure WinEventFunc(hwnd.l)
  Protected *objectIa.IAccessible
  Static previousUrl$
      className$ = Space(256)
      GetClassName_(hwnd, @className$, 256)
      If className$ = "MozillaWindowClass" Or className$ = "Internet Explorer_Server" Or className$ = "OpWindow" Or className$ = "Chrome_AutocompleteEditView" Or className$ = "Chrome_XPFrame"
        If CallFunction(0, "AccessibleObjectFromEvent", hwnd, idObject, idChild, @*objectIa, @v.VARIANT) = #S_OK
          v.VARIANT\vt = #VT_I4
          v\lVal = #CHILDID_SELF
          If *objectIa\get_accRole(v, @v) = #S_OK
            If v\lVal = #ROLE_SYSTEM_PANE Or v\lVal = #ROLE_SYSTEM_DOCUMENT Or v\lVal = #ROLE_SYSTEM_TEXT
              v\vt = #VT_I4
              v\lVal = #CHILDID_SELF
              url$ = Space(#MAX_PATH)
              bstr = ASCIItoBSTR(Space(#MAX_PATH))
              If *objectIa\get_accValue(v, @bstr) = #S_OK
                len = WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, 0, 0, 0, 0)
                url$ = Space(len)
                WideCharToMultiByte_(#CP_ACP, 0, bstr, -1, @url$, len, 0, 0)   
                If url$ <> ""
                  globurl$ = url$
                EndIf
              EndIf
            EndIf
            *objectIa\Release()
          EndIf
        EndIf
      EndIf
EndProcedure

;################
; Main Procedure
;################
ProcedureDLL.s getURL(hwnd.l)
  CoInitialize_(0);
  hdll = OpenLibrary(0, "Oleacc.dll")
  ;...Set event hook
  WinEventFunc(hwnd)
  Delay(2000)
  ;...Cleanup
  CoUninitialize_()
  If hdll
    CloseLibrary(0)
  EndIf
  ProcedureReturn globurl$
EndProcedure
Test program:

Code: Select all

result = OpenLibrary(0, "getURL.dll")
url.s =  PeekS(CallFunction(0, "getURL",66556))
Debug url
CloseLibrary(0)

Re:

Posted: Mon Nov 07, 2011 12:24 pm
by MachineCode
besko wrote: Read Browser URL (IE, Firefox,Opera,Chrome)
Doesn't work with Opera or Chrome anymore. :( Anyone know how to update it? I've tried various class names ("Chrome_OmniboxView") but they don't help.

Re: Re:

Posted: Mon Nov 07, 2011 12:29 pm
by gnozal
MachineCode wrote:
besko wrote: Read Browser URL (IE, Firefox,Opera,Chrome)
Doesn't work with Opera or Chrome anymore. :( Anyone know how to update it? I've tried various class names ("Chrome_OmniboxView") but they don't help.
I did not try the code but Opera's window class is "OperaWindowClass" iirc.

Re: Re:

Posted: Mon Nov 07, 2011 12:31 pm
by MachineCode
gnozal wrote:I did not try the code but Opera's window class is "OperaWindowClass" iirc.
Yeah, I tried that one too (I didn't specifically name it in my post above, sorry). It doesn't work.

Re: Firefox, mozilla based browser URL

Posted: Wed Mar 14, 2012 2:50 pm
by doctorized
Did anyone find the new class names for Chrome and Opera? How can somebody find them?

Re: Firefox, mozilla based browser URL

Posted: Wed Mar 14, 2012 7:34 pm
by doctorized
I found them. The new classes for Chrome are "Chrome_OmniboxView" and "Chrome_WidgetWin_0".

What change should I do to take the title of the page?

Re: Firefox, mozilla based browser URL

Posted: Thu Mar 15, 2012 4:33 pm
by ultralazor
find out the symbol they use in their heap struct for the active DOM URI.. Works on all platforms, you just have to get past page and heap security stuff. The only reliable method with modern browsers is integration or logging thread-input..

FYI: Even the founders of Mozilla say FF and TB source are based on poorly designed and bloated code. XUL or whatever that is they use is why. Writing advanced plugins is a nightmare cause of no documentation and way too much obscure class references and scopes..

Re: Firefox, mozilla based browser URL

Posted: Fri Mar 16, 2012 3:42 pm
by doctorized
There is a program, KidLogger, that does this job, it is open source but I cannot find where it does the job I need. Maybe the code that does my job is not included. This program is not a plugin or anything like that, it is a simple program.

Re: Firefox, mozilla based browser URL

Posted: Sat Mar 17, 2012 1:54 am
by doctorized
The solution was simple, GetWindowText_() API. I know, this is not cross platform but it gets the job done!

Code: Select all

Caption.s = Space(#MAX_PATH)
GetWindowText_(hwnd,@Caption, #MAX_PATH)

Re: Firefox, mozilla based browser URL

Posted: Sat Mar 17, 2012 11:54 am
by ultralazor
kidlogger does what cheatengine and other tools do, crawl the heap, except it probably looks for symbols. The adress is mapped different each runtime. Either that or it logs thread-input to avoid anti-virus products.

Getting window caption yields you no url.. No browsers put the url there but instead the title of the DOM if there is one.

Re: Firefox, mozilla based browser URL

Posted: Sun Mar 18, 2012 7:18 pm
by doctorized
ultralazor wrote:Getting window caption yields you no url.. No browsers put the url there but instead the title of the DOM if there is one.
No my friend. By taking the window caption I want the page title. For example the caption of this page is "PureBasic Forum Post a reply". That's what I want to take from GetWindowText_().