Override library library c functions?

I am working on a game, and one of the requirements for the license agreement for the sound assets that I use is that they are distributed in such a way as to make them inaccessible to the end user. So, I'm going to merge them into a flat file, encrypt them or some of them. The problem is that the used sound library (Hekkus Sound System) accepts only the path to the 'char *' file and processes the internal reading of the file. Therefore, if I continue to use it, I will have to redefine the functions of the stdio file to handle encryption or what I decide to do. It seems doable, but it bothers me. On the Internet, I see people encountering unexpected, unpleasant problems that arise on platforms that interest me (Win32, Android, and iOS).

Is there a cross-platform library that will take care of this? Is there a better approach you would recommend?

+6
source share
6 answers

Do you have the option of using a named pipe instead of a regular file? If so, you can present the channel to the sound library as a file for reading, and you can decrypt your data and write it to the pipe, without any problems. (See the Bay Guide for an explanation of named pipes.)

+7
source

Redefine stdio so that a lib that did not know how it works, works exactly the way the developer does not mean it, does not seem to be the right approach for me, since it is not very simple. It takes so much effort to implement ramdrive that I recommend looking for another audio library.

Hekkus Sound System I found that was created by one person and last updated 2012 year. I would not rely on lib with only one person working on it, without sharing sources.

My advice is to spend your time looking for the right sound library instead of looking for a fish job for it.

+5
source

One possibility is to use the encrypted loopback file system (google for additional resources).

How it works, you put your assets in an encrypted file system that actually lives in a simple file. This file system is mounted somewhere as a loopback device. Password must be provided when connecting / connecting. After installation, all files are available as regular files for your software. But otherwise, the files are encrypted and inaccessible.

+2
source

It depends on the compiler, and not on the guaranteed function, but many allow you to embed files / resources directly in exe and read them in code, like from a disk. You could embed your sound files this way. However, this will significantly increase the size of your exe.

+1
source

Another UNIX-based approach:

The environment variable LD_PRELOAD can be used to override any shared library with which the executable was associated. All characters exported by the library specified in LD_PRELOAD are allowed for this library, including calls to libc functions such as open , read and close . Using libdl, the wrapper library can also be called into the original implementation.

So, all you have to do is start a process that uses the Hekkus sound system in an environment where LD_PRELOAD is set appropriately, and you can do whatever you like in the file that it reads.

Please note, however, that you absolutely cannot keep the data inaccessible to the user: the fact that he must be able to hear means that he must have access. Even if all the software in the chain uses encryption, and your user does not want to hack the hardware, it would not be difficult to connect the audio output to the audio input jack, right? And you cannot forbid the user to use earphones, right? And, of course, the kernel can see all the audio output unencrypted and can send a copy to another location ...

+1
source

The solution to your problem is ramdisk. http://en.wikipedia.org/wiki/RAM_drive Using part of the memory in the plunger as if it were a disk. There is software for this. Caching databases in bars is becoming popular.

And he keeps the file on disk, which will facilitate access to the user.

0
source

Source: https://habr.com/ru/post/953070/


All Articles