Base Address
-
Why do you want this? This is a wierd way to go about doing things.
Steve
That's because no other way can i bypass the private method access in C++(perfectly non malicious intention). Read my previous posts in this forum titled private access and as well the links in the first post. I think you will get a better idea
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
shouvik.d wrote:
i();
if ur going to call a member function of a class like this.. u need to pass the "this" parameter also. Isn't it?
nave
Exactly...u're correct. I's actually experimenting for past many days and yesterday night ended up like this. Slowly i'll escalate it to OO paradigm. currently my problem is regarding my post only
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
Hi all, we al know the preffered load address of any proj is 0x00400000 and DLL is 0x10000000. now if the OS is unable to use this address it relocates the project. now i have a need to use the Rva+Base address of all the methods available in a class within a project. One method is reading the map file but say if u don't have the address available so relocation takes place hence the safest way is to dynamicaly obtain it hence i want to know is there any way of obtaining the base address or the load address of a process. if at all you feel this is not a viable solution then can i obtain the current address from the mangled names like ?show@disp@@QAEXXZ for a public method show belonging to class disp. undname just gives the resolved name but its of no use in callin a function. so can you people just help me out for a better idea u can refer 1)Mangled Name[^] 2)Private Access[^]
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
The
HINSTANCE
of a module is its load address. The address you get fromGetProcAddress()
points directly at the code, which is in the part of the address space that the module is mapped to.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
-
The
HINSTANCE
of a module is its load address. The address you get fromGetProcAddress()
points directly at the code, which is in the part of the address space that the module is mapped to.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
To use
GetProcAddress()
the source classes should be a DLL project. :( unfortunately they are not. hence its only during build time i can resolve the address. Wat do you suggest. Make sure one thing that I can't change one byte in the source classes provided to me. I've to apply means to access the methods in them be it private or public. Name mangling resolvng is one of the issues that can suffice to my needs
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
That's because no other way can i bypass the private method access in C++(perfectly non malicious intention). Read my previous posts in this forum titled private access and as well the links in the first post. I think you will get a better idea
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
Firstly, .EXEs are not relocated as they are the first module loaded and thus always get loaded at their preferred base address. Even if this wasn’t true, or you were working with a DLL, the code I gave earlier can help you. Translate your address into an offset by subtracting the preferred base address from it then add this to the actual base address. Finally a disclaimer: what you are doing is perverse and I don’t approve of it.
Steve
-
The
HINSTANCE
of a module is its load address. The address you get fromGetProcAddress()
points directly at the code, which is in the part of the address space that the module is mapped to.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ"); Ford, what's this fish doing in my ear?
GetProcAddress
will only work for exported functions.Steve
-
Firstly, .EXEs are not relocated as they are the first module loaded and thus always get loaded at their preferred base address. Even if this wasn’t true, or you were working with a DLL, the code I gave earlier can help you. Translate your address into an offset by subtracting the preferred base address from it then add this to the actual base address. Finally a disclaimer: what you are doing is perverse and I don’t approve of it.
Steve
Stephen Hewitt wrote:
Finally a disclaimer: what you are doing is perverse and I don’t approve of it
well thhis has been a blow in all forums i went.:( Ok fine, you mean to say that even if the preferred load adddres is not empty i'm deemed to get my .EXE running there. This might lift a lot of load
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
GetProcAddress
will only work for exported functions.Steve
by exported u mean i need to create a .def and dll isn't it
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
by exported u mean i need to create a .def and dll isn't it
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
Yeah. I see no technical reason why an .EXE can't have exports (the PE file format would allow it) but when I've tried (in the past) it hasn't worked.
Steve
-
Yeah. I see no technical reason why an .EXE can't have exports (the PE file format would allow it) but when I've tried (in the past) it hasn't worked.
Steve
really stephen u seem to read my mind.;) Yes I tried to learn about Portable Executables but dont know how to implement them in VC++6.0. CAn you help me out please. i mean i really am a mediocre :-O with C++
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
really stephen u seem to read my mind.;) Yes I tried to learn about Portable Executables but dont know how to implement them in VC++6.0. CAn you help me out please. i mean i really am a mediocre :-O with C++
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
All EXEs and DLLs produced by VC++6.0 are PE files. Even dotNET assemblies are PE files.
Steve
-
All EXEs and DLLs produced by VC++6.0 are PE files. Even dotNET assemblies are PE files.
Steve
ok then here is wat you will feel is useful 1)I've set of few classes 2)I'm not allowed to change anything in "1" 3)I'll create my own class(es) and rebuild it along with the above set. now tell me when there is no scope of creating an EXE only using '1)' how do i access the private methods residing in '1)'. To do that i thought of using the base address to offset and locate the desired method or else use the name mangles and resolve. now in this scenario how eil PE help me out. Just let me know how does my flow of work should be and where sould PE fit in
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
ok then here is wat you will feel is useful 1)I've set of few classes 2)I'm not allowed to change anything in "1" 3)I'll create my own class(es) and rebuild it along with the above set. now tell me when there is no scope of creating an EXE only using '1)' how do i access the private methods residing in '1)'. To do that i thought of using the base address to offset and locate the desired method or else use the name mangles and resolve. now in this scenario how eil PE help me out. Just let me know how does my flow of work should be and where sould PE fit in
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
This is what you're trying to do but should not even consider:
// Win32.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
class CMyClass
{
private:
void Private();
};
void CMyClass::Private()
{
MessageBox(NULL, "CMyClass::Private", NULL, MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Type for a pointer to a member of "CMyClass" which returns and accepts nothing.
typedef void (CMyClass::*PMyClassMemFun)();
// Set the pointer from the address in the map file.
PMyClassMemFun pFunc;
*reinterpret_cast<ULONG_PTR*>(&pFunc) = 0x00401020; // From map file.
// Instantiate the class and call the private function.
CMyClass inst;
(inst.*pFunc)();
return 0;
}Again I reiterate; this is perverse but that's code to do what you we're trying to do. NOTE: You have to compile this code and then get the address from the map file. There is no guarantee your address is the same as mine. Any code changes and the address could change.
Steve
-
This is what you're trying to do but should not even consider:
// Win32.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
class CMyClass
{
private:
void Private();
};
void CMyClass::Private()
{
MessageBox(NULL, "CMyClass::Private", NULL, MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Type for a pointer to a member of "CMyClass" which returns and accepts nothing.
typedef void (CMyClass::*PMyClassMemFun)();
// Set the pointer from the address in the map file.
PMyClassMemFun pFunc;
*reinterpret_cast<ULONG_PTR*>(&pFunc) = 0x00401020; // From map file.
// Instantiate the class and call the private function.
CMyClass inst;
(inst.*pFunc)();
return 0;
}Again I reiterate; this is perverse but that's code to do what you we're trying to do. NOTE: You have to compile this code and then get the address from the map file. There is no guarantee your address is the same as mine. Any code changes and the address could change.
Steve
Stephen Hewitt wrote:
*reinterpret_cast(&pFunc) = 0x00401020; // From map file
yes i too did use the address statically. I wanted to ask you if at all I can get the address while i'm building only. Remember I said I can't go for EXEs alone with source class set.\ Thanks anyways. Your help is really solicited.
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
This is what you're trying to do but should not even consider:
// Win32.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <windows.h>
class CMyClass
{
private:
void Private();
};
void CMyClass::Private()
{
MessageBox(NULL, "CMyClass::Private", NULL, MB_OK);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Type for a pointer to a member of "CMyClass" which returns and accepts nothing.
typedef void (CMyClass::*PMyClassMemFun)();
// Set the pointer from the address in the map file.
PMyClassMemFun pFunc;
*reinterpret_cast<ULONG_PTR*>(&pFunc) = 0x00401020; // From map file.
// Instantiate the class and call the private function.
CMyClass inst;
(inst.*pFunc)();
return 0;
}Again I reiterate; this is perverse but that's code to do what you we're trying to do. NOTE: You have to compile this code and then get the address from the map file. There is no guarantee your address is the same as mine. Any code changes and the address could change.
Steve
I mean all is adhering to my requirements only one thing that I'm using static address. Is there no method to get the address from mangled name
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
I mean all is adhering to my requirements only one thing that I'm using static address. Is there no method to get the address from mangled name
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
Theoretically even recompiling the EXE to update the address could change the address (although in practice this is unlikely). The best approach would be to read in the address at runtime from a file you produce after the build is complete by parsing the map file. Not that I approve of such things;
private
functions are private for a reason.Steve
-
Exactly...u're correct. I's actually experimenting for past many days and yesterday night ended up like this. Slowly i'll escalate it to OO paradigm. currently my problem is regarding my post only
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
Theoretically even recompiling the EXE to update the address could change the address (although in practice this is unlikely). The best approach would be to read in the address at runtime from a file you produce after the build is complete by parsing the map file. Not that I approve of such things;
private
functions are private for a reason.Steve
Exactly...what i thought ou too said. I know how VC mangles the name so I can parse and read the Address. But now in this again i've a doubt. When I compile the files(source classes) then try to build it along with my classes. So the earlier one will generate a map file Will the address remain the same when i rebuild the application along with my class(es) Am i too ambiguous???:-0
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
Naveen R wrote:
why cant u change the private to public
Read my first post. I said I can't change 1 byte in the source classes
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik
-
Sorry naveen Read this Proj details[^]
There are only two kinds of people who are really fascinating-people who know absolutely everything, and people who know absolutely nothing. Oscar Wilde (1854-1900) Regards... Shouvik