diff --git a/jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java b/jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java index 4c6741d8d8ccfe04c21cb7b7c7167be6a2649f3a..13fccdbb77b081895165211145b5287ed3baf233 100644 --- a/jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java +++ b/jadx-core/src/main/java/jadx/core/deobf/DeobfPresets.java @@ -1,14 +1,17 @@ package jadx.core.deobf; -import java.io.File; +import static java.nio.charset.StandardCharsets.UTF_8; + import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,16 +22,16 @@ import jadx.core.dex.info.MethodInfo; class DeobfPresets { private static final Logger LOG = LoggerFactory.getLogger(DeobfPresets.class); - private static final String MAP_FILE_CHARSET = "UTF-8"; + private static final Charset MAP_FILE_CHARSET = UTF_8; private final Deobfuscator deobfuscator; - private final File deobfMapFile; + private final Path deobfMapFile; private final Map clsPresetMap = new HashMap<>(); private final Map fldPresetMap = new HashMap<>(); private final Map mthPresetMap = new HashMap<>(); - public DeobfPresets(Deobfuscator deobfuscator, File deobfMapFile) { + public DeobfPresets(Deobfuscator deobfuscator, Path deobfMapFile) { this.deobfuscator = deobfuscator; this.deobfMapFile = deobfMapFile; } @@ -37,12 +40,12 @@ class DeobfPresets { * Loads deobfuscator presets */ public void load() { - if (!deobfMapFile.exists()) { + if (!Files.exists(deobfMapFile)) { return; } - LOG.info("Loading obfuscation map from: {}", deobfMapFile.getAbsoluteFile()); + LOG.info("Loading obfuscation map from: {}", deobfMapFile.toAbsolutePath()); try { - List lines = FileUtils.readLines(deobfMapFile, MAP_FILE_CHARSET); + List lines = Files.readAllLines(deobfMapFile, MAP_FILE_CHARSET); for (String l : lines) { l = l.trim(); if (l.isEmpty() || l.startsWith("#")) { @@ -65,7 +68,7 @@ class DeobfPresets { } } } catch (IOException e) { - LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.getAbsolutePath(), e); + LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.toAbsolutePath(), e); } } @@ -79,18 +82,18 @@ class DeobfPresets { public void save(boolean forceSave) { try { - if (deobfMapFile.exists()) { + if (Files.exists(deobfMapFile)) { if (forceSave) { dumpMapping(); } else { LOG.warn("Deobfuscation map file '{}' exists. Use command line option '--deobf-rewrite-cfg' to rewrite it", - deobfMapFile.getAbsolutePath()); + deobfMapFile.toAbsolutePath()); } } else { dumpMapping(); } } catch (IOException e) { - LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.getAbsolutePath(), e); + LOG.error("Failed to load deobfuscation map file '{}'", deobfMapFile.toAbsolutePath(), e); } } @@ -122,7 +125,7 @@ class DeobfPresets { list.add(String.format("m %s = %s", mth.getRawFullId(), mth.getAlias())); } Collections.sort(list); - FileUtils.writeLines(deobfMapFile, MAP_FILE_CHARSET, list); + Files.write(deobfMapFile, list, MAP_FILE_CHARSET); if (LOG.isDebugEnabled()) { LOG.debug("Deobfuscation map file saved as: {}", deobfMapFile); } diff --git a/jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java b/jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java index a82e9f5ac20f81c945dd47cabf3991c1e2a1721c..a5e69067a7acbbf169a6354d744f9f29979685c2 100644 --- a/jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java +++ b/jadx-core/src/main/java/jadx/core/deobf/Deobfuscator.java @@ -1,6 +1,7 @@ package jadx.core.deobf; import java.io.File; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -62,7 +63,12 @@ public class Deobfuscator { private int fldIndex = 0; private int mthIndex = 0; + @Deprecated public Deobfuscator(JadxArgs args, @NotNull List dexNodes, File deobfMapFile) { + this(args, dexNodes, deobfMapFile.toPath()); + } + + public Deobfuscator(JadxArgs args, @NotNull List dexNodes, Path deobfMapFile) { this.args = args; this.dexNodes = dexNodes; diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java index 1ae7d6206385840d05f416784faf7b15e2e271de..5fb44813929186309494a6eac325197ad593b320 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/RenameVisitor.java @@ -1,12 +1,10 @@ package jadx.core.dex.visitors; -import java.io.File; +import java.nio.file.Path; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.io.FilenameUtils; - import jadx.api.JadxArgs; import jadx.core.Consts; import jadx.core.deobf.Deobfuscator; @@ -33,13 +31,14 @@ public class RenameVisitor extends AbstractVisitor { return; } InputFile firstInputFile = dexNodes.get(0).getDexFile().getInputFile(); - String firstInputFileName = firstInputFile.getFile().getAbsolutePath(); - String inputPath = FilenameUtils.getFullPathNoEndSeparator(firstInputFileName); - String inputName = FilenameUtils.getBaseName(firstInputFileName); + Path inputFilePath = firstInputFile.getFile().toPath(); + + String inputName = inputFilePath.getFileName().toString(); + inputName = inputName.substring(0, inputName.lastIndexOf('.')); - File deobfMapFile = new File(inputPath, inputName + ".jobf"); + Path deobfMapPath = inputFilePath.getParent().resolve(inputName + ".jobf"); JadxArgs args = root.getArgs(); - deobfuscator = new Deobfuscator(args, dexNodes, deobfMapFile); + deobfuscator = new Deobfuscator(args, dexNodes, deobfMapPath); boolean deobfuscationOn = args.isDeobfuscationOn(); if (deobfuscationOn) { deobfuscator.execute();