File: beam_lib.html

package info (click to toggle)
erlang-doc-html 1%3A11.b.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,284 kB
  • ctags: 10,724
  • sloc: erlang: 505; ansic: 323; makefile: 62; perl: 61; sh: 45
file content (691 lines) | stat: -rw-r--r-- 21,716 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
  <TITLE>beam_lib</TITLE>
  <SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
  <STYLE TYPE="text/css">
<!--
    .REFBODY     { margin-left: 13mm }
    .REFTYPES    { margin-left: 8mm }
-->
  </STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
  <IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>beam_lib</H1>
</CENTER>

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
beam_lib
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
An Interface To the BEAM File Format
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P><CODE>beam_lib</CODE> provides an interface to files created by
the BEAM compiler (&#34;BEAM files&#34;). The format used, a variant of
&#34;EA IFF 1985&#34; Standard for Interchange Format Files, divides data
into chunks.
<P>Chunk data can be returned as binaries or as compound terms.
Compound terms are returned when chunks are referenced by names
(atoms) rather than identifiers (strings). The names recognized
and the corresponding identifiers are:
<P>
<UL>

<LI>
<CODE>abstract_code (&#34;Abst&#34;)</CODE>
</LI>


<LI>
<CODE>attributes (&#34;Attr&#34;)</CODE>
</LI>


<LI>
<CODE>compile_info (&#34;CInf&#34;)</CODE>
</LI>


<LI>
<CODE>exports (&#34;ExpT&#34;)</CODE>
</LI>


<LI>
<CODE>labeled_exports (&#34;ExpT&#34;)</CODE>
</LI>


<LI>
<CODE>imports (&#34;ImpT&#34;)</CODE>
</LI>


<LI>
<CODE>indexed_imports (&#34;ImpT&#34;)</CODE>
</LI>


<LI>
<CODE>locals (&#34;LocT&#34;)</CODE>
</LI>


<LI>
<CODE>labeled_locals (&#34;LocT&#34;)</CODE>
</LI>


<LI>
<CODE>atoms (&#34;Atom&#34;)</CODE>
</LI>


</UL>

</DIV>
<A NAME="debug_info"><!-- Empty --></A>
<H3>Debug Information/Abstract Code</H3>
<DIV CLASS=REFBODY>

<P>The option <CODE>debug_info</CODE> can be given to the compiler (see
<A HREF="javascript:erlhref('../../../../', 'compiler', 'compile.html#debug_info');">compile(3)</A>)
in order to have debug information in the form of abstract code
(see <A HREF="javascript:erlhref('../../../../', 'erts', 'absform.html');">The Abstract Format</A>
in ERTS User's Guide) stored in the <CODE>abstract_code</CODE> chunk.
Tools such as Debugger and Xref require the debug information to
be included.
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
    <TD>

<P>Source code can be reconstructed from the debug information.
        Use encrypted debug information (see below) to prevent this.
    </TD>
  </TR>
</TABLE>

<P>The debug information can also be removed from BEAM files
using <A HREF="#strip/1">strip/1</A>,
<A HREF="#strip_files/1">strip_files/1</A> and/or
<A HREF="#strip_release/1">strip_release/1</A>.
<P><STRONG>Reconstructing source code</STRONG>
<P>Here is an example of how to reconstruct source code from
the debug information in a BEAM file <CODE>Beam</CODE>:
<PRE>
      {ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_code]).
      io:fwrite(&#34;~s~n&#34;, [erl_prettypr:format(erl_syntax:form_list(AC))]).
    
</PRE>

<P><STRONG>Encrypted debug information</STRONG>
<P>The debug information can be encrypted in order to keep
the source code secret, but still being able to use tools such as
Xref or Debugger. 
<P>To use encrypted debug information, a key must be provided to
the compiler and <CODE>beam_lib</CODE>. The key is given as a string and
it is recommended that it contains at least 32 characters and
that both upper and lower case letters as well as digits and
special characters are used.
<P>

<P>The default type -- and currently the only type -- of crypto
algorithm is <CODE>des3_cbc</CODE>, three rounds of DES. The key string
will be scrambled using <CODE>erlang:md5/1</CODE> to generate
the actual keys used for <CODE>des3_cbc</CODE>.
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>As far as we know when by the time of writing, it is
        infeasible to break <CODE>des3_cbc</CODE> encryption without any
        knowledge of the key. Therefore, as long as the key is kept
        safe and is unguessable, the encrypted debug information
        <STRONG>should</STRONG> be safe from intruders.    </TD>
  </TR>
</TABLE>

<P>There are two ways to provide the key:
<P>
<OL>

<LI>
        Use the compiler option <CODE>{debug_info,Key}</CODE>, see
         <A HREF="javascript:erlhref('../../../../', 'compiler', 'compile.html#debug_info_key');">compile(3)</A>,
         and the function
         <A HREF="#crypto_key_fun/1">crypto_key_fun/1</A>
         to register a fun which returns the key whenever
         <CODE>beam_lib</CODE> needs to decrypt the debug information.<BR>


        If no such fun is registered, <CODE>beam_lib</CODE> will instead
         search for a <CODE>.erlang.crypt</CODE> file, see below.<BR>


</LI>


<LI>
        Store the key in a text file named <CODE>.erlang.crypt</CODE>.<BR>


        In this case, the compiler option <CODE>encrypt_debug_info</CODE>
         can be used, see
         <A HREF="javascript:erlhref('../../../../', 'compiler', 'compile.html#encrypt_debug_info');">compile(3)</A>.<BR>


</LI>


</OL>

<P><STRONG>.erlang.crypt</STRONG>
<P><CODE>beam_lib</CODE> searches for <CODE>.erlang.crypt</CODE> in the current
directory and then the home directory for the current user. If
the file is found and contains a key, <CODE>beam_lib</CODE> will
implicitly create a crypto key fun and register it.
<P>The <CODE>.erlang.crypt</CODE> file should contain a single list of
tuples:
<PRE>
      {debug_info, Mode, Module, Key}
    
</PRE>

<P><CODE>Mode</CODE> is the type of crypto algorithm; currently, the only
allowed value thus is <CODE>des3_cbc</CODE>. <CODE>Module</CODE> is either an
atom, in which case <CODE>Key</CODE> will only be used for the module
<CODE>Module</CODE>, or <CODE>[]</CODE>, in which case <CODE>Key</CODE> will be
used for all modules. <CODE>Key</CODE> is the non-empty key string.
<P>The <CODE>Key</CODE> in the first tuple where both <CODE>Mode</CODE> and
<CODE>Module</CODE> matches will be used.
<P>Here is an example of an <CODE>.erlang.crypt</CODE> file that returns
the same key for all modules:
<PRE>
[{debug_info, des3_cbc, [], &#34;%&#62;7}|pc/DM6Cga*68$Mw]L#&#38;_Gejr]G^&#34;}].
    
</PRE>

<P>And here is a slightly more complicated example of an
<CODE>.erlang.crypt</CODE> which provides one key for the module
<CODE>t</CODE>, and another key for all other modules:
<PRE>
[{debug_info, des3_cbc, t, &#34;My KEY&#34;},
 {debug_info, des3_cbc, [], &#34;%&#62;7}|pc/DM6Cga*68$Mw]L#&#38;_Gejr]G^&#34;}].
    
</PRE>

<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>Do not use any of the keys in these examples. Use your own
        keys.    </TD>
  </TR>
</TABLE>

</DIV>

<H3>DATA TYPES</H3>
<DIV CLASS=REFBODY>

<PRE>
beam() -&#62; Module | Filename | binary()
  Module = atom()
  Filename = string() | atom()
    
</PRE>

<P>Each of the functions described below accept either the module
name, the filename, or a binary containing the beam module.
<PRE>
chunkdata() = {ChunkId, DataB} | {ChunkName, DataT}
  ChunkId = chunkid()
  DataB = binary()
  {ChunkName, DataT} =
        {abstract_code, AbstractCode}
      | {attributes, [{Attribute, [AttributeValue]}]}
      | {compile_info, [{InfoKey, [InfoValue]}]}
      | {exports, [{Function, Arity}]}
      | {labeled_exports, [{Function, Arity, Label}]}
      | {imports, [{Module, Function, Arity}]}
      | {indexed_imports, [{Index, Module, Function, Arity}]}
      | {locals, [{Function, Arity}]}]}
      | {labeled_locals, [{Function, Arity, Label}]}]}
      | {atoms, [{integer(), atom()}]}
  AbstractCode = {AbstVersion, Forms} | no_abstract_code
    AbstVersion = atom()
  Attribute = atom()
  AttributeValue = term()
  Module = Function = atom()
  Arity = int()
  Label = int()
    
</PRE>

<P>It is not checked that the forms conform to the abstract format
indicated by <CODE>AbstVersion</CODE>. <CODE>no_abstract_code</CODE> means
that the <CODE>&#34;Abst&#34;</CODE> chunk is present, but empty.
<P>The list of attributes is sorted on <CODE>Attribute</CODE>, and each
attribute name occurs once in the list. The attribute values
occur in the same order as in the file. The lists of functions
are also sorted.
<PRE>
chunkid() = &#34;Abst&#34; | &#34;Attr&#34; | &#34;CInf&#34;
            | &#34;ExpT&#34; | &#34;ImpT&#34; | &#34;LocT&#34;
            | &#34;Atom&#34;

chunkname() = abstract_code | attributes | compile_info
            | exports | labeled_exports
            | imports | indexed_imports
            | locals | labeled_locals
            | atoms
      
chunkref() = chunkname() | chunkid()
    
</PRE>

</DIV>

<H3>EXPORTS</H3>

<P><A NAME="chunks/2"><STRONG><CODE>chunks(Beam, [ChunkRef]) -&#62; 
        {ok, {Module, [ChunkData]}} | {error, beam_lib, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Beam = beam()</CODE></STRONG><BR>
<STRONG><CODE>ChunkRef = chunkref()</CODE></STRONG><BR>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
<STRONG><CODE>ChunkData = chunkdata()</CODE></STRONG><BR>
<STRONG><CODE>Reason = {unknown_chunk, Filename, atom()}</CODE></STRONG><BR>
<STRONG><CODE>| {key_missing_or_invalid, Filename,
         abstract_code}</CODE></STRONG><BR>
<STRONG><CODE>| Reason1 -- see info/1</CODE></STRONG><BR>
<STRONG><CODE>Filename = string()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Reads chunk data for selected chunks refs. The order of
         the returned list of chunk data is determined by the order
         of the list of chunks references.
</DIV>

<P><A NAME="version/1"><STRONG><CODE>version(Beam) -&#62;
        {ok, {Module, [Version]}} | {error, beam_lib, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Beam = beam()</CODE></STRONG><BR>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
<STRONG><CODE>Version = term()</CODE></STRONG><BR>
<STRONG><CODE>Reason -- see chunks/2</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the module version(s). A version is defined by
         the module attribute <CODE>-vsn(Vsn)</CODE>. If this attribute is
         not specified, the version defaults to the checksum of
         the module. Note that if the version <CODE>Vsn</CODE> is not a list,
         it is made into one, that is <CODE>{ok,{Module,[Vsn]}}</CODE> is
         returned. If there are several <CODE>-vsn</CODE> module attributes,
         the result is the concatenated list of versions. Examples:
<PRE>
1&#62; <STRONG>beam_lib:version(a).</STRONG> % -vsn(1).
{ok,{a,[1]}}
2&#62; <STRONG>beam_lib:version(b).</STRONG> % -vsn([1]).
{ok,{b,[1]}}
3&#62; <STRONG>beam_lib:version(c).</STRONG> % -vsn([1]). -vsn(2).
{ok,{c,[1,2]}}
4&#62; <STRONG>beam_lib:version(d).</STRONG> % no -vsn attribute
{ok,{d,[275613208176997377698094100858909383631]}}
        
</PRE>

</DIV>

<P><A NAME="info/1"><STRONG><CODE>info(Beam) -&#62; [{Item, Info}] | {error, beam_lib, Reason1}
</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Beam = beam()</CODE></STRONG><BR>
<STRONG><CODE>Item, Info -- see below</CODE></STRONG><BR>
<STRONG><CODE>Reason1 =
         {chunk_too_big, Filename, ChunkId, ChunkSize, FileSize}</CODE></STRONG><BR>
<STRONG><CODE>| {invalid_beam_file, Filename, Pos}</CODE></STRONG><BR>
<STRONG><CODE>| {invalid_chunk, Filename, ChunkId}</CODE></STRONG><BR>
<STRONG><CODE>| {missing_chunk, Filename, ChunkId}</CODE></STRONG><BR>
<STRONG><CODE>| {not_a_beam_file, Filename}</CODE></STRONG><BR>
<STRONG><CODE>| {file_error, Filename, Posix}</CODE></STRONG><BR>
<STRONG><CODE>Filename = string()</CODE></STRONG><BR>
<STRONG><CODE>ChunkId = chunkid()</CODE></STRONG><BR>
<STRONG><CODE>ChunkSize = FileSize = int()</CODE></STRONG><BR>
<STRONG><CODE>Pos = int()</CODE></STRONG><BR>
<STRONG><CODE>Posix = posix() -- see file(3)</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a list containing some information about a BEAM file
         as tuples <CODE>{Item, Info}</CODE>:
<P>
<DL>

<DT>
<CODE>{file, Filename} | {binary, Binary}</CODE>
</DT>

<DD>
         The name (string) of the BEAM file, or the binary from
         which the information was extracted.<BR>

         
</DD>

<DT>
<CODE>{module, Module}</CODE>
</DT>

<DD>
         The name (atom) of the module.<BR>

         
</DD>

<DT>
<CODE>{chunks, [{ChunkId, Pos, Size}]}</CODE>
</DT>

<DD>
         For each chunk, the identifier (string) and the position
         and size of the chunk data, in bytes.<BR>

         
</DD>

</DL>

</DIV>

<P><A NAME="cmp/2"><STRONG><CODE>cmp(Beam1, Beam2) -&#62; ok | {error, beam_lib, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Beam1 = Beam2 = beam()</CODE></STRONG><BR>
<STRONG><CODE>Reason = {modules_different, Module1, Module2}</CODE></STRONG><BR>
<STRONG><CODE>| {chunks_different, ChunkId}</CODE></STRONG><BR>
<STRONG><CODE>| Reason1 -- see info/1</CODE></STRONG><BR>
<STRONG><CODE>Module1 = Module2 = atom()</CODE></STRONG><BR>
<STRONG><CODE>ChunkId = chunkid()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Compares the contents of two BEAM files. If the module names
         are the same, and the chunks with the identifiers
         <CODE>&#34;Code&#34;</CODE>, <CODE>&#34;ExpT&#34;</CODE>, <CODE>&#34;ImpT&#34;</CODE>, <CODE>&#34;StrT&#34;</CODE>,
         and <CODE>&#34;Atom&#34;</CODE> have the same contents in both files,
         <CODE>ok</CODE> is returned. Otherwise an error message is returned.
        
</DIV>

<P><A NAME="cmp_dirs/2"><STRONG><CODE>cmp_dirs(Dir1, Dir2) -&#62; 
        {Only1, Only2, Different} | {error, beam_lib, Reason1}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Dir1 = Dir2 = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Different = [{Filename1, Filename2}]</CODE></STRONG><BR>
<STRONG><CODE>Only1 = Only2 = [Filename]</CODE></STRONG><BR>
<STRONG><CODE>Filename = Filename1 = Filename2 = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason1 -- see info/1</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>cmp_dirs/2</CODE> function compares the BEAM files in
         two directories. Only files with extension <CODE>&#34;.beam&#34;</CODE> are
         compared. BEAM files that exist in directory <CODE>Dir1</CODE>
         (<CODE>Dir2</CODE>) only are returned in <CODE>Only1</CODE>
         (<CODE>Only2</CODE>). BEAM files that exist on both directories but
         are considered different by <CODE>cmp/2</CODE> are returned as
         pairs {<CODE>Filename1</CODE>, <CODE>Filename2</CODE>} where
         <CODE>Filename1</CODE> (<CODE>Filename2</CODE>) exists in directory
         <CODE>Dir1</CODE> (<CODE>Dir2</CODE>).
</DIV>

<P><A NAME="diff_dirs/2"><STRONG><CODE>diff_dirs(Dir1, Dir2) -&#62; ok | {error, beam_lib, Reason1}
</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Dir1 = Dir2 = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason1 -- see info/1</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>diff_dirs/2</CODE> function compares the BEAM files in
         two directories the way <CODE>cmp_dirs/2</CODE> does, but names of
         files that exist in only one directory or are different are
         presented on standard output.
</DIV>

<P><A NAME="strip/1"><STRONG><CODE>strip(Beam1) -&#62;
        {ok, {Module, Beam2}} | {error, beam_lib, Reason1}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Beam1 = Beam2 = beam()</CODE></STRONG><BR>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
<STRONG><CODE>Reason1 -- see info/1</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>strip/1</CODE> function removes all chunks from a BEAM
         file except those needed by the loader. In particular,
         the debug information (<CODE>abstract_code</CODE> chunk) is removed.
        
</DIV>

<P><A NAME="strip_files/1"><STRONG><CODE>strip_files(Files) -&#62; 
{ok, [{Module, Beam2}]} | {error, beam_lib, Reason1}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Files = [Beam1]</CODE></STRONG><BR>
<STRONG><CODE>Beam1 = beam()</CODE></STRONG><BR>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
<STRONG><CODE>Beam2 = beam()</CODE></STRONG><BR>
<STRONG><CODE>Reason1 -- see info/1</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>strip_files/1</CODE> function removes all chunks except
         those needed by the loader from BEAM files. In particular,
         the debug information (<CODE>abstract_code</CODE> chunk) is removed.
         The returned list contains one element for each given file
         name, in the same order as in <CODE>Files</CODE>.
</DIV>

<P><A NAME="strip_release/1"><STRONG><CODE>strip_release(Dir) -&#62; 
{ok, [{Module, Filename]}} | {error, beam_lib, Reason1}
</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Dir = string() | atom()</CODE></STRONG><BR>
<STRONG><CODE>Module = atom()</CODE></STRONG><BR>
<STRONG><CODE>Filename = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason1 -- see info/1</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>strip_release/1</CODE> function removes all chunks
         except those needed by the loader from the BEAM files of a
         release. <CODE>Dir</CODE> should be the installation root
         directory. For example, the current OTP release can be
         stripped with the call
         <CODE>beam_lib:strip_release(code:root_dir())</CODE>.
</DIV>

<P><A NAME="format_error/1"><STRONG><CODE>format_error(Reason) -&#62; Chars</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Reason -- see other functions</CODE></STRONG><BR>
<STRONG><CODE>Chars = [char() | Chars]</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Given the error returned by any function in this module, 
         the function <CODE>format_error</CODE> returns a descriptive string
         of the error in English. For file errors, the function 
         <CODE>file:format_error(Posix)</CODE> should be called.
</DIV>

<P><A NAME="crypto_key_fun/1"><STRONG><CODE>crypto_key_fun(CryptoKeyFun) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>CryptoKeyFun = fun() -- see below</CODE></STRONG><BR>
<STRONG><CODE>Reason = badfun | exists | term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>The <CODE>crypto_key_fun/1</CODE> function registers a unary fun
         that will be called if <CODE>beam_lib</CODE> needs to read an
         <CODE>abstract_code</CODE> chunk that has been encrypted. The fun
         is held in a process that is started by the function.
<P>If there already is a fun registered when attempting to
         register a fun, <CODE>{error, exists}</CODE> is returned.
<P>The fun must handle the following arguments:
<PRE>
          CryptoKeyFun(init) -&#62; ok | {ok, NewCryptoKeyFun} | {error, Term}
        
</PRE>

<P>Called when the fun is registered, in the process that holds
         the fun. Here the crypto key fun can do any necessary
         initializations. If <CODE>{ok, NewCryptoKeyFun}</CODE> is returned
         then <CODE>NewCryptoKeyFun</CODE> will be registered instead of
         <CODE>CryptoKeyFun</CODE>. If <CODE>{error, Term}</CODE> is returned,
         the registration is aborted and <CODE>crypto_key_fun/1</CODE>
         returns <CODE>{error, Term}</CODE> as well.
<PRE>
          CryptoKeyFun({debug_info, Mode, Module, Filename}) -&#62; Key
        
</PRE>

<P>Called when the key is needed for the module <CODE>Module</CODE>
         in the file named <CODE>Filename</CODE>. <CODE>Mode</CODE> is the type of
         crypto algorithm; currently, the only possible value thus is
         <CODE>des3_cbc</CODE>. The call should fail (raise an exception) if
         there is no key available.
<PRE>
          CryptoKeyFun(clear) -&#62; term()
        
</PRE>

<P>Called before the fun is unregistered. Here any cleaning up
         can be done. The return value is not important, but is passed
         back to the caller of <CODE>clear_crypto_key_fun/0</CODE> as part
         of its return value.
</DIV>

<P><A NAME="clear_crypto_key_fun/0"><STRONG><CODE>clear_crypto_key_fun() -&#62; {ok, Result}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Result = undefined | term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Unregisters the crypto key fun and terminates the process
         holding it, started by <CODE>crypto_key_fun/1</CODE>.
<P>The <CODE>clear_crypto_key_fun/1</CODE> either returns
         <CODE>{ok, undefined}</CODE> if there was no crypto key fun
         registered, or <CODE>{ok, Term}</CODE>, where <CODE>Term</CODE> is
         the return value from <CODE>CryptoKeyFun(clear)</CODE>, see
         <CODE>crypto_key_fun/1</CODE>.
</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Hans Bolinder - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>