Share configuration between DLLs

c++ / delphi package - dll injection and api hooking

Share configuration between DLLs

Postby mutantc0der » Tue Jun 29, 2004 8:41 am

Hi

I want to send a set of instructions to each injected DLL. My first approach is to send them via IPC messages, but as madshi stated before, it isnt that fast. What is the best solution ? e.g is it possible to share a global block of memory each DLL can access. or should i use:

* config files
* sockets (winsock.dll might not be loaded in each process?)
* IPC
* registry (is advapi.dll always loaded?)

What is the most fastest and non-resource-eating way of sharing config to DLLs in certain intervals??

thanks!
mutantc0der
 
Posts: 11
Joined: Thu Jun 17, 2004 1:48 pm

Postby nildo » Tue Jun 29, 2004 11:42 am

Use a file mapping. Its fast, like access to memory (coz it is :-x )

You need to create a pointer to a record that has your configurations.

Code: Select all
   FHandle := CreateFileMapping($FFFFFFFF, nil, 4, 0, $ffff, 'Ipd_DLL');
   // This creates the mapping

   if FHandle = 0 then
   begin
      if GetLastError = 183 then
      begin
         FHandle := OpenFileMapping(FILE_MAP_ALL_ACCESS, False, 'Ipd_DLL');
         // This open the mapping

         if FHandle = 0 then
            Exit;
      end
      else
         Exit;
   end;

   PointerToYourRecord := MapViewOfFile(FHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);


This you must do on your DLL and on your program, when loading. Then, to read information in your DLL is easy:

Code: Select all
   Blablabla := PointerToYourRecord^.YourInfo;


And to write your information by your EXE is easy too.

Code: Select all
   PointerToYourRecord^.YourInfo := 'testing';
nildo
 
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am

Postby mutantc0der » Tue Jun 29, 2004 1:36 pm

thanks nildo, this sure looks good! i was wondering, what happends when , say, ~ 100 DLL instances write to this mapped memory file , who syncs the access, windows ? or do i have to work with mutexes/critical sections ?
mutantc0der
 
Posts: 11
Joined: Thu Jun 17, 2004 1:48 pm

Postby mutantc0der » Tue Jun 29, 2004 2:17 pm

dohh nevermind, i just figured out i can name each mapped similair as the process exe + path with a random integer at the end, and will report it to the controlling app with an IPC message

thanks nildo!
mutantc0der
 
Posts: 11
Joined: Thu Jun 17, 2004 1:48 pm

Postby nildo » Tue Jun 29, 2004 2:25 pm

mutantc0der wrote:dohh nevermind, i just figured out i can name each mapped similair as the process exe + path with a random integer at the end, and will report it to the controlling app with an IPC message

thanks nildo!


Thats it!
But if its the same configuration for ALL those 100 DLLs, I think it will have no problem if you put a CriticalSection there.
nildo
 
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am

Postby madshi » Tue Jun 29, 2004 7:24 pm

Hey, I think I can stop giving advices here. nildo is doing it just fine... :D

Just some comments:

(1) Using madCodeHook.Create/OpenGlobalFileMapping is recommend, because those functions work over the boundaries of XP fast user switching sessions.

(2) mutantc0der, first you ask how you can send config info to the dlls. Then you ask what happens if all dlls write to the config block at the same time. Heh? :confused: If your application wants to send config data to the dlls, then use a global memory block (as suggested by nildo). But it doesn't make ANY sense for the dlls to write to such a config block. Use something else (e.g. SendIpcMessage; or a different global memory block) if the dlls want to report something back to the application. You shouldn't mix the config block with dll-to-exe information transports.
madshi
Site Admin
 
Posts: 9822
Joined: Sun Mar 21, 2004 5:25 pm

Postby nildo » Tue Jun 29, 2004 7:34 pm

madshi wrote:Hey, I think I can stop giving advices here. nildo is doing it just fine... :D


Doing this I can learn more!
Thats because I am from a the best Delphi Fórum here from Brazil, I am a moderator. So I think its instinct. Ahh, don't forget that every thing that was explained, I've learned with you...
nildo
 
Posts: 249
Joined: Mon Mar 22, 2004 11:32 am

Postby madshi » Wed Jun 30, 2004 6:44 am

:D

I'm glad if you help here, cause that saves me time!
madshi
Site Admin
 
Posts: 9822
Joined: Sun Mar 21, 2004 5:25 pm


Return to madCodeHook

Who is online

Users browsing this forum: No registered users and 11 guests

cron