toizy-mr / delphi-detours-library

Automatically exported from code.google.com/p/delphi-detours-library
0 stars 0 forks source link

Hook fails #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What is the function that you are trying to hook ?
- FInternetSetCookieExW := InterceptCreate('wininet.dll', 
'InternetSetCookieExW', @InternetSetCookieExW, True);
- FInternetGetCookieExW := InterceptCreate('wininet.dll', 
'InternetGetCookieExW', @InternetGetCookieExW, True);
- FInternetSetCookie := InterceptCreate('wininet.dll', 'InternetSetCookieW', 
@InternetSetCookie, True);
- FInternetGetCookie := InterceptCreate('wininet.dll', 'InternetSetCookieW', 
@InternetSetCookie, True);

What is the expected output? What do you see instead?
- Function is not fired

What version of the product are you using? On what operating system? Which
architecture x86 or x64 ?

- x64

If the function hooked is not an windows API function , please include this
function .

Please provide any additional information below.
- Nothing happens on WebBrowser1.Navigate('http://www.google.com');

Original issue reported on code.google.com by david.lo...@gmail.com on 18 Jan 2015 at 1:33

GoogleCodeExporter commented 9 years ago
How do you know that calling WebBrowser.Navigate will fire 
InternetSetCookieExW/InternetGetCookieExW ?
Please try to call InternetGetCookieExW/InternetSetCookieExW directly after 
hooking .If it's works that's probably means that WebBrowser.Navigate does not 
call/use the previous functions.

Original comment by ismspi...@gmail.com on 18 Jan 2015 at 1:41

GoogleCodeExporter commented 9 years ago
How do I know? :)

http://www.raysoftware.cn/?p=357

Has example how to do it..

Original comment by david.lo...@gmail.com on 18 Jan 2015 at 1:44

GoogleCodeExporter commented 9 years ago
And this too..

www.codeproject.com/Articles/38616/Retrieve-HttpOnly-Session-Cookie-in-WebBrowse
r

Original comment by david.lo...@gmail.com on 18 Jan 2015 at 1:46

GoogleCodeExporter commented 9 years ago
This is a definite bug. I used this 
https://code.google.com/p/delphi-hook-library/

I can see these functions being fired.

function InternetSetCookieEx(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; 
dwFlags: DWORD; lpReserved: Pointer): DWORD; stdcall;
begin
  Result := _InternetSetCookieEx(lpszUrl, lpszCookieData, lpszCookieData, dwFlags, lpReserved);
end;

function InternetGetCookieEx(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; 
var lpdwSize: DWORD; dwFlags: DWORD; lpReserved: Pointer): BOOL; stdcall;
begin
  Result := _InternetGetCookieEx(lpszUrl, lpszCookieName, lpszCookieData, lpdwSize, dwFlags, lpReserved);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('www.google.com');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  @_InternetSetCookieEx := HookProcInModule('Wininet.dll', 'InternetSetCookieExW', @InternetSetCookieEx);
  @_InternetGetCookieEx := HookProcInModule('Wininet.dll', 'InternetGetCookieExW', @InternetGetCookieEx);
end;

end.

Original comment by david.lo...@gmail.com on 18 Jan 2015 at 3:49

GoogleCodeExporter commented 9 years ago
It seem this library cannot hook IAT/EAT ?

Original comment by david.lo...@gmail.com on 18 Jan 2015 at 11:31

GoogleCodeExporter commented 9 years ago
I am very disappointed !
Please refer to the documentation first before reporting a fake bug.
From DDetours wiki:
<ForceLoadModule : if True the DDL will try to load the module/library if it's 
not loaded.>
On x64 Wininet module is not loaded that's mean DDL can not find 
InternetSetCookieEx/InternetGetCookieEx methods pointer.
You need to set ForceLoadModule (True).In that way even if the Wininet module 
is not loaded DDL will load it:
  @_InternetSetCookieEx := InterceptCreate('Wininet.dll', 'InternetSetCookieExW', @InternetSetCookieEx, True);
  @_InternetGetCookieEx := InterceptCreate('Wininet.dll', 'InternetGetCookieExW', @InternetGetCookieEx, True);

Original comment by ismspi...@gmail.com on 19 Jan 2015 at 1:50

GoogleCodeExporter commented 9 years ago
This doesn't work on 32 bit too ! 

Original comment by david.lo...@gmail.com on 19 Jan 2015 at 2:18

GoogleCodeExporter commented 9 years ago
I really don't know what's the problem .
I tested this code and it works fine on x32 & x64.
//-----------------------------------
uses DDetours;

var
  _InternetSetCookieEx: function(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; dwFlags: DWORD; lpReserved: Pointer): DWORD; stdcall;
  _InternetGetCookieEx: function(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; var lpdwSize: DWORD; dwFlags: DWORD; lpReserved: Pointer): BOOL; stdcall;

function InternetSetCookieEx(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; 
dwFlags: DWORD; lpReserved: Pointer): DWORD; stdcall;
begin
  Main.LogMem.Lines.Add('InternetSetCookieEx');
  Result := _InternetSetCookieEx(lpszUrl, lpszCookieData, lpszCookieData, dwFlags, lpReserved);
end;

function InternetGetCookieEx(lpszUrl, lpszCookieName, lpszCookieData: LPCWSTR; 
var lpdwSize: DWORD; dwFlags: DWORD; lpReserved: Pointer): BOOL; stdcall;
begin
  Main.LogMem.Lines.Add('InternetGetCookieEx');
  Result := _InternetGetCookieEx(lpszUrl, lpszCookieName, lpszCookieData, lpdwSize, dwFlags, lpReserved);
end;

procedure TMain.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('google.com');
end;

initialization

@_InternetGetCookieEx := InterceptCreate('Wininet.dll', 'InternetGetCookieExW', 
@InternetGetCookieEx,True);
@_InternetSetCookieEx := InterceptCreate('Wininet.dll', 'InternetSetCookieExW', 
@InternetSetCookieEx,True);

Original comment by ismspi...@gmail.com on 19 Jan 2015 at 2:47