0

I have an application that occasionally stores information to a file. For a particular reason, I find it necessary to have the information stored in a database system like MySQL. So is it possible for me to safely hijack the read and write system calls (in Ubuntu) produced by the application and cause it to store the information to a MySQL database instead of letting the application write to the file system?

Let A be the application.

A -> calls:read -> reads-from-file-system

A -> calls:write -> writes-to-file-system

This is how the application originally functions. Is it possible to write a program (without messing with the Kernel-mode if possible) and implement two functions mysql_wrapped_read and mysql_wrapped_write, which respectively substitutes the original read and write function in the application?

So now, the scenario becomes:

A -> calls:mysql_wrapped_read -> reads-from-mysql-database

A -> calls:mysql_wrapped_write -> writes-to-mysql-database

Can you please tell me if this is possible? If yes, how?

Sreram
  • 491
  • 1
  • 9
  • 22
  • 1
    Assuming its not a statically linked program, you could write a `.so` "shim" and use `LD_PRELOAD`. https://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick – jamieguinan Apr 06 '18 at 03:58
  • Thanks a lot! That really helped! This was exactly what I was looking for! – Sreram Apr 06 '18 at 05:13

0 Answers0