Technology

Your executable is a SQLite database: SELF format enables executable SQLite files

Farid Zakaria describes a pattern for creating SQLite database files that can be directly executed as binaries on Linux using the SELF format.

Farid Zakaria has created SELF (Structured Executable & Linkable Format), a pattern that makes SQLite database files directly executable on Linux. The technique sets SQLite's application ID to enable the file to be both a database and a binary.

Farid Zakaria has described a neat Linux pattern for creating a SQLite database file that can be directly used as an executable binary [reference:26]. The trick sets the SQLite file format's 4-byte application ID (68 bytes into the file) to SELF, standing for Structured Executable & Linkable Format [reference:27].

How it works

The approach creates a file that is both a valid SQLite database and a valid executable. Not "a database that describes an executable," but the actual file you chmod +x and run [reference:28]. Zakaria has developed a prototype called SELF, which stands for Structured Executable & Linkable Format [reference:29].

Why it matters

The technique opens up interesting possibilities for software distribution and deployment. An executable that is also a SQLite database could embed its own data, configuration, or state within the same file, simplifying distribution and reducing the number of files that need to be managed. It also represents a creative exploration of file format boundaries and what's possible with existing tools.

Implementation

The SELF format builds on SQLite's flexibility, using the application ID field that SQLite reserves for application-specific purposes. By setting this ID to a specific value and structuring the file appropriately, Zakaria has created a format that the Linux kernel can execute while SQLite can still open and query the file as a database [reference:30]. The project is available on GitHub for those interested in experimenting with the concept.