CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Dec 2010
    Posts
    907

    Instantianting different copies of a class where there is a static function in it?

    Hello,
    In the code snippet below,
    You can see that the Hook function must be static if I want to assign the function pointer
    to newStruct->pNewFunc, as a consequence, all new'ed copies of newStruct point
    to the same function address. I don't really want that, I want each copy of
    newStruct->pNewFunc to point to a different address, how can I make it happen?
    Thanks
    Jack

    Code:
    // This class is exported from the ThreadSpy.dll
    typedef struct
    {
    	char		szDLLName[MAX_PATH];	// The DLL name
    	char		szFuncName[MAX_PATH];	// The function name
    	void *		pNewFunc;				// The new function pointer
    	void *		pPrevFunc;				// The previous function pointer	 	 
    	Flags		flags;					// The flags (hooked or not, etc...)
    	DWORD       iat;                    // The Address of the import table
    } HookStruct;
    
    class Hookerr
    {
    public:
    	Hookerr(std::string _module, std::string _api, DWORD _originalFunc)		 
    	{
    		module = _module;
    		api = _api;
    		orignalFunc = (void*)_originalFunc;
    	}
    
    	static std::string module;
    	static std::string api;
    	static void* orignalFunc;
    
    	//BOOL WINAPI Hook(int n_args, ...);
    	static void Hook(void);
    };
    
    
    newHooker.reset(new Hookerr(fullPath, api, mp.first.addr));
    
    strcpy(newStruct->szDLLName, fullPath.c_str());
    strcpy(newStruct->szFuncName, mp.second.c_str());
    newStruct->pPrevFunc = (void*)mp.first.addr; 
    newStruct->flags = NotHookedYet;
    newStruct->pNewFunc = &newHooker->Hook;
    Last edited by lucky6969b; August 5th, 2016 at 11:23 PM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Instantianting different copies of a class where there is a static function in it

    I have no idea what you what to achieve and why you want it...
    However, static class member means it is the same (one and only one!) for all the class instances.
    Victor Nijegorodov

  3. #3
    Join Date
    Dec 2010
    Posts
    907

    Re: Instantianting different copies of a class where there is a static function in it

    Hello Victor,
    I want to hook the whole module of windows like kernel32.dll dynamically.
    Because it's too time consuming to write each function individually,
    I want to do that dynamically.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Instantianting different copies of a class where there is a static function in it

    Then just look for another way to implement your "hook"...
    Victor Nijegorodov

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Instantianting different copies of a class where there is a static function in it

    Inside the static hook class, call a singleton class that manages your instance data.

  6. #6
    Join Date
    Dec 2010
    Posts
    907

    Re: Instantianting different copies of a class where there is a static function in it

    Thanks Arjay,
    let me think about it.

  7. #7
    Join Date
    Dec 2010
    Posts
    907

    Re: Instantianting different copies of a class where there is a static function in it

    Hello,
    Sorry for trying too hard
    But in this case, all apis and modules are hooked to the user space, but there are still some kernel space access?
    How do I get around this? Basically, I am just hooking them to the user space, once they are hooked, they don't call anything,

    Do I have to hook the EAT as well?

    Code:
    [02F10000] Currently hooking 7125 from 05B43028
    Entered critical section 00573968
    Function SetWindowTheme from .//modified//^XTHEME.DLL is found at 02F10000
    Function ^XTHEME.DLL is found at 05B430D0
    Function ^XTHEME.DLL is now found at 05AACD38 should be 05AACD38 <<<<< Module in user space
    Replaced function SetWindowTheme from 02F10000 to 05AACD38 <<<<< api in user space
    Leaved critical section 00573968
    
    Fixing Image Base address in PEB
    
    Executing Entry Point: 0x02f260cc
    First-chance exception at 0x77E5A682 in Pe-Loader-Sample.exe: 0xC0000005: Access violation executing location 0x77E5A682. << still using kernel pointers.....
    Last edited by lucky6969b; August 8th, 2016 at 09:56 PM.

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Instantianting different copies of a class where there is a static function in it

    Quote Originally Posted by lucky6969b View Post
    all apis and modules are hooked to the user space, but there are still some kernel space access?
    How do I get around this? Basically, I am just hooking them to the user space, once they are hooked, they don't call anything,
    Maybe your idea of hooking is a little bit wrong. Maybe you should explain it a little bit more verbose.
    Best regards,
    Igor

  9. #9
    Join Date
    Feb 2013
    Location
    Canada
    Posts
    52

    Re: Instantianting different copies of a class where there is a static function in it

    You don't hook the EAT (by itself), but you can walk it to look for something or hook a function from it at program runtime and it will only work on programs that explicitly link against libraries. You also don't hook DLL's by themselves, I think more clarification is required -- what are you trying to do with your "hook" exactly? The idea of a static object should be self-explanatory as well, you simply can't do what you're trying to do with allowing them to have different addresses, that's why they are "static".
    Last edited by AceInfinity; August 9th, 2016 at 09:16 PM.
    [sigpic][/sigpic]
    Microsoft MVP .NET Programming (2012 - Present)
    ®Crestron DMC-T Certified Automation Programmer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured