[Help] Have code injected *only* when required. menu

User Tag List

Results 1 to 9 of 9
  1. #1
    vulcanaoc's Avatar Member
    Reputation
    31
    Join Date
    Jul 2008
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Help] Have code injected *only* when required.

    Hey,

    As a precaution against warden, and for my own knowledge, I've been toying around with only having my DLL loaded while it is actually doing something. I can't seem to get it to work, though (code hooking/unhooking is leading to crashes.) I also think there might be a far simpler solution that I'm overlooking.

    Here's what I've been doing
    (assume all remote threads exit before the next operation begins)
    From out of process:

    Suspend WoW's main thread.
    Inject dll with CreateRemoteThread. (Nothing is done in DllMain)
    Hook EndScene with CreateRemoteThread.
    Use IPC to flag that an operation must be done (I.E. DoString)
    Resume WoW's main thread.
    Wait for EndScene to call my hook, and flag that the operation has completed.
    //before uninjecting, my hooks must be removed, but I'm having trouble removing them reliably without WoW calling code that is no longer there.
    Uninject.

    I've tried using CreateRemoteThread to unhook EndScene (which doesn't work without crashing).

    I've also tried modifying my hooking code so as to restore the original function right after my hook has been called. This crashes if I don't do a sleep until the next frame, which is unacceptable and unpredictable.

    Thanks in advance for any advice...

    [Help] Have code injected *only* when required.
  2. #2
    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)
    Wtf?

    No, this is a terrible idea.

  3. #3
    vulcanaoc's Avatar Member
    Reputation
    31
    Join Date
    Jul 2008
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Cypher View Post
    Wtf?

    No, this is a terrible idea.
    Better ideas?

    *braces*

  4. #4
    vulcanaoc's Avatar Member
    Reputation
    31
    Join Date
    Jul 2008
    Posts
    125
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Let me rephrase: what is a good way to unhook so I can uninject my dll safely?

    Also, I realize you're not a fan of CreateRemoteThread for various reasons which you have laid out in other threads. What are some better alternatives?

  5. #5
    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)
    Let me rephrase: what is a good way to unhook so I can uninject my dll safely?
    What do you mean? You're in process, and you're using CreateRemoteThread in EndScene? Don't. To remove the hooks after you're finished or whatever just simply DetourDetach( MS detours 2.1 ), DetourRemove( MS detours 1.5 ), or whatever you're using. Then destruct anything you have allocated using the new keyword with delete, would be a good idea to set any pointers that you're deleting to 0 after them.

    Personally, I'm either way too tired and got up too early and don't really understand why you want to do this. You are probably having problems with removing hooks because you're using CreateRemoteThread. Why aren't you putting anything in DllMain? Just allocate a class, and do your stuff in the class constructor.

    Something like this( i'm realllyyy tired, so don't take any notice if i'm completely wrong )

    Code:
    class CClass 
    {
    
    
    public:
    	CClass();	// Constructor
    	~CClass();	// Destructor
    
    };
    
    CClass * gpClassWhatever = 0;
    
    CClass::CClass()
    {
    	// Attach your hooks here, whatever you want to do
    }
    
    CClass::~CClass()
    {
    	// Detach your hooks here
    }
    
    BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
    {
    	switch( dwReason )
    	{
    	case DLL_PROCESS_ATTACH:
    		{	
    			gpClassWhatever = new CClass();
    
    			break;
    		}
    	case DLL_PROCESS_DETACH:
    		{
    		        delete gpClassWhatever;
                            gpClassWhatever = 0;
    
    			break;
    		}
    	}
    	return true;
    }

    I don't exactly understand what kind of answer you were expecting, so I hope this is somewhat helpful, because I saw that you were having problems how to start hooks too it seems in your injected DLL, CreateRemoteThread.. Don't get why you were doing that in-process. Also, if you're having problems on how to use hooks, google.

  6. #6
    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
    What do you mean? You're in process, and you're using CreateRemoteThread in EndScene? Don't. To remove the hooks after you're finished or whatever just simply DetourDetach( MS detours 2.1 ), DetourRemove( MS detours 1.5 ), or whatever you're using. Then destruct anything you have allocated using the new keyword with delete, would be a good idea to set any pointers that you're deleting to 0 after them.

    Personally, I'm either way too tired and got up too early and don't really understand why you want to do this. You are probably having problems with removing hooks because you're using CreateRemoteThread. Why aren't you putting anything in DllMain? Just allocate a class, and do your stuff in the class constructor.

    Something like this( i'm realllyyy tired, so don't take any notice if i'm completely wrong )

    Code:
    class CClass 
    {
    
    
    public:
    	CClass();	// Constructor
    	~CClass();	// Destructor
    
    };
    
    CClass * gpClassWhatever = 0;
    
    CClass::CClass()
    {
    	// Attach your hooks here, whatever you want to do
    }
    
    CClass::~CClass()
    {
    	// Detach your hooks here
    }
    
    BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
    {
    	switch( dwReason )
    	{
    	case DLL_PROCESS_ATTACH:
    		{	
    			gpClassWhatever = new CClass();
    
    			break;
    		}
    	case DLL_PROCESS_DETACH:
    		{
    		        delete gpClassWhatever;
                            gpClassWhatever = 0;
    
    			break;
    		}
    	}
    	return true;
    }

    I don't exactly understand what kind of answer you were expecting, so I hope this is somewhat helpful, because I saw that you were having problems how to start hooks too it seems in your injected DLL, CreateRemoteThread.. Don't get why you were doing that in-process. Also, if you're having problems on how to use hooks, google.
    You shouldn't do that. It's not safe to do a lot of things in DllMain (for the full list, please consult MSDN). You should instead export an initialization function and do all your real work in there.

    Also, that doesn't solve this problem:
    Hook EndScene
    Code in EndScene is executing
    You attempt an unload

    That's all it takes. If you remove your module while its code is being executed your process will blow up.

    I work around this problem in Hades by using an extension system and a "safe" callback system for potentially dangerous hooks. But that's a tad more complex than most people would want I assume.

    Also, you still need a remote thread to do both the injection and the ejection, as you obviously can't do it from inside one of your hooks.

  7. #7
    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
    You shouldn't do that. It's not safe to do a lot of things in DllMain (for the full list, please consult MSDN). You should instead export an initialization function and do all your real work in there.

    Also, that doesn't solve this problem:
    Hook EndScene
    Code in EndScene is executing
    You attempt an unload

    That's all it takes. If you remove your module while its code is being executed your process will blow up.

    I work around this problem in Hades by using an extension system and a "safe" callback system for potentially dangerous hooks. But that's a tad more complex than most people would want I assume.

    Also, you still need a remote thread to do both the injection and the ejection, as you obviously can't do it from inside one of your hooks.
    Thanks, I'll checkout MSDN. I remember hearing something about that, but just couldn't be bothered changing it. Thanks for the heads up!

    I also kind of missed the problem that he was having, I think...

    I'm interested in your "safe" callback system, mind sharing or nono?

  8. #8
    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
    Thanks, I'll checkout MSDN. I remember hearing something about that, but just couldn't be bothered changing it. Thanks for the heads up!

    I also kind of missed the problem that he was having, I think...

    I'm interested in your "safe" callback system, mind sharing or nono?

    The backend is Boost.Signals2, I've simply wrapped it in a bunch of code so I can ensure that all extensions are accessed by Hades (and hence the game) in a single-threaded manner, thus eliminating the possibility of a race condition in a multi-threaded environment and a module ejection whilst code inside it is being executed.

    It's not hard to do.

  9. #9
    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

    The backend is Boost.Signals2, I've simply wrapped it in a bunch of code so I can ensure that all extensions are accessed by Hades (and hence the game) in a single-threaded manner, thus eliminating the possibility of a race condition in a multi-threaded environment and a module ejection whilst code inside it is being executed.

    It's not hard to do.
    I actually had problems with race conditions when I was writing something similar to what you were writing, minus portablity, minus CEGUI. I dropped the modules and went for a WoW only approach. I might take it back up in the future some time, and if I do, I will be sure to check that out. Cheers again

Similar Threads

  1. [HELP] Editing character model ONLY?
    By Flail in forum WoW ME Questions and Requests
    Replies: 2
    Last Post: 04-23-2008, 09:40 AM
  2. [HELP] Having trouble getting poeple to connect! (Can Tip)
    By Hostilex12345 in forum World of Warcraft Emulator Servers
    Replies: 12
    Last Post: 03-26-2008, 04:46 AM
  3. help having a problem creating objects
    By wowperson in forum World of Warcraft Emulator Servers
    Replies: 3
    Last Post: 03-09-2008, 10:01 PM
  4. [Help Thread] Coding in LavishScript
    By Apoc in forum World of Warcraft Bots and Programs
    Replies: 4
    Last Post: 02-19-2008, 02:35 PM
  5. [Help] Need code 4 players to start with 1 item.
    By jokerjokes in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 12-21-2007, 11:18 PM
All times are GMT -5. The time now is 01:10 AM. 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