Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect registry access of a dll loaded by my program

I have got a dll that I load in my program which reads and writes its settings to the registry (hkcu). My program changes these settings prior to loading the dll so it uses the settings my program wants it to use which works fine.

Unfortunately I need to run several instances of my program with different settings for the dll. Now the approach I have used so far no longer works reliably because it is possible for one instance of the program to overwrite the settings that another instance just wrote before the dll has a chance to read them.

I haven't got the source of the dll in question and I cannot ask the programmer who wrote it to change it.

One idea I had, was to hook registry access functions and redirect them to a different branch of the registry which is specific to the instance of my program (e.g. use the process id as part of the path). I think this should work but maybe you have got a different / more elegant.

In case it matters: I am using Delphi 2007 for my program, the dll is probably written in C or C++.

like image 358
dummzeuch Avatar asked Feb 26 '23 20:02

dummzeuch


1 Answers

As an alternative to API hooking, perhaps you could use RegOverridePredefKey API.

like image 178
Ondrej Kelle Avatar answered Mar 01 '23 12:03

Ondrej Kelle