Results 1 to 12 of 12

Thread: Hooking with ASM

  1. #1
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Hooking with ASM

    Hello,

    I need to hook something for a school project, we've an address, and instead of the regular assembly we've to rewrite it with a jump to our code call an address and return. I did this in VS easily like this:

    Qt Code:
    1. void __declspec(naked) NewFunc ( void )
    2. {
    3.  
    4. __asm
    5. {
    6. lea ebx,[ebp-0x0C]
    7.  
    8. call MyFunction // my function
    9.  
    10. popad
    11. pop ebx // Notice how we reproduce the assembly that was overwritten
    12. leave
    13.  
    14. jmp back// back is just address + 5
    15. }
    16. }
    17.  
    18. *(LPBYTE)Address = 0xE9;
    19. *(PDWORD)( Address + 1 ) = ((LONG_PTR)HookFunc)-((LONG_PTR)Address))- 5;
    To copy to clipboard, switch view to plain text mode 

    Now is my question can I do something similar in QtCreator?

    Else what is my best option, make a .dll and inject it and when clicked, call my function in the .exe?

    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Hooking with ASM

    QtCreator isn't a compiler, it's an IDE, so yes, you can do the above, just use VS as your compiler.

    If you want to use the compiler that comes with the Qt SDK, then read the inline assembly howto for GCC.

  3. #3
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: Hooking with ASM

    Thanks,

    but this line does not work

    Qt Code:
    1. *(char*)address = 0xE9; // jmp
    2. *(void **)((char *)address + 1) = (void*)(((char*)NewFun()) - ((char *)address + 5));
    To copy to clipboard, switch view to plain text mode 

    error I get:

    void value not ingored as it ought to be
    EDIT:
    btw, this is the NewFun

    Qt Code:
    1. void Hook::NewFun()
    2. {
    3. __asm__ (
    4.  
    5. );
    6. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Hooking with ASM

    The reason for the error is fairly obvious, but this isn't the place to talk about such topics. You would be better on a GCC forum as this topic has nothing to do with Qt.

  5. #5
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: Hooking with ASM

    Quote Originally Posted by squidge View Post
    The reason for the error is fairly obvious, but this isn't the place to talk about such topics. You would be better on a GCC forum as this topic has nothing to do with Qt.
    Sorry I forgot that, I would also register myself on a GCC forum, but why not telling me?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Hooking with ASM

    Because if he told you, you wouldn't register on a GCC forum and you would ask the next totally Qt-unrelated question here and not there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: Hooking with ASM

    Quote Originally Posted by wysota View Post
    Because if he told you, you wouldn't register on a GCC forum and you would ask the next totally Qt-unrelated question here and not there.
    Actually I registered

    http://www.avrfreaks.net/index.php?n...=viewforum&f=2

    EDIT: found out that

    NewSendFun() -> should be -> NewSendFun;

    Now I get a new error

    invalid use of member (did you forget the '&'? )
    Last edited by Nazgul; 22nd March 2011 at 13:22.

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    21
    Thanked 418 Times in 411 Posts

    Default Re: Hooking with ASM

    Because if he told you, you wouldn't register on a GCC forum and you would ask the next totally Qt-unrelated question here and not there.
    Now I get a new error
    and you thought if he got registered on that other forum it will stop him from asking it here as well ;-)
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  9. #9
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: Hooking with ASM

    Quote Originally Posted by high_flyer View Post
    and you thought if he got registered on that other forum it will stop him from asking it here as well ;-)
    It's not weird that I ask on both right? I could not ask question there with some wierd bug, no I did it at the forum "old nabble".

    So if someone would be so kind?

  10. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    6
    Thanked 348 Times in 333 Posts

    Default Re: Hooking with ASM

    Forgive me for my bluntness, but what part of "This is a Qt forum and your questions have nothing to do with Qt" are you struggling with?

  11. #11
    Join Date
    Mar 2011
    Posts
    33
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Re: Hooking with ASM

    Quote Originally Posted by squidge View Post
    Forgive me for my bluntness, but what part of "This is a Qt forum and your questions have nothing to do with Qt" are you struggling with?
    This is a general programming forum now, so my question is not off topic right?

    So how can I jump fom my address to my asm code?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Hooking with ASM

    Quote Originally Posted by Nazgul View Post
    This is a general programming forum now, so my question is not off topic right?
    Only because I have moved your thread here. You originally posted it in the Qt section.

    And I doubt you will get your answer here because we are aware of the fact that people at GCC forum are more skilled than us to answer this question so why should we do bugchasing for you here if they can probably pull a proper answer right out of their heads.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Hooking Qt Signals/Slots
    By mlheese in forum Newbie
    Replies: 6
    Last Post: 5th October 2010, 06:04
  2. QWebView and hooking events
    By invictus in forum Qt Programming
    Replies: 1
    Last Post: 30th November 2009, 11:26
  3. Hooking Keyboard and mouse
    By moya in forum Qt Programming
    Replies: 2
    Last Post: 3rd August 2009, 15:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.