【文章标题】:Your executable is a SQLite database
你的可执行文件是一个SQLite数据库
【文章正文】: Your executable is a SQLite database
你的可执行文件是一个SQLite数据库
Farid Zakaria describes a neat Linux pattern for creating a SQLite database file that can be directly used as an executable binary.
Farid Zakaria 描述了一种巧妙的 Linux 模式,用于创建一个可以直接作为可执行二进制文件使用的 SQLite 数据库文件。
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. The various components of the ELF executable format are then arranged into a number of different SQLite tables, using
this schema
.
这个技巧将 SQLite 文件格式的 4 字节应用程序 ID(文件偏移 68 字节处)设置为 SELF,代表 Structured Executable & Linkable Format(结构化可执行与可链接格式)。然后,ELF 可执行格式的各个组件被安排到多个不同的 SQLite 表中,使用
这个模式
。
Their
self-exec
interpreter (
C code here
) can then extract and execute the necessary pieces.
他们的
self-exec
解释器(
C 代码在此
)随后可以提取并执行必要的部分。
You can additionally use a Linux mechanism called
binfmt_misc
to teach the kernel to execute that any time it encounters an executable matching that binary pattern. Farid uses NixOS here, but without NixOS I think registration looks something like this:
你还可以使用一种名为
binfmt_misc
的 Linux 机制,让内核在遇到与该二进制模式匹配的可执行文件时执行它。Farid 在这里使用的是 NixOS,但如果没有 NixOS,我认为注册过程大致如下:
printf ‘%s\n’ ‘:self:M:68:SELF::/usr/local/bin/self-exec:’ \
/proc/sys/fs/binfmt_misc/register
Via
Hacker News
来自
Hacker News
Tags:
c
,
linux
,
sqlite
标签:
c
,
linux
,
sqlite