Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Base Address

Base Address

Scheduled Pinned Locked Moved C / C++ / MFC
comhelpquestion
35 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Stephen Hewitt

    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

    S Offline
    S Offline
    Shouvik Das
    wrote on last edited by
    #14

    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

    1 Reply Last reply
    0
    • S Stephen Hewitt

      GetProcAddress will only work for exported functions.

      Steve

      S Offline
      S Offline
      Shouvik Das
      wrote on last edited by
      #15

      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

      S 1 Reply Last reply
      0
      • S Shouvik Das

        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

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #16

        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

        S 1 Reply Last reply
        0
        • S Stephen Hewitt

          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

          S Offline
          S Offline
          Shouvik Das
          wrote on last edited by
          #17

          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

          S 1 Reply Last reply
          0
          • S Shouvik Das

            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

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #18

            All EXEs and DLLs produced by VC++6.0 are PE files. Even dotNET assemblies are PE files.

            Steve

            S 1 Reply Last reply
            0
            • S Stephen Hewitt

              All EXEs and DLLs produced by VC++6.0 are PE files. Even dotNET assemblies are PE files.

              Steve

              S Offline
              S Offline
              Shouvik Das
              wrote on last edited by
              #19

              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

              S 1 Reply Last reply
              0
              • S Shouvik Das

                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

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #20

                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

                S 2 Replies Last reply
                0
                • S Stephen Hewitt

                  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

                  S Offline
                  S Offline
                  Shouvik Das
                  wrote on last edited by
                  #21

                  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

                  1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    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

                    S Offline
                    S Offline
                    Shouvik Das
                    wrote on last edited by
                    #22

                    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

                    S 1 Reply Last reply
                    0
                    • S Shouvik Das

                      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

                      S Offline
                      S Offline
                      Stephen Hewitt
                      wrote on last edited by
                      #23

                      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

                      S 4 Replies Last reply
                      0
                      • S Shouvik Das

                        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

                        N Offline
                        N Offline
                        Naveen
                        wrote on last edited by
                        #24

                        1 simple doubt.. why cant u change the private to public?

                        nave

                        S 2 Replies Last reply
                        0
                        • S Stephen Hewitt

                          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

                          S Offline
                          S Offline
                          Shouvik Das
                          wrote on last edited by
                          #25

                          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

                          1 Reply Last reply
                          0
                          • N Naveen

                            1 simple doubt.. why cant u change the private to public?

                            nave

                            S Offline
                            S Offline
                            Shouvik Das
                            wrote on last edited by
                            #26

                            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

                            1 Reply Last reply
                            0
                            • N Naveen

                              1 simple doubt.. why cant u change the private to public?

                              nave

                              S Offline
                              S Offline
                              Shouvik Das
                              wrote on last edited by
                              #27

                              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

                              N 2 Replies Last reply
                              0
                              • S Shouvik Das

                                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

                                N Offline
                                N Offline
                                Naveen
                                wrote on last edited by
                                #28

                                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

                                1 Reply Last reply
                                0
                                • S Shouvik Das

                                  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

                                  N Offline
                                  N Offline
                                  Naveen
                                  wrote on last edited by
                                  #29

                                  please let me know the above metioned way will work or not in ur case...

                                  nave

                                  S 1 Reply Last reply
                                  0
                                  • N Naveen

                                    please let me know the above metioned way will work or not in ur case...

                                    nave

                                    S Offline
                                    S Offline
                                    Shouvik Das
                                    wrote on last edited by
                                    #30

                                    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

                                    N 1 Reply Last reply
                                    0
                                    • S Shouvik Das

                                      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

                                      N Offline
                                      N Offline
                                      Naveen
                                      wrote on last edited by
                                      #31

                                      shouvik.d wrote:

                                      the addres is always a Rva

                                      Rva means? so then how u gonne do it?

                                      nave

                                      S 1 Reply Last reply
                                      0
                                      • N Naveen

                                        shouvik.d wrote:

                                        the addres is always a Rva

                                        Rva means? so then how u gonne do it?

                                        nave

                                        S Offline
                                        S Offline
                                        Shouvik Das
                                        wrote on last edited by
                                        #32

                                        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

                                        1 Reply Last reply
                                        0
                                        • S Stephen Hewitt

                                          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

                                          S Offline
                                          S Offline
                                          Shouvik Das
                                          wrote on last edited by
                                          #33

                                          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

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups