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