Firefox, mozilla based browser URL

Just starting out? Need help? Post your questions and find answers here.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post 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
besko
User
User
Posts: 42
Joined: Tue Oct 28, 2008 1:08 pm

Post by besko »

And how can i Hook Url?
And How Hook www.google.com or Urls List and then do something?
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Post by ar-s »

Great Coding guys ! :D
fizix
New User
New User
Posts: 1
Joined: Mon Dec 06, 2010 10:01 pm

Re: Firefox, mozilla based browser URL

Post 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)
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re:

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Re:

Post 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.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: Re:

Post 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.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Firefox, mozilla based browser URL

Post by doctorized »

Did anyone find the new class names for Chrome and Opera? How can somebody find them?
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Firefox, mozilla based browser URL

Post 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?
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Firefox, mozilla based browser URL

Post 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..
so many ideas so little time..
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Firefox, mozilla based browser URL

Post 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.
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Firefox, mozilla based browser URL

Post 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)
User avatar
ultralazor
Enthusiast
Enthusiast
Posts: 186
Joined: Sun Jun 27, 2010 9:00 am

Re: Firefox, mozilla based browser URL

Post 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.
so many ideas so little time..
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: Firefox, mozilla based browser URL

Post 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_().
Post Reply