-
August 5th, 2016, 11:16 PM
#1
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.
-
August 6th, 2016, 04:01 PM
#2
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
-
August 6th, 2016, 09:45 PM
#3
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.
-
August 7th, 2016, 04:04 AM
#4
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
-
August 7th, 2016, 01:41 PM
#5
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.
-
August 7th, 2016, 09:43 PM
#6
Re: Instantianting different copies of a class where there is a static function in it
Thanks Arjay,
let me think about it.
-
August 8th, 2016, 09:54 PM
#7
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.
-
August 9th, 2016, 05:52 AM
#8
Re: Instantianting different copies of a class where there is a static function in it
Originally Posted by lucky6969b
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
-
August 9th, 2016, 09:07 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|