How to access application's extern variable inside a dll
-
I have an application which has several extern variables, I need to access them inside dll. Is that possible?
-
I have an application which has several extern variables, I need to access them inside dll. Is that possible?
You may, for instance, pass them (their pointers or references) as parameters of a DLL function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
I have an application which has several extern variables, I need to access them inside dll. Is that possible?
-
You may, for instance, pass them (their pointers or references) as parameters of a DLL function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Thanks, I agree the way you are saying is right and genuine. But unfortunately I don't have exe's source code :) I have injected a dll into exe's process space and now want to get the data from exe's memory space. I tried with hooking the system level functions like LoadLibrary and TextOut etc but I could not hook GetProfileInt, CString's sprintf, format etc functions. Any way to do so ? I wonder who downvoted my question :D :D
-
Use a shared header externing the variable in the dll. Include this in the exe, and then the linker will do the rest for you.
============================== Nothing to say.
Thanks Eric, But I don't have exe's code. See my above reply for more details.
-
I have an application which has several extern variables, I need to access them inside dll. Is that possible?
you can access extern (and exported) variables in a DLL from an EXE. you cannot access variables in an EXE from a DLL. you could, in theory, decompile the EXE, find the references to the data you want, figure out if the data is statically or dynamically allocated, then create some mechanism to probe the EXE's memory at the right locations and times, etc.. a huge task.
-
you can access extern (and exported) variables in a DLL from an EXE. you cannot access variables in an EXE from a DLL. you could, in theory, decompile the EXE, find the references to the data you want, figure out if the data is statically or dynamically allocated, then create some mechanism to probe the EXE's memory at the right locations and times, etc.. a huge task.
Thanks Chris for verifying that I cannot access variables in an EXE from a DLL directly. So I am doing the Huge task. Still I think hooking should work as it is working for few of the functions; I will try a little more before leaving hooks.
-
Thanks, I agree the way you are saying is right and genuine. But unfortunately I don't have exe's source code :) I have injected a dll into exe's process space and now want to get the data from exe's memory space. I tried with hooking the system level functions like LoadLibrary and TextOut etc but I could not hook GetProfileInt, CString's sprintf, format etc functions. Any way to do so ? I wonder who downvoted my question :D :D
So you're an hacker?! :-D I upvoted your question for balancing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
So you're an hacker?! :-D I upvoted your question for balancing.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Nopes! I am not; but I like to explore the things at extreme level :-\
-
Thanks Chris for verifying that I cannot access variables in an EXE from a DLL directly. So I am doing the Huge task. Still I think hooking should work as it is working for few of the functions; I will try a little more before leaving hooks.
This is largely a waste of time as there is nothing in the executable file that would get you a reference to the location of the variables. The use of
extern
on a variable declaration merely tells the compiler that it exists in a different source module. Such references are then resolved by the linker but no more information about them is held in the EXE file.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
This is largely a waste of time as there is nothing in the executable file that would get you a reference to the location of the variables. The use of
extern
on a variable declaration merely tells the compiler that it exists in a different source module. Such references are then resolved by the linker but no more information about them is held in the EXE file.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
that's true. i suppose i left out the "...in a debugger..." part.
-
that's true. i suppose i left out the "...in a debugger..." part.
What you wrote looked fine to me; I just think the OP read more into it than you intended.
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman