【erlang】反编译

反编译函数

beam_lib:chunks(BeamPath, [abstract_code]).

test_decompile.erl

-module(test_decompile).
-export([decompile/1]).

decompile(Beam) ->
	case beam_lib:chunks(code:which(Beam),  [abstract_code]) of
	    {ok, {_, [{abstract_code, {_, AC}}]}} ->
		    io:format("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]);
		Other ->
			Other
	end.

test.erl

-module(test).
-compile(export_all).

-record(kv, {key, val}).

list() ->
	[1, 2, 3].
tuple() ->
	{a, b, c}.
string() ->
	"test".
atom() ->
	hello.
record() ->
	#kv{key = 1}.
binary() ->
	<<"aabbcc">>.

示例:

1> c(test).
{ok,test}
2> c(test_decompile).
{ok,test_decompile}
3> test_decompile:decompile(test).
{ok,{test,[{abstract_code,no_abstract_code}]}}

注意:要想反编译就必须在编译的时候加上+debug_info标记

[root@localhost]# erlc +debug_info test.erl
[root@localhost]# erl
Eshell V8.3  (abort with ^G)
1> test_decompile:decompile(test).
-file("test.erl", 1).
-module(test).
-compile(export_all).
-record(kv, {key, val}).
list() -> [1, 2, 3].
tuple() -> {a, b, c}.
string() -> "test".
atom() -> hello.
record() -> #kv{key = 1}.
binary() -> <<"aabbcc">>.
ok
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值