[go: up one dir, main page]

Skip to content

INI settings

Yun Dou edited this page Feb 6, 2021 · 1 revision

INI设置

注意:在micro主版本号1之前,下面用到的magic可能发生变化。

micro通过特殊的magic来标识INI文件头,通过INI文件头可以实现micro带INI启动。

一个带INI的micro自执行文件的结构:


|--------------------------|---------------------------------------------------------------------------|----------------------|
| micro.sfx ELF/PE header  |                            ini part                                       |    php/phar code     |
|                          |                    |                                |                     |                      |
| micro_get_sfx_filesize() |    4 byte magic    |     4 byte sizeof(ini text)    |   n byte ini text   |                      |
| returns sizeof this part | "\xfd\xf6\x69\xe6" | "\0\0\0\x10"(16 in big endian) | "ini_key=\"value\"" | "<?php things();..." |
|--------------------------|---------------------------------------------------------------------------|----------------------|
^ micro_open_self() will return stream start at here                                                   |
                     fopen functions will create stream start reading at here, code will run from here ^

ini文件头为

struct MICRO_INI_HEADER{
    uint32_t magic; // "\xfd\xf6\x69\xe6"
    uint32_t size; // in big-endian
}

例如:使用以下php代码来生成ini头:

$myini = "
ffi.enable=1
micro.php_binary=cafebabe
"
$f=fopen("myiniheader.bin", "wb");
fwrite($f, "\xfd\xf6\x69\xe6");
fwrite($f, pack("N", strlen($myini)));
fwrite($f, $myini);
fclose($f);

然后执行

Windows:

COPY /B micro.sfx + myiniheader.bin + myawesomeapp.phar myawesomeapp.exe

Unix:

cat micro.sfx myiniheader.bin myawesomeapp.phar > myawesomeapp
chmod 0755 myawesomeapp

来生成带INI设置的micro自执行文件

Clone this wiki locally