Skip to content

Commit

Permalink
chore: do not deobfuscate known top level domains with 2 or 3 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
jpstotz committed Feb 6, 2022
1 parent 3c05b05 commit 38525d1
Show file tree
Hide file tree
Showing 3 changed files with 508 additions and 0 deletions.
1 change: 1 addition & 0 deletions jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ private void processPackageFull(PackageNode pkg, String fullName) {
if (!pkg.hasAlias()) {
String pkgName = pkg.getName();
if ((args.isDeobfuscationOn() && shouldRename(pkgName))
&& (pkg.getParentPackage() != rootPackage || !TldHelper.contains(pkgName)) // check if first level is a valid tld
|| (args.isRenameValid() && !NameMapper.isValidIdentifier(pkgName))
|| (args.isRenamePrintable() && !NameMapper.isAllCharsPrintable(pkgName))) {
String pkgAlias = String.format("p%03d%s", pkgIndex++, prepareNamePart(pkg.getName()));
Expand Down
38 changes: 38 additions & 0 deletions jadx-core/src/main/java/jadx/core/deobf/TldHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package jadx.core.deobf;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

import jadx.core.utils.exceptions.JadxRuntimeException;

/**
* Provides a list of all top level domains with 3 characters and less,
* so we can exclude them from deobfuscation.
*/
public class TldHelper {

private static final Set<String> TLD_SET = loadTldFile();

private static Set<String> loadTldFile() {
Set<String> tldNames = new HashSet<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(Deobfuscator.class.getResourceAsStream("tld_3.txt")))) {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
if (!line.startsWith("#") && !line.isEmpty()) {
tldNames.add(line);
}
}
return tldNames;
} catch (Exception e) {
throw new JadxRuntimeException("Failed to load top level domain list tld_3.txt", e);
}
}

public static boolean contains(String name) {
return TLD_SET.contains(name);
}

}
Loading

0 comments on commit 38525d1

Please sign in to comment.