0

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!

VahidN
  • 18,457
  • 8
  • 73
  • 117
psergiu
  • 1
  • 2

1 Answers1

1

If I understand correctly what you meant by "string scrambled and the lines get mixed" than there are two issues that might help you:

  1. The string could be output as Glyphs indices and not as Chars (therefore will appear as scrambled text).

  2. 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.

Momico
  • 85
  • 1
  • 8
  • For now i am expiriencing the same problem. Even when i just pass parameters to ExtTextOutW function, i still have problems in the hooked program - it shows some hieroglyphs instead of latin text. I am sure, problem is that MarshalAs changes something in the source data while converting to CLR string. The problem shows itself only when Glyphs flag is set, otherwise hook works correctly and hooked text is not corrupted. – Alexander Sobolev Jan 14 '13 at 12:55