Hooking extTextOut problems
I am working on a dll injection soft in c#, the injected dll is also in c# and i'am using pinvoke for certain system functions.
When using extTextOut i get the string scrambled and the lines get mixed together What am i doing wrong?
I hooked extTextOut using EasyHook from codeplex.com like this:
try
{
CreateFileHook = LocalHook.Create(
LocalHook.GetProcAddress("gdi32.dll", "ExtTextOutW"),
new DExtTextOutW(ExtTextOutW_Hooked),
this);
CreateFileHook.ThreadACL.SetExclusiveACL(new Int32[1]);
}
and my extTextOut method is
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, CallingConvention = CallingConvention.StdCall)]
static extern bool ExtTextOutW(IntPtr hdc,
int X,
int Y,
uint fuOptions,
[In] ref RECT lprc,
string lpString,
uint cbCount,
[In] IntPtr lpDx);
static bool ExtTextOutW_Hooked(
IntPtr hdc,
int X,
int Y,
uint fuOptions,
[In] ref RECT lprc,
string lpString,
uint cbCount,
[In] IntPtr lpDx)
{
try
{
DemoInjection This = (DemoInjection)HookRuntimeInfo.Callback;
开发者_运维百科 lock (This.Queue)
{
This.Queue.Push(lpString);
}
}
catch
{
}
return ExtTextOutW(
hdc,
X,
Y,
fuOptions,
ref lprc,
lpString,
cbCount,
lpDx
);
}
And another question if i may. How can i constantly monitor a window which is out of focus or minimized(using this approach it does not work properly)
Thanks a lot!
If I understand correctly what you meant by "string scrambled and the lines get mixed" than there are two issues that might help you:
The string could be output as Glyphs indices and not as Chars (therefore will appear as scrambled text).
You should refer only to the amount of chars supplied by cbCount param other chars in the string may be "garbage" chars.
Hope that helped.
精彩评论