Base Address
-
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
-
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
i am not sure Suppose ur class have a public function. U can get the address of that function at the runtime. The private function will be also at some address near to it. By adding some value to the address of the public function u can get the address of private function.
nave
-
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
-
yes but the addres is always a Rva so u cant just add subtract like tht. Its better to leave it to the compiler to do it. even though u will use sizeof() opeartor knowing the load address is imp 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
-
yes but the addres is always a Rva so u cant just add subtract like tht. Its better to leave it to the compiler to do it. even though u will use sizeof() opeartor knowing the load address is imp 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
-
Rva means relative virtual address. have you taken a look at the map file i mean are you aware of the map file structure.
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
hi steve your help has pulled me off a catastrophe. I did the tokenizing of the .map file and could retrieve the address. noe since the address is of a string type in the as 0x00401190 so now i need to convert it into a HEX format. then I can pass it as an address where earlier we were passing the constant adress. So the dangling pointer error is removed. thanks for the immense help you have provided
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
I did a conversion for string type to unsigned long using strtoul() method. Now works fine
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
So when I could achieve it in VC now next comes in line is GCC where the name mangling starts with _Z and then few traits are there. Anyhow can you help me out in generating the map file for a GCC environment. I mean a detailed help. I really am greatful to you for the help you extended hence looking forward for a next one;). Thanks steve!:)
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