Poker-AI.org
http://poker-ai.org/phpbb/

Calling back into the Qt framework from a hooked function
http://poker-ai.org/phpbb/viewtopic.php?f=22&t=2964
Page 1 of 1

Author:  stat80 [ Thu Feb 18, 2016 8:41 pm ]
Post subject:  Calling back into the Qt framework from a hooked function

Hi there, this is my first post on this forum I've been following for quite some time. Recently I got an idea to improve my decisions while playing poker. I've come a long way, but still I'm figuring out some issues. Currently I'm figuring out how to call back into the Qt framework from an Easyhook hooked Qt function, but can't resolve this for some reason. Can you help me out? I tried searching for it, but either I'm not using the right keywords or there's nothing to be found about this subject (highly unlikely).

I'm hooking into QLabel::paintEvent and in the hook I want to call (for example) the QLabel::text function of the passed in QLabel. Please check the code below.

The hook works, but the moment I call QLabel::text I'm getting an AccessViolationException.

Thanks a million!

PS: I saw codingthewheel.com is down. Such a shame! Is there a mirror of the site?

Currently I have this (c#)

Code:
 [DllImport("Qt5Widgets.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.ThisCall, EntryPoint = "?text@QLabel@@QBE?AVQString@@XZ")]
    protected static extern IntPtr QLabel_text(IntPtr obj);

    [DllImport("Qt5Widgets.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.ThisCall, EntryPoint = "?paintEvent@QLabel@@MAEXPAVQPaintEvent@@@Z")]
    protected static extern void QLabel_paintEvent(IntPtr obj, IntPtr p1);

    [UnmanagedFunctionPointer(CallingConvention.ThisCall, CharSet = CharSet.Unicode, SetLastError = true)]
    delegate void TQLabel_paintEvent(IntPtr obj, IntPtr p1);

    static unsafe void QLabel_paintEvent_Hooked(IntPtr obj, IntPtr p1)
    {
        try
        {
            var ptr = QLabel_text(obj); // <-- I'm getting an AccessViolationException here. Why? And how can I resolve this?
            var str = (QString)Marshal.PtrToStructure(ptr, typeof(QString));
            ((Main)HookRuntimeInfo.Callback).Interface.GotQLabel_paintEvent(str.ToString());
            QLabel_paintEvent(obj, p1);
        }
        catch (Exception ex)
        {
            ((Main)HookRuntimeInfo.Callback).Interface.ErrorHandler(ex);
        }
    }

Author:  spears [ Thu Feb 18, 2016 10:32 pm ]
Post subject:  Re: Calling back into the Qt framework from a hooked functio

http://web.archive.org/web/*/codingthewheel.com

Sorry, know nothing about Qt

Author:  stat80 [ Thu Feb 18, 2016 11:05 pm ]
Post subject:  Re: Calling back into the Qt framework from a hooked functio

spears wrote:
http://web.archive.org/web/*/codingthewheel.com

Sorry, know nothing about Qt

Awesome, saw the archive.org link on the forum too. Such a wonderful resource. Too bad you know nothing abou Qt, but there must be someone out there who can help me out :).

I found this code https://searchcode.com/codesearch/view/8384629/ and it looks like they're doing it succesfully (it being calling back into Qt from the hooked function to get extra info from the client) in the QWidgetPrivate_repaint_sys_Hooked function...

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/