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

  • Home
  • SEARCH
  • 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 3309722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:40:30+00:00 2026-05-17T21:40:30+00:00

First off I would like to say, that I am not trying to hack

  • 0

First off I would like to say, that I am not trying to hack a game. I am actually employed by the company whose process I am trying to inject. 🙂
I would like to know how to call a function from an already injected DLL.
So, I have successfully injected and loaded my DLL in the target using CreateRemoteThread(). Below you can see a snippet of the injection:

private static bool Inject(Process pToBeInjected, string sDllPath,out string sError, out IntPtr hwnd, out IntPtr hLibModule)
    { 
        IntPtr zeroPtr = (IntPtr)0;
        hLibModule = zeroPtr;

        IntPtr hProcess = NativeUtils.OpenProcess(
            (0x2 | 0x8 | 0x10 | 0x20 | 0x400), //create thread, query info, operation ,write, and read 
            1,
            (uint)pToBeInjected.Id);

        hwnd = hProcess;
        IntPtr loadLibH = NativeUtils.GetProcAddress( NativeUtils.GetModuleHandle("kernel32.dll"),"LoadLibraryA");

        IntPtr dllAddress = NativeUtils.VirtualAllocEx(
            hProcess,
            (IntPtr)null,
            (IntPtr)sDllPath.Length, //520 bytes should be enough 
            (uint)NativeUtils.AllocationType.Commit |
            (uint)NativeUtils.AllocationType.Reserve,
            (uint)NativeUtils.MemoryProtection.ExecuteReadWrite);

    byte[] bytes = CalcBytes(sDllPath);
        IntPtr ipTmp = IntPtr.Zero;

        NativeUtils.WriteProcessMemory(
            hProcess,
            dllAddress,
            bytes,
            (uint)bytes.Length,
            out ipTmp);


        IntPtr hThread = NativeUtils.CreateRemoteThread(
            hProcess,
            (IntPtr)null,
            (IntPtr)0,
            loadLibH, //handle to LoabLibrary function
            dllAddress,//Address of the dll in remote process
            0,
            (IntPtr)null);

        uint retV= NativeUtils.WaitForSingleObject(hThread, NativeUtils.INFINITE_WAIT);
        bool exitR = NativeUtils.GetExitCodeThread(hThread, out hLibModule);
        return true;
    }

Note: Error checking and freeing resources were removed for brevity, but rest assured I check all the pointers and free my resources.
After the function above exits, I have a non-zero module handle to my DLL returned by LoadLibrary through hLibModule, meaning that the DLL was loaded correctly.
My DLL is a C# class library meant to show a message box (for testing). I have tried testing the function and the message box pops up. It looks like this:

 public class Class1
    {
        public static void ThreadFunc(IntPtr param ) 
        {       
        IntPtr libPtr = LoadLibrary("user32.dll");

            MessageBox(IntPtr.Zero, "I'm ALIVE!!!!", "InjectedDll", 0);

        }
        [DllImport("kernel32", SetLastError = true)]
        public static extern IntPtr LoadLibrary(string lpFileName);

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int MessageBox(IntPtr hWnd, String text, String caption, int options);

} 

I compile it from Visual Studio and the DLL appears in the Debug folder. I then pass the full path of my DLL to the injector.
After injection into the target process, I don’t know how to call my ThreadFunc from the injected DLL, so it never executes.
I cannot use GetProcAddress(hLibModule,"ThreadFunc") since I am out of process, so the answer must lie into calling CreateRemoteThread() somehow. Also, I have read that DllMain is no longer allowed for .NET DLLs, so I cannot get any free execution that way either.
Does anyone have any idea how to call a function from an injected DLL?
Thank you in advance.

  • 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-05-17T21:40:30+00:00Added an answer on May 17, 2026 at 9:40 pm

    Well, you already got a thread running inside that process. You make it do something boring, it only loads a DLL. This works completely by accident, LoadLibrary just happens to have to correct function signature.

    It can do much more. That however better be unmanaged code, just like LoadLibrary(), you cannot count on any managed code running properly. That takes a heckofalot more work, you have to load and initialize the CLR and tell it to load and execute the assembly you want to run. And no, you cannot load the CLR in DllMain().

    Keywords to look for are CorBindToRuntimeEx() and ICLRRuntimeHost::ExecuteInAppDomain(). This is gritty stuff to get going but I’ve seen it done. COM and C++ skills and generous helpings of luck required.

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

Sidebar

Related Questions

First off, I would like to say that I am just starting with PHP
First off, before I ask, i would like to point out that this question
First off, let me start off that I am not a .net developer. The
First off I'm not sure that's the proper title for this question but hopefully
First off, I'm working on an app that's written such that some of your
First off let me just say, i dont want anyone to post solutions because
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First off, there's a bit of background to this issue available on my blog:

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.