我把 .beam 当作脚本使用,这样能隐藏代码,并在任何地方运行。
通常会有多个文件一起工作,例如
entry.erl
helper.erl
....
能把多个 beam 文件合成一个 beam 吗?
我唯一想到的办法是把 beam 嵌入 erl 文件,然后再编译,例如
["[",
lists:map(fun(Artifact) ->
{ok, Payload} = prim_file:read_file(Artifact),
["{", filename:basename(Artifact, ".beam"), ",", io_lib:format("~w", [Payload]), "},"]
end, Artifacts)
"ok]"]
得到
[{module, <<"....">>}]
最后通过 code:load_file 加载
从英语翻译·查看原文I'm treating .beam as a script so I can conceal my code and execute it any where.
Normally several files cooperate, for example:
entry.erl
helper.erl
....
Can several beam files be combined into a single beam?
My only idea is embedding the beam inside an erl file before compiling that, for example
["[",
lists:map(fun(Artifact) ->
{ok, Payload} = prim_file:read_file(Artifact),
["{", filename:basename(Artifact, ".beam"), ",", io_lib:format("~w", [Payload]), "},"]
end, Artifacts)
"ok]"]
producing
[{module, <<"....">>}]
then loading it via code:load_file