Attempting to hook via Detours menu

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 15 of 23
  1. #1
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Attempting to hook via Detours

    Hi,
    the first time I try to hook a function.
    I googled a bit and thought it would be good to use Detours, so I downloaded it and read a bit about it.

    This is my attempt to hook IsShiftKeyPressed():
    Code:
    typedef int		(__cdecl *IsShiftKeyPressedPtr)(int argument);
    IsShiftKeyPressedPtr TrueIsShiftKeyPressed	= reinterpret_cast<IsShiftKeyPressedPtr>(0x7B3B60);
    
    int HookIsShiftKeyPressed(int argument)
    {
    	MessageBox(NULL, "IsShiftKeyPressed() got called !", "It works", MB_OK);
    
    	return TrueIsShiftKeyPressed(argument);
    }
    
    bool InstallHook()
    {
    	DetourTransactionBegin();
    	DetourUpdateThread(GetCurrentThread());
    	DetourAttach(&reinterpret_cast<void*&>(TrueIsShiftKeyPressed), HookIsShiftKeyPressed);
    
    	long error = DetourTransactionCommit();
    	if (error == NO_ERROR)
    	{
                return true;
        }
    
    	return false;
    }
    But it doesn't work. Did I do any obvious mistakes?

    Thanks.

    Attempting to hook via Detours
  2. #2
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure about detours 2 or whatever they're on now, but I use detours 1.5. It's much simpler. There should be a version of it with WoWX, slightly modded by BSing. You don't have to do any of that Init() nonsense. Just hook 'n go.

  3. #3
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by lanman92 View Post
    I'm not sure about detours 2 or whatever they're on now, but I use detours 1.5. It's much simpler. There should be a version of it with WoWX, slightly modded by BSing. You don't have to do any of that Init() nonsense. Just hook 'n go.

    Except that 1.5 is not thread safe afaik, I think 2.1 is.

  4. #4
    ramey's Avatar Member
    Reputation
    45
    Join Date
    Jan 2008
    Posts
    320
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post

    Except that 1.5 is not thread safe afaik, I think 2.1 is.
    Yep, 2.1 is threadsafe.

  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ramey View Post
    Yep, 2.1 is threadsafe.
    Yup, I thought I remembered that being the case.

    Personally I don't use either, the only things I hook are APIs (because they're safe to hook as long as your code is private, you have plausible deniability and there's nothing they can hash).

    I use a custom library for that though because Detours doesn't support x64 unless you fork over 10 grand so I wrote an IAT/EAT hooking lib.

  6. #6
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I am hooking lua_tostring now.

    Are there really 11 Threads executing lua_tostring at a time or is it a logical problem ?

    Code:
    int HookLuaToString(void* luastate, int index, size_t* length)
    {
    	if(do_string)
    	{
    		DoLuaString(luastringtoexec.c_str(), luastringtoexec.c_str(), NULL);
    		do_string = false;
    	}
    		
    	return TrueLuaToString(luastate, index, length);
    }
    
    .....
    
    if(action == "printHScount")
    {
    	luastringtoexec = "print(GetItemCount(6948))";
    	do_string = true;
    }
    That code is printing the number to chat 11 times.

  7. #7
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by flo8464 View Post
    Ok, I am hooking lua_tostring now.

    Are there really 11 Threads executing lua_tostring at a time or is it a logical problem ?

    Code:
    int HookLuaToString(void* luastate, int index, size_t* length)
    {
    	if(do_string)
    	{
    		DoLuaString(luastringtoexec.c_str(), luastringtoexec.c_str(), NULL);
    		do_string = false;
    	}
    		
    	return TrueLuaToString(luastate, index, length);
    }
    
    .....
    
    if(action == "printHScount")
    {
    	luastringtoexec = "print(GetItemCount(6948))";
    	do_string = true;
    }
    That code is printing the number to chat 11 times.
    Holy shit. You're hooking a function, then using a global static object in order to "call" it. Seriously? SERIOUSLY?

    1. Static data that isn't thread-local is evil. Unless you're properly serializing access to it you're probably DOINITWRONG.
    2. You don't need to hook a function to call it, that's retarded, just call it using a function pointer!
    3. Did I mention that using static data that way is ****ING AWFUL?

  8. #8
    ramey's Avatar Member
    Reputation
    45
    Join Date
    Jan 2008
    Posts
    320
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    holy shit LOL

  9. #9
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by ramey View Post
    holy shit LOL

    Yeah. It seems the quality of the average C++ programmer around here has gone downhill recently....

    Aww who am I kidding, it hasn't gone "downhill", that would imply a curve, it's a ****ing straight line.

  10. #10
    ramey's Avatar Member
    Reputation
    45
    Join Date
    Jan 2008
    Posts
    320
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post

    Yeah. It seems the quality of the average C++ programmer around here has gone downhill recently....

    Aww who am I kidding, it hasn't gone "downhill", that would imply a curve, it's a ****ing straight line.
    LOOOOOOL. I really can't agree anymore with you.. It's true.

  11. #11
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Holy shit. You're hooking a function, then using a global static object in order to "call" it. Seriously? SERIOUSLY?

    1. Static data that isn't thread-local is evil. Unless you're properly serializing access to it you're probably DOINITWRONG.
    2. You don't need to hook a function to call it, that's retarded, just call it using a function pointer!
    3. Did I mention that using static data that way is ****ING AWFUL?
    lua_dostring fails if I call it from my thread via a normal function pointer.
    Thats why I call it inside a hooked function.

    Yes I know using that bool is bad style. But it works for me perfectly at the moment, at least it didnt cause problems until now.

    Oh, and I don't see in how far my missing knowledge in how Windows manages memory/threads/processes shows the quality of my general c++ skills.

    @ramey: Repeating one time what Cypher said is enough to show you are his fanboy. Please stop posting nonsense.

  12. #12
    ramey's Avatar Member
    Reputation
    45
    Join Date
    Jan 2008
    Posts
    320
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by flo8464 View Post
    lua_dostring fails if I call it from my thread via a normal function pointer.
    Thats why I call it inside a hooked function.

    Yes I know using that bool is bad style. But it works for me perfectly at the moment, at least it didnt cause problems until now.

    Oh, and I don't see in how far my missing knowledge in how Windows manages memory/threads/processes shows the quality of my general c++ skills.

    @ramey: Repeating one time what Cypher said is enough to show you are his fanboy. Please stop posting nonsense.
    I think you are an idiot. Okayokay, let's try to get somewhere with your problem.

    Originally Posted by flo8464 View Post
    lua_dostring fails if I call it from my thread via a 'normal' function pointer
    What could you possibly be doing wrong? ****, I don't know, maybe calling it from your thread? Hell, even look at a AutoIt post and you will, might I say, learn something.

    You're INPROCESS(might be a shock), so what could you do to ****ing get it working properly? You could ****ing hook EndScene, because GUESS WHAT, EndScene is in the MAIN THREAD. IT MIGHT BE POSSIBLE that your problem is that you're not calling it from the main thread, and then you would be able to use a "normal" function pointer, or was it possible that you couldn't typedef shit?

    I would recommend that you go to an easier language, like Visual Basic. Judging by what you pasted in your first post, it looks suitable.

    Originally Posted by flo8464 View Post
    Oh, and I don't see in how far my missing knowledge in how Windows manages memory/threads/processes shows the quality of my general c++ skills.
    The amazing code you have pasted shows your also amazing C++ skills, after all, your variable naming convention is just beautiful. TrueLuaToString, global do_string bool, action... It's all just so obvious what they are, isn't it? Maybe you should think when you name your variables.

    Originally Posted by flo8464 View Post
    Repeating one time what Cypher said is enough to show you are his fanboy. Please stop posting nonsense.
    How did I "repeat one time" what Cypher said? I don't see how you can take "I agree" as repeating what he said. Are you a ****ing retard? Please, put some more effort into not just your insults but also put some effort into your "programming" knowledge, which seems to lack; just like your insults. Jesus Christ. Here you go, I think this link would help you out: AutoIt Forums . Now **** off, and bring your useless posts with you.

  13. #13
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I ll add to my note .. you are some unkind person.

    What could you possibly be doing wrong? ****, I don't know, maybe calling it from your thread? Hell, even look at a AutoIt post and you will, might I say, learn something.

    You're INPROCESS(might be a shock), so what could you do to ****ing get it working properly? You could ****ing hook EndScene, because GUESS WHAT, EndScene is in the MAIN THREAD. IT MIGHT BE POSSIBLE that your problem is that you're not calling it from the main thread, and then you would be able to use a "normal" function pointer, or was it possible that you couldn't typedef shit?

    I would recommend that you go to an easier language, like Visual Basic. Judging by what you pasted in your first post, it looks suitable.
    Ok, now think again Mr.
    I could hook EndScene. I hook lua_toString instead which also seems to be executed by WoWs Main thread.

    So it works, it already worked when I made the second post you are too stupid/ignorant to read.

    Second question, as you feel like some sort of elitist: What the hell is different in VisualBasic when doing that except VBs horrible syntax ?

    The amazing code you have pasted shows your also amazing C++ skills, after all, your variable naming convention is just beautiful. TrueLuaToString, global do_string bool, action... It's all just so obvious what they are, isn't it? Maybe you should think when you name your variables.
    Of course you can judge my variable naming conventions after I pasted 20 lines code out of 40 lines test code without any meaning.

    I got a link for you: Directupload.net - Dup3m9q6h.swf

    Now **** off, and bring your useless posts with you.
    Loled at that. Your last 100 postings were flames/spams without any meaning. I am sure you help this forum a lot, lol.
    Last edited by flo8464; 07-12-2009 at 05:16 PM.

  14. #14
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1358
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/6
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No flo. YOU are the idiot.

    Hooking EndScene makes sense. Hooking DoString makes none. From EndScene you can directly call any of the engine functions safely. You're not hooking an engine function, so you're safer from warden, and you're also thread-safe because you don't need to use any static data.

    VB is different in that it takes care of a lot of the low level details that are OBVIOUSLY way above your head. Please, for the sake of all our sanity, go to an easier language, because you have no idea what you're doing.

    It's obvious you're totally clueless, so you might want to ease up and stop flaming the people who actually do know what they're doing and are in a position to help you.

    Also, your code in general shows the "quality of your general C++ skills". Just from that tiny snippet I can tell straight away you're either VERY new to C++ or just a terrible programmer.

  15. #15
    flo8464's Avatar Active Member
    Reputation
    30
    Join Date
    Apr 2009
    Posts
    434
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    No flo. YOU are the idiot.
    When did I call someone an idiot ?

    Hooking EndScene makes sense. Hooking DoString makes none. From EndScene you can directly call any of the engine functions safely. You're not hooking an engine function, so you're safer from warden, and you're also thread-safe because you don't need to use any static data.
    Yes, Endscene is better. But my whole point was to get a __failfree__ doString for testing purposes. I am __not__ going to code a bot or stuff, I only wanted to get a __single function__ working.
    As long its working and I don't care about Warden and its much easier to autoupdate, I am fine with it.

    VB is different in that it takes care of a lot of the low level details that are OBVIOUSLY way above your head. Please, for the sake of all our sanity, go to an easier language, because you have no idea what you're doing.
    Which low level details do you mean? Its not clearly visible to me which are exactly above my head.

    It's obvious you're totally clueless, so you might want to ease up and stop flaming the people who actually do know what they're doing and are in a position to help you.
    I was flaming ramey as he doesn't help even a bit, has a gutter speech like a little uneducated child and doesn't show he knows what he is doing, at least I didn't read something usefull from him ever.

    [QUOTE]
    Also, your code in general shows the "quality of your general C++ skills". Just from that tiny snippet I can tell straight away you're either VERY new to C++ or just a terrible programmer.[/COLOR]

    I don't think the snippet speaks so much about me as it was created in like 5-6 line snippets and copied together later.

    Whenever I try to code something reuseable I put much more afford into it.

    Oh, and yes I am new to C++. Doing it for 4 month now, but read a lot of literature about it and coded (imo) pretty decent stuff which doesn't have to anything with the kind of stuff I try to do now.

Page 1 of 2 12 LastLast

Similar Threads

  1. Trouble hooking function with Detours
    By Miivers in forum WoW Memory Editing
    Replies: 5
    Last Post: 01-03-2016, 04:52 AM
  2. Understanding Detours and EndScene Hooking
    By berlinermauer in forum WoW Memory Editing
    Replies: 7
    Last Post: 10-04-2012, 02:08 PM
All times are GMT -5. The time now is 02:59 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search