Hooking DirectWrite

c++ / delphi package - dll injection and api hooking
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: Hooking DirectWrite

Post by madshi »

Looks good to me. I think we can safely say that GetInterfaceMethod probably works alright. I really wonder why HookAPI fails. Can you check again whether you really don't get a GetLastError value? You need to be careful not to call any win32 APIs after calling HookAPI and before calling GetLastError, because any API you're calling could clear the GetLastError value. Also avoid any string conversions, they may also clear the GetLastError. Ideally, do something like this:

Code: Select all

bool result = HookAPI(...);
if (!result)
{
  DWORD lastError = GetLastError();
  // report lastError somehow
}
manjeetk
Posts: 32
Joined: Thu Apr 07, 2011 6:40 am

Re: Hooking DirectWrite

Post by manjeetk »

Hi,

Yes, we are sure that HookCode is returning ‘0’ and the GetLastError gives ‘0’ i.e. “Operation completed successfully”.

We are using the following code to read the GetLastError for “HookCode” API:

Code: Select all

BOOL bCheck = HookCode(GetInterfaceMethod(*factory, 18), CreateTextLayoutCallback, (PVOID*) &CreateTextLayoutNext);
if(TRUE == bCheck)
{
//Success.
}
else
{
DWORD dwLastErrCode = GetLastError();
     LPVOID lpMsgBuf = NULL;
     FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | 
                     FORMAT_MESSAGE_FROM_SYSTEM | 
                     FORMAT_MESSAGE_IGNORE_INSERTS,
                     NULL,
                     dwLastErrCode,
                     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                     (LPTSTR) &lpMsgBuf,
                     0,
                     NULL);
                //Writing the last error code and reason to a file.
                
     LocalFree(lpMsgBuf);
     lpMsgBuf = NULL;
}
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Re: Hooking DirectWrite

Post by madshi »

Sorry for the late reply.

Can you provide me with a short demo project with which I could reproduce the problem on my PC?
ameetmalekar
Posts: 29
Joined: Thu Feb 16, 2012 5:12 am

Re: Hooking DirectWrite

Post by ameetmalekar »

Hi Manjeet,

Are you able to intercept IE9 Text? I am also trying to do similar kind of thing.
manjeetk
Posts: 32
Joined: Thu Apr 07, 2011 6:40 am

Re: Hooking DirectWrite

Post by manjeetk »

Hi Ameet,

Sorry for the late reply.

No, we are not able to intercept IE9 text. Right now we are not much working on text out issues.
Once we have a time i will provide demo as requested by Madshi about my work for further troubleshooting.
Post Reply