Home | History | Annotate | Download | only in docs
      1 <!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
      2 <html>
      3 <head>
      4 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
      5 <meta http-equiv="content-style-type" content="text/css">
      6 <link rel="stylesheet" type="text/css" href="style.css">
      7 <title>ProGuard FAQ</title>
      8 <script type="text/javascript" language="JavaScript">
      9 <!--
     10 if (window.self==window.top)
     11   window.top.location.replace("index.html#"+window.location.pathname+window.location.hash);
     12 else {
     13   var hash="#"+window.location.pathname.replace(window.top.location.pathname.replace("index.html", ""), "");
     14   if (window.top.location.hash!=hash)
     15     window.top.location.hash=hash;
     16 }
     17 //-->
     18 </script>
     19 </head>
     20 <body>
     21 
     22 <h2>Frequently Asked Questions</h2>
     23 
     24 <h3>Contents</h3>
     25 
     26 <ol>
     27 <li><a href="#shrinking">What is shrinking?</a></li>
     28 <li><a href="#obfuscation">What is obfuscation?</a></li>
     29 <li><a href="#preverification">What is preverification?</a></li>
     30 <li><a href="#optimization">What kind of optimizations does <b>ProGuard</b>
     31     support?</a></li>
     32 <li><a href="#commercial">Can I use <b>ProGuard</b> to process my commercial
     33     application?</a></li>
     34 <li><a href="#jdk1.4">Does <b>ProGuard</b> work with Java 2? Java 5? Java
     35     6?</a></li>
     36 <li><a href="#jme">Does <b>ProGuard</b> work with Java Micro Edition?</a></li>
     37 <li><a href="#android">Does <b>ProGuard</b> work for Google Android
     38     code?</a></li>
     39 <li><a href="#blackberry">Does <b>ProGuard</b> work for Blackberry
     40     code?</a></li>
     41 <li><a href="#ant">Does <b>ProGuard</b> have support for Ant?</a></li>
     42 <li><a href="#gui">Does <b>ProGuard</b> come with a GUI?</a></li>
     43 <li><a href="#forname">Does <b>ProGuard</b> handle <code>Class.forName</code>
     44     calls?</a></li>
     45 <li><a href="#resource">Does <b>ProGuard</b> handle resource files?</a></li>
     46 <li><a href="#encrypt">Does <b>ProGuard</b> encrypt strings constants?</a></li>
     47 <li><a href="#flow">Does <b>ProGuard</b> perform control flow
     48     obfuscation?</a></li>
     49 <li><a href="#incremental">Does <b>ProGuard</b> support incremental
     50     obfuscation?</a></li>
     51 <li><a href="#keywords">Can <b>ProGuard</b> obfuscate using reserved
     52     keywords?</a></li>
     53 <li><a href="#stacktrace">Can <b>ProGuard</b> reconstruct obfuscated stack
     54     traces?</a></li>
     55 </ol>
     56 
     57 <h3><a name="shrinking">What is shrinking?</a></h3>
     58 
     59 Java source code (.java files) is typically compiled to bytecode (.class
     60 files). Bytecode is more compact than Java source code, but it may still
     61 contain a lot of unused code, especially if it includes program libraries.
     62 Shrinking programs such as <b>ProGuard</b> can analyze bytecode and remove
     63 unused classes, fields, and methods. The program remains functionally
     64 equivalent, including the information given in exception stack traces.
     65 
     66 <h3><a name="obfuscation">What is obfuscation?</a></h3>
     67 
     68 By default, compiled bytecode still contains a lot of debugging information:
     69 source file names, line numbers, field names, method names, argument names,
     70 variable names, etc. This information makes it straightforward to decompile
     71 the bytecode and reverse-engineer entire programs. Sometimes, this is not
     72 desirable. Obfuscators such as <b>ProGuard</b> can remove the debugging
     73 information and replace all names by meaningless character sequences, making
     74 it much harder to reverse-engineer the code. It further compacts the code as a
     75 bonus. The program remains functionally equivalent, except for the class
     76 names, method names, and line numbers given in exception stack traces.
     77 
     78 <h3><a name="preverification">What is preverification?</a></h3>
     79 
     80 When loading class files, the class loader performs some sophisticated
     81 verification of the byte code. This analysis makes sure the code can't
     82 accidentally or intentionally break out of the sandbox of the virtual machine.
     83 Java Micro Edition and Java 6 introduced split verification. This means that
     84 the JME preverifier and the Java 6 compiler add preverification information to
     85 the class files (StackMap and StackMapTable attributes, respectively), in order
     86 to simplify the actual verification step for the class loader. Class files can
     87 then be loaded faster and in a more memory-efficient way. <b>ProGuard</b> can
     88 perform the preverification step too, for instance allowing to retarget older
     89 class files at Java 6.
     90 
     91 <h3><a name="optimization">What kind of optimizations does <b>ProGuard</b> support?</a></h3>
     92 
     93 Apart from removing unused classes, fields, and methods in the shrinking step,
     94 <b>ProGuard</b> can also perform optimizations at the bytecode level, inside
     95 and across methods. Thanks to techniques like control flow analysis, data flow
     96 analysis, partial evaluation, static single assignment, global value numbering,
     97 and liveness analysis, <b>ProGuard</b> can:
     98 
     99 <ul>
    100 <li>Evaluate constant expressions.</li>
    101 <li>Remove unnecessary field accesses and method calls.</li>
    102 <li>Remove unnecessary branches.</li>
    103 <li>Remove unnecessary comparisons and instanceof tests.</li>
    104 <li>Remove unused code blocks.</li>
    105 <li>Merge identical code blocks.</li>
    106 <li>Reduce variable allocation.</li>
    107 <li>Remove write-only fields and unused method parameters.</li>
    108 <li>Inline constant fields, method parameters, and return values.</li>
    109 <li>Inline methods that are short or only called once.</li>
    110 <li>Simplify tail recursion calls.</li>
    111 <li>Merge classes and interfaces.</li>
    112 <li>Make methods private, static, and final when possible.</li>
    113 <li>Make classes static and final when possible.</li>
    114 <li>Replace interfaces that have single implementations.</li>
    115 <li>Perform over 200 peephole optimizations, like replacing ...*2 by
    116     ...&lt;&lt;1.</li>
    117 <li>Optionally remove logging code.</li>
    118 </ul>
    119 The positive effects of these optimizations will depend on your code and on
    120 the virtual machine on which the code is executed. Simple virtual machines may
    121 benefit more than advanced virtual machines with sophisticated JIT compilers.
    122 At the very least, your bytecode may become a bit smaller.
    123 <p>
    124 Some notable optimizations that aren't supported yet:
    125 <ul>
    126 <li>Moving constant expressions out of loops.</li>
    127 <li>Optimizations that require escape analysis.</li>
    128 </ul>
    129 
    130 <h3><a name="commercial">Can I use <b>ProGuard</b> to process my commercial application?</a></h3>
    131 
    132 Yes, you can. <b>ProGuard</b> itself is distributed under the GPL, but this
    133 doesn't affect the programs that you process. Your code remains yours, and
    134 its license can remain the same.
    135 
    136 <h3><a name="jdk1.4">Does <b>ProGuard</b> work with Java 2? Java 5? Java 6? Java 7?</a></h3>
    137 
    138 Yes, <b>ProGuard</b> supports all JDKs from 1.1 up to and including 7.0. Java 2
    139 introduced some small differences in the class file format. Java 5 added
    140 attributes for generics and for annotations. Java 6 introduced optional
    141 preverification attributes. Java 7 made preverification obligatory and
    142 introduced support for dynamic languages. <b>ProGuard</b> handles all versions
    143 correctly.
    144 
    145 <h3><a name="jme">Does <b>ProGuard</b> work with Java Micro Edition?</a></h3>
    146 
    147 Yes. <b>ProGuard</b> itself runs in Java Standard Edition, but you can freely
    148 specify the run-time environment at which your programs are targeted,
    149 including Java Micro Edition. <b>ProGuard</b> then also performs the required
    150 preverification, producing more compact results than the traditional external
    151 preverifier.
    152 <p>
    153 <b>ProGuard</b> also comes with an obfuscator plug-in for the JME Wireless
    154 Toolkit.
    155 
    156 <h3><a name="android">Does <b>ProGuard</b> work for Google Android code?</a></h3>
    157 
    158 Yes. Google's <code>dx</code> compiler converts ordinary jar files into files
    159 that run on Android devices. By preprocessing the original jar files,
    160 <b>ProGuard</b> can significantly reduce the file sizes and boost the run-time
    161 performance of the code.
    162 
    163 <h3><a name="blackberry">Does <b>ProGuard</b> work for Blackberry code?</a></h3>
    164 
    165 It should. RIM's proprietary <code>rapc</code> compiler converts ordinary JME
    166 jar files into cod files that run on Blackberry devices. The compiler performs
    167 quite a few optimizations, but preprocessing the jar files with
    168 <b>ProGuard</b> can generally still reduce the final code size by a few
    169 percent. However, the <code>rapc</code> compiler also seems to contain some
    170 bugs. It sometimes fails on obfuscated code that is valid and accepted by other
    171 JME tools and VMs. Your mileage may therefore vary.
    172 
    173 <h3><a name="ant">Does <b>ProGuard</b> have support for Ant?</a></h3>
    174 
    175 Yes. <b>ProGuard</b> provides an Ant task, so that it integrates seamlessly
    176 into your Ant build processes. You can still use configurations in
    177 <b>ProGuard</b>'s own readable format. Alternatively, if you prefer XML, you
    178 can specify the equivalent XML configuration.
    179 
    180 <h3><a name="gui">Does <b>ProGuard</b> come with a GUI?</a></h3>
    181 
    182 Yes. First of all, <b>ProGuard</b> is perfectly usable as a command-line tool
    183 that can easily be integrated into any automatic build process. For casual
    184 users, there's also a graphical user interface that simplifies creating,
    185 loading, editing, executing, and saving ProGuard configurations.
    186 
    187 <h3><a name="forname">Does <b>ProGuard</b> handle <code>Class.forName</code> calls?</a></h3>
    188 
    189 Yes. <b>ProGuard</b> automatically handles constructs like
    190 <code>Class.forName("SomeClass")</code> and <code>SomeClass.class</code>. The
    191 referenced classes are preserved in the shrinking phase, and the string
    192 arguments are properly replaced in the obfuscation phase.
    193 <p>
    194 With variable string arguments, it's generally not possible to determine their
    195 possible values. They might be read from a configuration file, for instance.
    196 However, <b>ProGuard</b> will note a number of constructs like
    197 "<code>(SomeClass)Class.forName(variable).newInstance()</code>". These might
    198 be an indication that the class or interface <code>SomeClass</code> and/or its
    199 implementations may need to be preserved. The user can adapt his configuration
    200 accordingly.
    201 
    202 <h3><a name="resource">Does <b>ProGuard</b> handle resource files?</a></h3>
    203 
    204 Yes. <b>ProGuard</b> copies all non-class resource files, optionally adapting
    205 their names and their contents to the obfuscation that has been applied.
    206 
    207 <h3><a name="encrypt">Does <b>ProGuard</b> encrypt strings constants?</a></h3>
    208 
    209 No. Storing encrypted string constants in program code is fairly futile, since
    210 the encryption has to be perfectly reversible by definition. Moreover, the
    211 decryption costs additional memory and computation at run-time. If this feature
    212 is ever incorporated, I'll provide a tool to decrypt the strings as well.
    213 
    214 <h3><a name="flow">Does <b>ProGuard</b> perform flow obfuscation?</a></h3>
    215 
    216 Not explicitly. Control flow obfuscation injects additional branches into the
    217 bytecode, in an attempt to fool decompilers. <b>ProGuard</b> does not do this,
    218 in order to avoid any negative effects on performance and size. However, the
    219 optimization step often already restructures the code to the point where most
    220 decompilers get confused.
    221 
    222 <h3><a name="incremental">Does <b>ProGuard</b> support incremental obfuscation?</a></h3>
    223 
    224 Yes. This feature allows you to specify a previous obfuscation mapping file in
    225 a new obfuscation step, in order to produce add-ons or patches for obfuscated
    226 code.
    227 
    228 <h3><a name="keywords">Can <b>ProGuard</b> obfuscate using reserved keywords?</a></h3>
    229 
    230 Yes. You can specify your own obfuscation dictionary, such as a list of
    231 reserved key words, identifiers with foreign characters, random source files,
    232 or a text by Shakespeare. Note that this hardly improves the obfuscation.
    233 Decent decompilers can automatically replace reserved keywords, and the effect
    234 can be undone fairly easily, by obfuscating again with simpler names.
    235 
    236 <h3><a name="stacktrace">Can <b>ProGuard</b> reconstruct obfuscated stack traces?</a></h3>
    237 
    238 Yes. <b>ProGuard</b> comes with a companion tool, <b>ReTrace</b>, that can
    239 'de-obfuscate' stack traces produced by obfuscated applications. The
    240 reconstruction is based on the mapping file that <b>ProGuard</b> can write
    241 out. If line numbers have been obfuscated away, a list of alternative method
    242 names is presented for each obfuscated method name that has an ambiguous
    243 reverse mapping. Please refer to the <a href="manual/index.html">ProGuard User
    244 Manual</a> for more details.
    245 
    246 <hr />
    247 <noscript><div><a target="_top" href="index.html" class="button">Show menu</a></div></noscript>
    248 <address>
    249 Copyright &copy; 2002-2011
    250 <a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a>.
    251 </address>
    252 </body>
    253 </html>
    254