I am writing an application that should hook InternetOpenUrl
and InternetReadFile
in another process.
In the hooked version of InternetOpenUrl
, it will check whether lpszUrl
passed to it matches a regular expression. If matches, record the handle returned by the actual InternetOpenUrl
.
Then in the hooked version of InternetReadFile
, it will read from a file instead of calling the actual InternetReadFile
if the hFile
argument equals to the recorded handle .
I found out that Windows will try to connect to the server provided immediately when calling InternetOpenUrl
and the function will return NULL
if failed to establish the connection.
But I want this mechanism to work even without Internet connection, so it seems that I can't get a handle by calling the actual InternetOpenUrl
in my hooked one when the regular expression matches.
So how can I get it to work?
UPDATE:
Now I call InternetOpen
to get a dummy handle. It seems that handles returned by InternetOpen
and InternetOpenUrl
won't equal.
But I'm not sure whether it is guaranteed, looking for better choices.
So you are attempting to redirect a URL query to a file... You could always host the file, then you will be guaranteed a valid handle in either scenario. However, assuming a local file, I think if you specify the "file://" protocol in the URL it may work in the way you desire.