SQLite Forum

[Windows] SQLite dll hooking is nearly impossible due to recursive calls
Login
This is to answer questions not addressed by Warren's appropriate response.

> why sqlite3.dll is doing this?

Mmmm. Because the API is useful enough to be suitable for recursive use? I'm pretty sure that's it, combined with the fact that the 'lite' part of the project/product name is a seriously intended design objective.  I urge you to accept that reality; it is not going to change to suit ideas of modularity that might pertain to other, larger projects.

> how to solve this problem?

If you have control of the client, it would be relatively easy to write preprocessor macros to redirect SQLite API calls into instrumentation functions of your choice and devising, which would call the "real" API to get the work done without such instrumentation.

> Is there another way to hook into sqlite3.dll to get the actual actions from the client of the dll?

It is also relatively easy to create a "shim" DLL or linked code which presents the same interface to a client as another DLL would have, if directly loaded by the client. This can be done in an automated manner for simple instrumentation. (I have done this, so I know it is quite doable.) This can amount to creation of an alternative object (.obj), replacing the usual .lib produced during DLL creation which typically just contains a jump table that is rewritten during dynamic load.