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. get the function address from it's name using IMAGE_IMPORT_DESCRIPTOR

get the function address from it's name using IMAGE_IMPORT_DESCRIPTOR

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
7 Posts 3 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.
  • J Offline
    J Offline
    JoneLe86
    wrote on last edited by
    #1

    I can get the linked functions in any file by using IMAGE_IMPORT_DESCRIPTOR, but how in this world I can get their addresses? Assuming AddAtomA is the target .... Asm code: (jmp dword ptr ds:004050b8)in memory address of 004050b8 is 779B9EB8 which is function AddAtomA so is there any way to show the AddAtomA address while using IMAGE_IMPORT_DESCRIPTOR or showing the place where it will be called in the program?

    P 1 Reply Last reply
    0
    • J JoneLe86

      I can get the linked functions in any file by using IMAGE_IMPORT_DESCRIPTOR, but how in this world I can get their addresses? Assuming AddAtomA is the target .... Asm code: (jmp dword ptr ds:004050b8)in memory address of 004050b8 is 779B9EB8 which is function AddAtomA so is there any way to show the AddAtomA address while using IMAGE_IMPORT_DESCRIPTOR or showing the place where it will be called in the program?

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      The actual address of a function that is imported from another module is resolved while loading your image. If the other image is a dll then it can be loaded to any address if it has a relocation table. If you are curious about the address of a function whose code is in a builtin system dll then you can ask the function address with (GetModuleHandle() or LoadLibrary()) + GetProcAddress() yourself in your program without reading anything from an exe/dll file as some builtin dlls (kernel32, user32) are loaded to the same virtual address in the virtual memory space of every process in the system (at least on 32 bit windows versions, never tried the 64 bit ones). This is an old trick. This has nothing to do with the IMAGE_IMPORT_DESCRITPTOR of a specific image, this way you retrieve a constant that is guaranteed to be constant from system startup to system shutdown.

      J Richard Andrew x64R 2 Replies Last reply
      0
      • P pasztorpisti

        The actual address of a function that is imported from another module is resolved while loading your image. If the other image is a dll then it can be loaded to any address if it has a relocation table. If you are curious about the address of a function whose code is in a builtin system dll then you can ask the function address with (GetModuleHandle() or LoadLibrary()) + GetProcAddress() yourself in your program without reading anything from an exe/dll file as some builtin dlls (kernel32, user32) are loaded to the same virtual address in the virtual memory space of every process in the system (at least on 32 bit windows versions, never tried the 64 bit ones). This is an old trick. This has nothing to do with the IMAGE_IMPORT_DESCRITPTOR of a specific image, this way you retrieve a constant that is guaranteed to be constant from system startup to system shutdown.

        J Offline
        J Offline
        JoneLe86
        wrote on last edited by
        #3

        :thumbsup: thanks

        P 2 Replies Last reply
        0
        • J JoneLe86

          :thumbsup: thanks

          P Offline
          P Offline
          pasztorpisti
          wrote on last edited by
          #4

          You are welcome! Was everything clear?

          1 Reply Last reply
          0
          • J JoneLe86

            :thumbsup: thanks

            P Offline
            P Offline
            pasztorpisti
            wrote on last edited by
            #5

            BTW, this trick is guaranteed to work only with user32 and kernel32, I never tried it with other dlls. These dlls are usually mapped to 7xxxxxxx addresses as you see in your example.

            1 Reply Last reply
            0
            • P pasztorpisti

              The actual address of a function that is imported from another module is resolved while loading your image. If the other image is a dll then it can be loaded to any address if it has a relocation table. If you are curious about the address of a function whose code is in a builtin system dll then you can ask the function address with (GetModuleHandle() or LoadLibrary()) + GetProcAddress() yourself in your program without reading anything from an exe/dll file as some builtin dlls (kernel32, user32) are loaded to the same virtual address in the virtual memory space of every process in the system (at least on 32 bit windows versions, never tried the 64 bit ones). This is an old trick. This has nothing to do with the IMAGE_IMPORT_DESCRITPTOR of a specific image, this way you retrieve a constant that is guaranteed to be constant from system startup to system shutdown.

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              pasztorpisti wrote:

              some builtin dlls (kernel32, user32) are loaded to the same virtual address in the virtual memory space of every process in the system

              Don't forget about ASLR![^]

              The difficult we do right away... ...the impossible takes slightly longer.

              P 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                pasztorpisti wrote:

                some builtin dlls (kernel32, user32) are loaded to the same virtual address in the virtual memory space of every process in the system

                Don't forget about ASLR![^]

                The difficult we do right away... ...the impossible takes slightly longer.

                P Offline
                P Offline
                pasztorpisti
                wrote on last edited by
                #7

                You are right, thank you for mentioning. I was playing around with these things long ago...

                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