I don’t know how many people have said I’m going to write a blog about dictionary confusion
1. What is obfuscation dictionary?
Dictionarytext.txt dictionarytext.txt
IiII1I1iI
iiIiI1
1IIII11i
1IIIiI111
iiiIII
iIIIIi1
1II11IiiI
II1i1
....// Approximately 5000 lines without repeating each line
Copy the code
Set in proguard-rules:
-obfuscationdictionary dictionarytext.txt
-classobfuscationdictionary dictionarytext.txt
-packageobfuscationdictionary dictionarytext.txt
Copy the code
This confuses the packaged code to use the dictionary content.
So if you mix it up, you can mix up the class name, the method name, it’s very hard to read but if you have a dictionary that’s kind of crazy like Arabic Sanskrit doesn’t follow the naming rules, it just changes the package pathname, it doesn’t change the class name it doesn’t use the dictionary for the method name
2. How do I get (generate) obfuscation dictionaries
To have your own unique dictionary I wrote a script in Java:
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/** * Created by Tomato 2020/12 * JAVA generated obfuscating dictionary */
public class ProguardGenerateClass {
// Dictionary sample
private static List<String> SOURCE = Arrays.asList("i"."I"."1"."l");
// The number of dictionary lines
private static int LENGTH = 5000;
// Output path
private static final String ROOT_PATH = System.getProperty("user.dir") + "/app/";
// Output the name
private static final String FILE_NAME = "output_dict.txt";
private static Random random = new Random();
public static void main(String[] args) {
List<String> unicodeList = new ArrayList(SOURCE);
List<String> outputList = new ArrayList<String>();
Collections.sort(unicodeList);
File file = new File(ROOT_PATH, FILE_NAME);
if (file.exists()) {
System.out.println("File already exists, delete");
file.delete();
} else {
System.out.println("File does not exist");
}
String encoding = "UTF-8";
int repeatCount = 0;
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
int i = 0;
while (i < LENGTH) {
String tmp = "";
int width = random.nextInt(7) + 4;
for (int j = 0; j < width; j++) {
tmp = tmp + getRandomString(unicodeList);
}
if(! outputList.contains(tmp)) { i++; outputList.add(tmp); fileOutputStream.write(tmp.getBytes(encoding));if (i < LENGTH) {
// The last line does not enter enter
fileOutputStream.write('\n');
}
repeatCount = 0;
} else {
repeatCount++;
System.out.println("Current line number of repeatedly generated string -->" + i + "Contents" --> + tmp);
if (repeatCount == 10000) {
System.out.println("The number of consecutive repetitions exceeds 10,000. The maximum number of rows cannot be generated.");
break;
}
}
}
fileOutputStream.flush();
fileOutputStream.close();
} catch(Exception e) { e.printStackTrace(); }}private static String getRandomString(List<String> list) {
String tm;
int s = random.nextInt(list.size());
tm = list.get(s);
returntm; }}Copy the code
Set the desired number of lines, source characters, output path, and output file name to run in Android Studio
You may encounter the following problems:
Could not create task ':app:ProguardGenerateClass.main()'. > SourceSet with
Just add a sentence under.idea gradle.xlm
<GradleProjectSettings>
<option name="delegatedBuild" value="false"/>
...
</GradleProjectSettings>
Copy the code
In addition, there are a lot of ready-made dictionaries on Github. I recommend one at github.com/ysrc/Androi…