怎么通过beam文件得到所有的record或源代码?

 
1. 首先必须要在compile里面加上debug_info信息:
1 > c(load,[debug_info]).
{ok,load}
2> beam_lib:chunks(code:which(load),[compile_info]).
{ok,{load,[{compile_info,[{options,[debug_info]},
{version,"5.0.2"},
{time,{2014,11,10,15,19,43}},
{source,"c:/Users/admin/Documents/GitHub/ErlMixCode/src/load/load.erl"}]}]}}
 
2. 从beam中通过beam_lib模块取出recod信息或源代码:
-module(beamI).
%% API
-export([record_attrs/1,beam_to_source/1]).
%%得到record信息[{RecName1,[Filed11,Filed12]},{RecName2,[Filed21,Filed22]}]
record_attrs(Beam) ->
{ok,{_Mod,[{abstract_code,{_Version,Forms}},{"CInf",_CB}]}} =
beam_lib:chunks(code:which(Beam), [abstract_code,"CInf"]),
[join_name_field(D) || {attribute,_,record,D} <- Forms].

%%得到源代码Beam.erl内容:
beam_to_source(Beam) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(code:which(Beam),[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]). join_name_field({Name, Fs}) -> {Name, [element(3, element(3,F)) || F <- Fs]}.
3. 测试:得到record和源文件:
3> beamI:record_attrs(mnesia).
[{tid,[counter,pid]},
{tidstore,[store,up_stores,level]},
{cstruct,[name,type,ram_copies,disc_copies,disc_only_copies,
load_order,access_mode,majority,index,snmp,local_content,
record_name,attributes,user_properties,frag_properties,
storage_properties,cookie,version]},
{log_header,[log_kind,log_version,mnesia_version,node,now]},
{commit,[node,decision,ram_copies,disc_copies,
disc_only_copies,snmp,schema_ops]},
{decision,[tid,outcome,disc_nodes,ram_nodes]},
{cyclic,[node,oid,op,lock,lucky]},
{mnesia_select,[tab,tid,node,storage,cont,written,spec,type,
orig]}]
4> beamI:beam_to_source(load).
-file("load.erl", 1).
-module(load).
-behaviour(gen_server).
-vsn("1.0").
-export([multi_start/0, multi_start/1, start/0, start/1,
start_link/0, start_link/1]).
-export([stop/0, multi_stop/0]).
.......
这一切的前提都是你要在编译时+上debug_info信息:
 
因为你不想加debug_info让代码泄露,但有一些测试工具又非常依赖debug_info。
这时你可以使用encryption对debug_info进行加密,详见beam_lib的官方文档:)
 
参照:beam_lib模块的官方文档。
--------------------------------------------------------------------------------------------------------------------------------------
人家手都伸出来了,好歹给一小鱼干啊,这是人干的吗?
 

[Erlang26]怎么通过beam文件得到所有的record或源代码?的更多相关文章

  1. [Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?

    在Erlang In Anger第二章中讲到使用rebar来创建一个Erlang项目(Application或Project) 但美中不足的只是给出了指引,但没有给出详细的步骤. 下面我们就使用reb ...

  2. Xml日志记录文件最优方案(附源代码)

    Xml作为数据存储的一种方式,当数据非常大的时候,我们将碰到很多Xml处理的问题.通常,我们对Xml文件进行编辑的最直接的方式是将xml文件加载到XmlDocument,在内存中来对XmlDocume ...

  3. Android布局文件的载入过程分析:Activity.setContentView()源代码分析

    大家都知道在Activity的onCreate()中调用Activity.setContent()方法能够载入布局文件以设置该Activity的显示界面.本文将从setContentView()的源代 ...

  4. 上传文件时 重新载入页面以获取源代码 http://*/upload.php

    今天做一个处理上传文件的接口时碰到这样一个问题, 用的是element-ui的上传组件,但是上传失败, 抓包一看返回的是 重新载入页面以获取源代码 http://*/upload.php 网上搜了一下 ...

  5. 【Android Developers Training】 42. 从另一台设备接收文件

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  6. 【Android Developers Training】 41. 向另一台设备发送文件

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  7. [Erlang06]在Erlang shell怎么在目录A下编译目录B下的文件,并把生成文件统一放置目录C?

    问题描述: 我们想快速测试一个小功能,第一个反应就是打开Erl shell 直接输入,但是当想测试一个复杂的函数时,一般会写成一个*.erl文件,然后在shell下: cd(FileDir). c(F ...

  8. erlang app 文件

    http://hje.iteye.com/blog/1211734 应用的概念¶ 当我们写了实现特定功能的代码之后,我们可能想将代码转成一个 应用 (application),这是可以作为一个单元启动 ...

  9. Erlang那些事儿第2回之我是模块(module),一文件一模块

    前几篇文章会写得比较基础,但是既然要写一系列的文章,还是得从基础开始写.我刚学Erlang碰到最大的问题是,想网上搜索下语法,结果却是寥寥无几,而且介绍得不是很系统,对我了解一些细节是有影响的,正好我 ...

随机推荐

  1. 需登录账号与密码的网页爬取demo

    public static String connect(String dataUrl){ String result = null; try { HttpClient httpclient = ne ...

  2. 开启php的xdebug扩展及phpstorm配置xdebug,chrome调试插件组合

    一. 开启php xdebug扩展      注意:     1. 原生php各版本需对应各自的xdebug版本,可到xdebug上对应下载     2. 若用wampserver等环境,wampse ...

  3. js格式化时间 js格式化时间戳

    一个js格式化时间和js格式化时间戳的例子. 代码:/** * 时间对象的格式化; */Date.prototype.format = function(format) { /* * eg:forma ...

  4. 33.使用默认的execAndWait拦截器

    转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 当我们进行数据库查询等相关的操作时,如果服务器负荷过重可能不能及时把数据查询 ...

  5. Firemonkey MultiView

    MultiView 做导航用的. http://docwiki.embarcadero.com/RADStudio/Seattle/en/Mobile_Tutorial:_Using_a_MultiV ...

  6. y=x^2 vs y=x^(1/2)

    [y=x^2 vs y=x^(1/2)] y=x^2,基础函数,废话不多说. y=x^(1/2),指数变成了上式的倒数.x^(1/2)即是,√x.但函数图像会是什么样呢?可以把y=x^(1/2),转变 ...

  7. 106. Construct Binary Tree from Inorder and Postorder Traversal (Tree; DFS)

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  8. cnblog博客管理

    http://www.cnblogs.com/wc1903036673/                                        12436109 https://www.cnb ...

  9. [SQL]查询数据库中具有某个字段名的表

    SELECT t.name AS table_name, c.name AS column_name FROM XOIFundData.sys.tables AS t INNER JOIN XOIFu ...

  10. 启动项目报错:502 Server dropped connection The following error occurred while trying to access http://localhost:8080/TestDemo:

    之前的项目一直是好的,可以启动,但最近启动出了问题,访问不了,于是找到原因发现是启用了访问国外网站的加速器, 更改了浏览器的代理模式,如下: 解决方法: 打开浏览器,进入到浏览器的网络设置中,将局域网 ...