Commit d2d43711 authored by NeoSpb's avatar NeoSpb

Make optional using source file name as alias for class name (some obfuscator

set the source file property with wrong value and break deobfuscation)
default: disabled
parent 510035b7
...@@ -64,6 +64,9 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -64,6 +64,9 @@ public class JadxCLIArgs implements IJadxArgs {
@Parameter(names = {"--deobf-rewrite-cfg"}, description = "force to save deobfuscation map") @Parameter(names = {"--deobf-rewrite-cfg"}, description = "force to save deobfuscation map")
protected boolean deobfuscationForceSave = false; protected boolean deobfuscationForceSave = false;
@Parameter(names = {"--deobf-use-sourcename"}, description = "use source file name as class name alias")
protected boolean deobfuscationUseSourceNameAsAlias = false;
@Parameter(names = {"-h", "--help"}, description = "print this help", help = true) @Parameter(names = {"-h", "--help"}, description = "print this help", help = true)
protected boolean printHelp = false; protected boolean printHelp = false;
...@@ -242,4 +245,9 @@ public class JadxCLIArgs implements IJadxArgs { ...@@ -242,4 +245,9 @@ public class JadxCLIArgs implements IJadxArgs {
public boolean isDeobfuscationForceSave() { public boolean isDeobfuscationForceSave() {
return deobfuscationForceSave; return deobfuscationForceSave;
} }
@Override
public boolean useSourceNameAsClassAlias() {
return deobfuscationUseSourceNameAsAlias;
}
} }
...@@ -68,4 +68,9 @@ public class DefaultJadxArgs implements IJadxArgs { ...@@ -68,4 +68,9 @@ public class DefaultJadxArgs implements IJadxArgs {
public boolean isDeobfuscationForceSave() { public boolean isDeobfuscationForceSave() {
return false; return false;
} }
@Override
public boolean useSourceNameAsClassAlias() {
return false;
}
} }
...@@ -28,4 +28,6 @@ public interface IJadxArgs { ...@@ -28,4 +28,6 @@ public interface IJadxArgs {
int getDeobfuscationMaxLength(); int getDeobfuscationMaxLength();
boolean isDeobfuscationForceSave(); boolean isDeobfuscationForceSave();
boolean useSourceNameAsClassAlias();
} }
...@@ -45,6 +45,8 @@ public class Deobfuscator { ...@@ -45,6 +45,8 @@ public class Deobfuscator {
private final int maxLength; private final int maxLength;
private final int minLength; private final int minLength;
private final boolean useSourceNameAsAlias;
private int pkgIndex = 0; private int pkgIndex = 0;
private int clsIndex = 0; private int clsIndex = 0;
private int fldIndex = 0; private int fldIndex = 0;
...@@ -56,6 +58,7 @@ public class Deobfuscator { ...@@ -56,6 +58,7 @@ public class Deobfuscator {
this.minLength = args.getDeobfuscationMinLength(); this.minLength = args.getDeobfuscationMinLength();
this.maxLength = args.getDeobfuscationMaxLength(); this.maxLength = args.getDeobfuscationMaxLength();
this.useSourceNameAsAlias = args.useSourceNameAsClassAlias();
this.deobfPresets = new DeobfPresets(this, deobfMapFile); this.deobfPresets = new DeobfPresets(this, deobfMapFile);
} }
...@@ -212,7 +215,12 @@ public class Deobfuscator { ...@@ -212,7 +215,12 @@ public class Deobfuscator {
private String makeClsAlias(ClassNode cls) { private String makeClsAlias(ClassNode cls) {
ClassInfo classInfo = cls.getClassInfo(); ClassInfo classInfo = cls.getClassInfo();
String alias = getAliasFromSourceFile(cls); String alias = null;
if (this.useSourceNameAsAlias) {
alias = getAliasFromSourceFile(cls);
}
if (alias == null) { if (alias == null) {
String clsName = classInfo.getShortName(); String clsName = classInfo.getShortName();
alias = String.format("C%04d%s", clsIndex++, makeName(clsName)); alias = String.format("C%04d%s", clsIndex++, makeName(clsName));
......
...@@ -132,6 +132,10 @@ public class JadxSettings extends JadxCLIArgs { ...@@ -132,6 +132,10 @@ public class JadxSettings extends JadxCLIArgs {
this.deobfuscationForceSave = deobfuscationForceSave; this.deobfuscationForceSave = deobfuscationForceSave;
} }
public void setUseSourceNameAsClassAlias(boolean useSourceNameAsAlias) {
this.deobfuscationUseSourceNameAsAlias = useSourceNameAsAlias;
}
public Font getFont() { public Font getFont() {
if (fontStr.isEmpty()) { if (fontStr.isEmpty()) {
return DEFAULT_FONT; return DEFAULT_FONT;
......
...@@ -141,11 +141,21 @@ public class JadxSettingsWindow extends JDialog { ...@@ -141,11 +141,21 @@ public class JadxSettingsWindow extends JDialog {
} }
}); });
JCheckBox deobfSourceAlias = new JCheckBox();
deobfSourceAlias.setSelected(settings.useSourceNameAsClassAlias());
deobfSourceAlias.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
settings.setUseSourceNameAsClassAlias(e.getStateChange() == ItemEvent.SELECTED);
needReload();
}
});
SettingsGroup deobfGroup = new SettingsGroup(NLS.str("preferences.deobfuscation")); SettingsGroup deobfGroup = new SettingsGroup(NLS.str("preferences.deobfuscation"));
deobfGroup.addRow(NLS.str("preferences.deobfuscation_on"), deobfOn); deobfGroup.addRow(NLS.str("preferences.deobfuscation_on"), deobfOn);
deobfGroup.addRow(NLS.str("preferences.deobfuscation_force"), deobfForce); deobfGroup.addRow(NLS.str("preferences.deobfuscation_force"), deobfForce);
deobfGroup.addRow(NLS.str("preferences.deobfuscation_min_len"), minLen); deobfGroup.addRow(NLS.str("preferences.deobfuscation_min_len"), minLen);
deobfGroup.addRow(NLS.str("preferences.deobfuscation_max_len"), maxLen); deobfGroup.addRow(NLS.str("preferences.deobfuscation_max_len"), maxLen);
deobfGroup.addRow(NLS.str("preferences.deobfuscation_source_alias"), deobfSourceAlias);
deobfGroup.end(); deobfGroup.end();
return deobfGroup; return deobfGroup;
} }
......
...@@ -62,6 +62,7 @@ preferences.deobfuscation_on=Enable deobfuscation ...@@ -62,6 +62,7 @@ preferences.deobfuscation_on=Enable deobfuscation
preferences.deobfuscation_force=Force rewrite deobfuscation map file preferences.deobfuscation_force=Force rewrite deobfuscation map file
preferences.deobfuscation_min_len=Minimum name length preferences.deobfuscation_min_len=Minimum name length
preferences.deobfuscation_max_len=Maximum name length preferences.deobfuscation_max_len=Maximum name length
preferences.deobfuscation_source_alias=Use source file name as class name alias
preferences.save=Save preferences.save=Save
preferences.cancel=Cancel preferences.cancel=Cancel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment