Share configuration between DLLs
-
- Posts: 11
- Joined: Thu Jun 17, 2004 1:48 pm
Share configuration between DLLs
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!
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!
Use a file mapping. Its fast, like access to memory (coz it is )
You need to create a pointer to a record that has your configurations.
This you must do on your DLL and on your program, when loading. Then, to read information in your DLL is easy:
And to write your information by your EXE is easy too.
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);
Code: Select all
Blablabla := PointerToYourRecord^.YourInfo;
Code: Select all
PointerToYourRecord^.YourInfo := 'testing';
-
- Posts: 11
- Joined: Thu Jun 17, 2004 1:48 pm
-
- Posts: 11
- Joined: Thu Jun 17, 2004 1:48 pm
Thats it!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!
But if its the same configuration for ALL those 100 DLLs, I think it will have no problem if you put a CriticalSection there.
Hey, I think I can stop giving advices here. nildo is doing it just fine...
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? 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.
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? 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.
Doing this I can learn more!madshi wrote:Hey, I think I can stop giving advices here. nildo is doing it just fine...
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...