0
votes

I use wininet library and hook this to monitor internet requests.

The Hooking Function is "InternetConnectW", "HttpOpenRequestW" and "InternetReadFile".

First, I get a HINTERNET handle from "InternetConnectW".

And I get a second HINTERNET handle from "HttpOpenRequestW" with first handle.

When I hook "InternetReadFile", IN parameter include the second handle.

This is InternetReadFile Hooking Function.

BOOL
STDAPICALLTYPE
Hook_InternetReadFile(
__in HINTERNET hFile,
__out LPVOID lpBuffer,
__in DWORD dwNumberOfBytesToRead,
__out LPDWORD lpdwNumberOfBytesRead
)
{
    // i want to get Internet http URL here!!!!!

    return Origin_InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead);
}

How to get URL from HINTERNET handle?

1

1 Answers

1
votes

Try using INTERNET_OPTION_URL with InternetQueryOption.

Example:

TCHAR *szUrl = new TCHAR[INTERNET_MAX_URL_LENGTH];
DWORD dwLen = sizeof(TCHAR)*INTERNET_MAX_URL_LENGTH;
BOOL bRet = InternetQueryOption(hFile, INTERNET_OPTION_URL, szUrl, &dwLen);