-1

I want to pass a structure to my dll's main thats in my injector so basically I want to do this:

struct structure{
    char text[1024];
};
int DllMain(structure arg1,uintptr_t arg2,uintptr_t arg3);

Yet I want to know how I can make my injector pass the struct. Im manual mapping the dll by the way.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • By "manually mapping" the DLL, do you mean that you are not using the operating system's [LoadLibrary](https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-loadlibrarya) function for loading the DLL? Are you manually loading the file contents into the virtual address space of the target process? Does that mean that you are also calling the DLL's entry point manually? – Andreas Wenzel Mar 07 '20 at 20:15

2 Answers2

1

You can't pass custom parameters to DllMain(). The signature is fixed, and besides that, you don't call DllMain() directly anyway, only the OS does.

Your options are to either:

  • have the DLL export a separate function that you call after injecting the DLL into a process.

  • store the data in a block of shared memory that the DLL can access after being injected.

  • setup an interprocess communication channel between the DLL and injector, such as with a named pipe or a socket.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I believe the signature is not fixed in this case. If I understand the OP correctly, he is not using the operating system's LoadLibrary API, but is [loading the DLL manually](https://www.joachim-bauch.de/tutorials/loading-a-dll-from-memory/). This means that he is also calling the DLL's entry point manually, so he has full control of the signature. However, I have still upvoted your answer, because the question is not very clear. – Andreas Wenzel Mar 07 '20 at 20:28
0

Add a resource to your DLL that is the size of your structure or a larger fixed size, the contents do not matter, you will overwrite it later, it's basically a stub.

Load the DLL into local memory in your injector before you manually map it

Overwrite this resource with your data.

Manual Map your DLL into the target process

Access the resource to get the data you needed

GuidedHacking
  • 3,628
  • 1
  • 9
  • 59