Renaming replaces the meaningful names of packages, classes, methods, and fields in your Java bytecode with meaningless names, such as a and b. It makes your bytecode more compact and harder to reverse-engineer.
The names you choose in your source code reveal a lot about what each part of your software does. Java keeps these names in the compiled bytecode, because some of them matter after compilation, such as the name of a class whose main method you invoke, or a method another project references. Most names, though, aren't needed after compilation. They only make your app easier for an attacker to understand.
This article explains how Renaming works. To configure it, see Configure Renaming in the DashO User Interface or the <renaming> element of your project file.
What Renaming Controls
You enable or disable Renaming globally. You also choose whether DashO renames:
- Classes
- Members (methods and fields)
- Internally defined annotations
Packages and Class Prefixes
When DashO renames classes, you control which packages the renamed classes go in.
Flattened Package Hierarchy (Default)
By default, DashO flattens the package hierarchy and puts all renamed classes in the same package. That's the default package, unless you set a class prefix that includes a period.
| Original Name | New Name |
|---|---|
yoyodyne.application.Main
|
a
|
yoyodyne.application.LoadData
|
b
|
yoyodyne.tools.BinaryTree
|
c
|
yoyodyne.tools.LinkedList
|
d
|
Flattened Hierarchy with a Class Prefix
Use a class prefix to specify a package or to add text to the start of each renamed class:
| Original Name | New Name with yoyodyne. Class Prefix |
New Name with yoyodyne.X_ Class Prefix |
|---|---|---|
yoyodyne.application.Main |
yoyodyne.a |
yoyodyne.X_a |
yoyodyne.application.LoadData |
yoyodyne.b |
yoyodyne.X_b |
yoyodyne.tools.BinaryTree |
yoyodyne.c |
yoyodyne.X_c |
yoyodyne.tools.LinkedList |
yoyodyne.d |
yoyodyne.X_d |
Retained Package Hierarchy
Without package flattening, DashO keeps each class in its original package and renames only the class itself:
| Original Name | New Name with No Class Prefix |
New Name with internal.X_ Class Prefix
|
|---|---|---|
yoyodyne.application.Main
|
yoyodyne.application.a
|
yoyodyne.application.internal.X_a
|
yoyodyne.application.LoadData
|
yoyodyne.application.b
|
yoyodyne.application.internal.X_b
|
yoyodyne.tools.BinaryTree
|
yoyodyne.tools.c
|
yoyodyne.tools.internal.X_c
|
yoyodyne.tools.LinkedList
|
yoyodyne.tools.d
|
yoyodyne.tools.internal.X_d
|
Alphabets
DashO creates new names for classes and members from an alphabet. Choose one of the predefined alphabets or create your own. A custom alphabet must follow these rules:
- It contains at least two characters. For larger projects, use three or more.
- Its initial characters are valid starting characters for Java identifiers. It needs at least one starting character.
- Its remaining characters are valid characters for Java identifiers.
The number of characters in the alphabet affects the allowed minimum length of new names.
Minimum Length
Minimum length sets the shortest name DashO creates for classes or members. For example, with a minimum length of 3 for classes, DashO starts with class names like aaa and never creates shorter ones.
DashO calculates the highest allowed minimum length from the number of characters in your alphabet. The fewer characters in the alphabet, the higher the allowed value. To raise the minimum length beyond the limit, shorten the alphabet.
| Alphabet | Highest allowed minimum length |
abcdefghijklmnopqrstuvwxyz_0123456789 |
6 |
abcdefghijklmno |
7 |
Randomized Renaming
With randomized renaming, DashO chooses names randomly from the pool of shortest available names, for classes, members, or both. The sequence of names changes between DashO runs, unless you use Incremental Obfuscation.
With the alphabet abc, DashO generates this sequence without randomized renaming:
a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc...
With randomized renaming, it might generate this sequence instead:
c, a, b, bc, ab, cc, bb, cb, ca, aa, bc, ac...
DashO uses all 1-character names before it uses any 2-character names.
Overload Induction™
Overload Induction reuses method names as much as possible through overloading. Methods with different signatures get the same new name.
| Original method | With Overload Induction | With Simple Renaming |
foo() |
a() |
a() |
bar(int) |
a(int) |
b(int) |
baz(String) |
a(String) |
c(String) |
Reusing short names makes your code harder to understand and your bytecode more compact. It reduces the number of constant pool entries your classes need to define names, and the remaining entries take up much less space because the names are shorter.
Entry Points and Renaming Exclusions
Some elements must keep their names to work correctly, such as static void main(String[]) methods and the classes that contain them.
For more information, see Entry Points and Exclude Items from Renaming.
Reflection
If your code accesses a class or its members through reflection, DashO may not be able to rename them in a way that keeps the reflection working. DashO offers two options on the Input - Options page:
| Option | What DashO does |
| Determine Reflected Classes | Attempts to find classes accessed through reflection and excludes them from Renaming. |
| Determine Reflected Classes and Rename Reflected Classes | Attempts to rename the reflected classes and update references to them in String constants to match the new names. |
Manually marking reflected classes and members as Entry Points, or excluding them from Renaming, is generally more reliable. For more information, see Dynamic Class Loading.
Renaming Map Files
A Renaming Map File maps the original names of classes, methods, and other items to their new names. Use it to:
- Decode stack traces. Stack traces from your protected software use the renamed package, class, and method names. Decode them in DashO or with the separate DashO Lucidator utility, using the map file you kept from the build.
- Use Incremental Obfuscation. Incremental Obfuscation requires a Renaming Map File.
Along with the default DashO-compatible map file, you choose whether DashO also creates an R8/ProGuard-compatible map file for third-party tools that depend on one.
Renaming Report
For a more human-readable record of Renaming, have DashO create a renaming report. Configure it on the Output - Reports page.
Limitations and Troubleshooting
| Issue | Cause and resolution |
| Renaming is unavailable. | Your project uses Android Mode, where R8 handles renaming. Enable R8. |
| The build fails with a minimum length error. | The minimum length exceeds the highest value your alphabet allows. Lower the minimum length or shorten the alphabet. |
| Reflection breaks after Renaming. | DashO can't detect reflection-based access to methods or fields. Mark reflected classes and members as Entry Points, or exclude them from Renaming. |
| DashO doesn't update the map file. | DashO doesn't overwrite an existing map file by default. Select Overwrite, or move the existing file. |