{"error":400,"message":"over quota"} Erlang代码如何反编译?——云诺说
云诺说 - 小程序开发 - 软件定制
当前位置: Erlang > Erlang代码如何反编译?

Erlang代码如何反编译?

2017-07-07 08:45 分类:Erlang 作者:云诺 阅读(4364)

版权声明:本文为博主原创文章,如果转载请给出原文链接:http://doofuu.com/article/4156131.html

hello~ 

做程序的最怕的就是自己辛苦些的代码被人轻易的反编译。 那么的beam文件被别人活得,或者erlang源码被意外删除只留下编译后的beam文件的时候怎么办?如果源码能还原也就大事化了, 如果不能就懵了?都有手误的是时候,今天就来聊聊erlang的反编译,到时也不至于乱了手脚。

在仔细翻阅文档之后终于找到了erlang反编译相关的说明,地址:http://erlang.org/doc/man/beam_lib.html 。beam_lib 模块就是对deam文件格式的接口。

其中最主要的是这两行代码:

{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_code]).
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).

so ~ 废话少说,直接上代码。

源码:

-module(test).

-export([hello/0,say/0]).

hello() ->
	"hello ~".

%%@doc say hello~
say() ->
	lists:foreach(fun hello/0 , lists:seq(1, 10)).

先看下面

20160923152144255.png

在chunks之后并没有成功,提示是no_abstract_code,这是为什么呢?查看文档,在文档中找到如下说明:

Option debug_info can be specified to the Compiler (see compile(3)) to have debug information in the form of abstract code (see section The Abstract Format in the ERTS User's Guide) stored in the abstract_code chunk. Tools such as Debugger and Xref require the debug information to be included.

 大致的意思是:要想反编译就必须在编译的时候加上+debug_info标记,现在我们再来试试:

QQ截图20190704174557.png

QQ截图20190704174608.png

这次成功了~


不过欢喜之余我们马上会发现,自己能反编译成功那别人也肯定能, 这样就存在安全问题了,那么有没有办法解决这个问题呢?幸运的是文档里给出了解决方法。有两种方法:

The key can be provided in the following two ways:

Use Compiler option {debug_info,Key}, see compile(3) and function crypto_key_fun/1 to register a fun that returns the key whenever beam_lib must decrypt the debug information.

If no such fun is registered, beam_lib instead searches for an .erlang.crypt file, see the next section.

Store the key in a text file named .erlang.crypt.

In this case, Compiler option encrypt_debug_info can be used, see compile(3).

我们这里选择第二种最简单的方法,在用户root目录下创建 .erlang.crypt文件,格式内容是[{debug_info, Mode, Module, Key}].

我这里是[{debug_info, des3_cbc, [], "my_key"}].

再来看

QQ截图20190704174715.png

QQ截图20190704174726.png

也成功了, 注意这里要加encrypt_debug_info而不是debug_info,

现在我们来修改.erlang.crypt文件里的内容为[{debug_info, des3_cbc, [], "no_key"}]. 或者删除.erlang.crypt文件再来尝试:

QQ截图20190704174742.png

失败了,意思是说加密验证不通过。

现在没什么好担心的啦~放心去干吧!!

 

祝生活愉快!

「创作不易,你的支持是本站持续更新最大的动力!」

赞(0) 打赏

谢谢你请我喝奶茶*^_^*

支付宝
微信
1

谢谢你请我喝奶茶*^_^*

支付宝
微信

上一篇:

下一篇:

共有 0 条评论 - Erlang代码如何反编译?

博客简介

云诺说是一个致力于分享互联网编程技术交流、小程序开发、小程序源码分享、软件服务定制和生活记录的技术服务型学习博客网站。

微信 :LGY178888

职业 :小程序开发、软件定制

现居 :广东省-广州市-天河区

友情链接

欢迎与本博客交换友情链接,本博客对交换链接的网站没有要求。如果您是本博客的友情链接网站,在遇到网站运行问题时,可以随时联系,我们将免费提供技术类支持! 申请交换友链

站点统计

  • 文章总数:155 篇
  • 草稿数目:0 篇
  • 分类数目:14 个
  • 独立页面:165 个
  • 评论总数:0 条
  • 访问总量: 636851次
  • 最近更新:2024年07月27日