Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:00:42+00:00 2026-06-01T16:00:42+00:00

I want to call a function in a remote process of an injected DLL

  • 0

I want to call a function in a remote process of an injected DLL that I’ve made.

I have successfully injected my DLL with:

CreateRemoteThread(pHandle, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("kernel32"), "LoadLibraryA"), pLibRemote, 0, NULL);

The DllMain is executed and the DLL is running in a stand-by mode. What I would like to do is somehow call the remotely loaded DLL in order to do some work.

I have tried exporting the function like this:

extern "C" __declspec(dllexport) void MyFunc(void)

and then executing the function like this:

CreateRemoteThread(pHandle, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("mydll"), "MyFunc"), NULL, 0, NULL);

but it results in a crash.

How can I solve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:00:43+00:00Added an answer on June 1, 2026 at 4:00 pm

    Calling GetModuleHandle as you have will get the base of the DLL as it is mapped into your process (if at all). So what you need to do is first make sure to export the function in the DLL. You can do as you have done or create a .def file as shown here. Thereafter:

    In Theory

    1. Inject the DLL to the target process and get the base address it was loaded at
    2. Inject the DLL to the current process. Use GetProcAddress to find the offset between the exported function and the base of the DLL.
    3. Add this offset to the base address obtained from step 1. CreateRemoteThread at this location.

    In Practice

    When doing your DLL injection, it is possible for you to get the base that your DLL is loaded into the target.

    HMODULE hInjected;
    
    hThread = CreateRemoteThread( hProcess, NULL, 0,
          (LPTHREAD_START_ROUTINE)( GetProcAddress( hMod,
          "LoadLibraryW" ) ), lpAddress, 0, NULL );
    
    // Locate address our payload was loaded
    if( hThread != 0 ) {
      WaitForSingleObject( hThread, INFINITE );
      GetExitCodeThread( hThread, ( LPDWORD )&hInjected );
      CloseHandle( hThread );
    }
    

    hInjected will be the base of the injected DLL. I then have another function:

    void* GetPayloadExportAddr( LPCWSTR lpPath, HMODULE hPayloadBase, LPCSTR lpFunctionName ) {
      // Load payload in our own virtual address space
      HMODULE hLoaded = LoadLibrary( lpPath );
    
      if( hLoaded == NULL ) {
        return NULL;
      } else {
        void* lpFunc   = GetProcAddress( hLoaded, lpFunctionName );
        DWORD dwOffset = (char*)lpFunc - (char*)hLoaded;
    
        FreeLibrary( hLoaded );
        return (DWORD)hPayloadBase + dwOffset;
      }
    }
    

    What this does is first load the payload into our own virtual address space. Afterwards,
    we can use GetProcAddress to get the address of the exported function. From this, we can get the offset of the function from the base of the DLL. Adding this offset to the hInjected we got earlier will tell us where the CreateRemoteThread call should be made. So you could make a call like so:

    BOOL InitPayload( HANDLE hProcess, LPCWSTR lpPath, HMODULE hPayloadBase, HWND hwndDlg ) {
      void* lpInit = GetPayloadExportAddr( lpPath, hPayloadBase, "Init" );
      if( lpInit == NULL ) {
        return FALSE;
      } else {
        HANDLE hThread = CreateRemoteThread( hProcess, NULL, 0,
            lpInit, hwndDlg, 0, NULL );
    
        if( hThread == NULL ) {
          return FALSE;
        } else {
          CloseHandle( hThread );
        }
      }
    
      return TRUE;
    }
    

    This is all code that is ripped out of an old project I have. You’re welcome to take the code and do whatever you want with it but I know if I were to rewrite the code now, I would do a lot of things differently.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function getCartItems in cart.js and I want to call that function in
I want to call a function that may throw an exception. If it does
I have 2 forms and I want to call a function of Form1 defined
I have a UDF in sql server. I want to call this function at
I have a void pointer returned by dlsym(), I want to call the function
I want to call a controller function from a view. Is that possible in
If i want to call a function of a remote service from within the
I want to call a function when click a cell in Extjs calendar http://ext.ensible.com/deploy/dev/examples/calendar/remote.html
I have a simple jQuery function that resizes text areas, and I want it
I want to call a function for every half minute. i am using the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.