| 1 |
/* Copyright (c) 2006, Sun Microsystems, Inc. |
| 2 |
* All rights reserved. |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are met: |
| 6 |
* |
| 7 |
* * Redistributions of source code must retain the above copyright notice, |
| 8 |
* this list of conditions and the following disclaimer. |
| 9 |
* * Redistributions in binary form must reproduce the above copyright |
| 10 |
* notice, this list of conditions and the following disclaimer in the |
| 11 |
* documentation and/or other materials provided with the distribution. |
| 12 |
* * Neither the name of the Sun Microsystems, Inc. nor the names of its |
| 13 |
* contributors may be used to endorse or promote products derived from |
| 14 |
* this software without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 17 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 20 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 23 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 24 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 25 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 26 |
* THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
|
| 29 |
This directory contains an obfuscation program. This program takes |
| 30 |
the following inputs: |
| 31 |
|
| 32 |
. An input directory which contains the original Java programs. This |
| 33 |
must be the CLASSPATH directory. All Java files within this |
| 34 |
directory except those under SCCS directories are considered for |
| 35 |
obfuscation. |
| 36 |
|
| 37 |
. An output directory into which the obfuscated files are generated. |
| 38 |
It should be possible to build the obfuscated version by setting the |
| 39 |
CLASSPATH to this directory. |
| 40 |
|
| 41 |
. A file of mappings of the form: |
| 42 |
( originalId "->" obfuscatedId ";" )* |
| 43 |
This specifies mappings from original identifiers to corresponding |
| 44 |
obfuscated ones. This file is optional, and even when it is |
| 45 |
present, it does not have to specify all identifiers in the input |
| 46 |
file. |
| 47 |
|
| 48 |
. A file containing identifiers that must not be obfuscated. This is |
| 49 |
typically used to prevent references to the standard API's from |
| 50 |
being changed. This file is optional. |
| 51 |
|
| 52 |
. A file containing identifiers to be used for obfuscation. If an |
| 53 |
identifier is encountered in the original file that does not have a |
| 54 |
specified mapping and is not an identifier that must not be |
| 55 |
obfuscated, then identifiers from this file are used for |
| 56 |
obfuscation. Once identifiers from this file are exhausted, then |
| 57 |
identifiers starting with "O0" the letter 'O' followed by the digit |
| 58 |
'0' are generated automatically. This file is optional. |
| 59 |
|
| 60 |
The output of the program is: |
| 61 |
|
| 62 |
. An obfuscated version for each input Java file. Since package and |
| 63 |
class names are also obfuscated, the directory and file names will |
| 64 |
be different also. |
| 65 |
|
| 66 |
. A main program for each of the original main programs in their |
| 67 |
original forms (with the same package and class names) that calls |
| 68 |
the corresponding obfuscated main program. This is useful to retain |
| 69 |
access to the system as before. |
| 70 |
|
| 71 |
. A file containing all the mappings used during the obfuscation |
| 72 |
process. This file is in the same syntax as the input mapping file, |
| 73 |
and therefore it can be used as input for future obfuscations. This |
| 74 |
is useful when related systems are obfuscated in different runs of |
| 75 |
this program. |
| 76 |
|
| 77 |
To build the obfuscator, do the following: |
| 78 |
|
| 79 |
javacc Java1.1.jj |
| 80 |
javacc IdsFile.jj |
| 81 |
javacc MapFile.jj |
| 82 |
javac *.java |
| 83 |
|
| 84 |
Now the obfuscator is ready for use. Try it out as follows on the |
| 85 |
example provided: |
| 86 |
|
| 87 |
java Main input output maps nochangeids useids |
| 88 |
|
| 89 |
And take a look at the input and output directories. |
| 90 |
|
| 91 |
This example illustrates the use of multiple grammar files, some of |
| 92 |
which are used more than once while the system is running. Take a |
| 93 |
look at the usage of ReInit's and also the actions in the grammar. |
| 94 |
Note how easy it was to include actions into the Java grammar to |
| 95 |
determine whether or not it had a main program. Also note how easy it |
| 96 |
is to modify this program. |
| 97 |
|
| 98 |
Some comments are present in each of the files that comprise this |
| 99 |
example. |