mirror of
https://github.com/skylot/jadx.git
synced 2025-02-17 03:30:06 +00:00
feat: allow to change config and cache dirs with env vars (#2159)
This commit is contained in:
parent
f2a6a1e942
commit
09fa35f144
@ -185,6 +185,8 @@ Environment variables:
|
||||
JADX_DISABLE_XML_SECURITY - set to 'true' to disable all security checks for XML files
|
||||
JADX_DISABLE_ZIP_SECURITY - set to 'true' to disable all security checks for zip files
|
||||
JADX_ZIP_MAX_ENTRIES_COUNT - maximum allowed number of entries in zip files (default: 100 000)
|
||||
JADX_CONFIG_DIR - custom config directory, using system by default
|
||||
JADX_CACHE_DIR - custom cache directory, using system by default
|
||||
JADX_TMP_DIR - custom temp directory, using system by default
|
||||
|
||||
Examples:
|
||||
|
@ -111,6 +111,8 @@ public class JCommanderWrapper<T> {
|
||||
out.println(" JADX_DISABLE_XML_SECURITY - set to 'true' to disable all security checks for XML files");
|
||||
out.println(" JADX_DISABLE_ZIP_SECURITY - set to 'true' to disable all security checks for zip files");
|
||||
out.println(" JADX_ZIP_MAX_ENTRIES_COUNT - maximum allowed number of entries in zip files (default: 100 000)");
|
||||
out.println(" JADX_CONFIG_DIR - custom config directory, using system by default");
|
||||
out.println(" JADX_CACHE_DIR - custom cache directory, using system by default");
|
||||
out.println(" JADX_TMP_DIR - custom temp directory, using system by default");
|
||||
out.println();
|
||||
out.println("Examples:");
|
||||
|
6
jadx-commons/jadx-app-commons/README.md
Normal file
6
jadx-commons/jadx-app-commons/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
## jadx app commons
|
||||
|
||||
This module contains common utilities used in jadx apps (cli and gui) and not needed in jadx-code module:
|
||||
- `JadxCommonFiles` - wrapper for `dev.dirs:directories` lib to get
|
||||
'config' and 'cache' directories in cross-platform way
|
||||
- `JadxCommonEnv` - utils for work with environment variables
|
7
jadx-commons/jadx-app-commons/build.gradle.kts
Normal file
7
jadx-commons/jadx-app-commons/build.gradle.kts
Normal file
@ -0,0 +1,7 @@
|
||||
plugins {
|
||||
id("jadx-library")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("dev.dirs:directories:26")
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package jadx.commons.app;
|
||||
|
||||
public class JadxCommonEnv {
|
||||
|
||||
public static String get(String varName, String defValue) {
|
||||
String strValue = System.getenv(varName);
|
||||
return isNullOrEmpty(strValue) ? defValue : strValue;
|
||||
}
|
||||
|
||||
public static boolean getBool(String varName, boolean defValue) {
|
||||
String strValue = System.getenv(varName);
|
||||
if (isNullOrEmpty(strValue)) {
|
||||
return defValue;
|
||||
}
|
||||
return strValue.equalsIgnoreCase("true");
|
||||
}
|
||||
|
||||
public static int getInt(String varName, int defValue) {
|
||||
String strValue = System.getenv(varName);
|
||||
if (isNullOrEmpty(strValue)) {
|
||||
return defValue;
|
||||
}
|
||||
return Integer.parseInt(strValue);
|
||||
}
|
||||
|
||||
private static boolean isNullOrEmpty(String value) {
|
||||
return value == null || value.isEmpty();
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package jadx.commons.app;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import dev.dirs.ProjectDirectories;
|
||||
|
||||
public class JadxCommonFiles {
|
||||
|
||||
private static final Path CONFIG_DIR;
|
||||
private static final Path CACHE_DIR;
|
||||
|
||||
public static Path getConfigDir() {
|
||||
return CONFIG_DIR;
|
||||
}
|
||||
|
||||
public static Path getCacheDir() {
|
||||
return CACHE_DIR;
|
||||
}
|
||||
|
||||
static {
|
||||
DirsLoader loader = new DirsLoader();
|
||||
loader.init();
|
||||
CONFIG_DIR = loader.getConfigDir();
|
||||
CACHE_DIR = loader.getCacheDir();
|
||||
}
|
||||
|
||||
private static final class DirsLoader {
|
||||
private @Nullable ProjectDirectories dirs;
|
||||
private Path configDir;
|
||||
private Path cacheDir;
|
||||
|
||||
public void init() {
|
||||
try {
|
||||
configDir = loadEnvDir("JADX_CONFIG_DIR");
|
||||
cacheDir = loadEnvDir("JADX_CACHE_DIR");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to init common directories", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Path loadEnvDir(String envVar) throws IOException {
|
||||
String envDir = JadxCommonEnv.get(envVar, null);
|
||||
String dirStr;
|
||||
if (envDir != null) {
|
||||
dirStr = envDir;
|
||||
} else {
|
||||
dirStr = loadDirs().configDir;
|
||||
}
|
||||
Path path = Path.of(dirStr).toAbsolutePath();
|
||||
Files.createDirectories(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
private synchronized ProjectDirectories loadDirs() {
|
||||
if (dirs == null) {
|
||||
dirs = ProjectDirectories.from("io.github", "skylot", "jadx");
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
public Path getCacheDir() {
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
public Path getConfigDir() {
|
||||
return configDir;
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ dependencies {
|
||||
implementation(project(":jadx-core"))
|
||||
implementation(project(":jadx-cli"))
|
||||
implementation(project(":jadx-plugins-tools"))
|
||||
implementation(project(":jadx-commons:jadx-app-commons"))
|
||||
|
||||
// import mappings
|
||||
implementation(project(":jadx-plugins:jadx-rename-mappings"))
|
||||
@ -26,7 +27,6 @@ dependencies {
|
||||
|
||||
implementation("org.jcommander:jcommander:1.83")
|
||||
implementation("ch.qos.logback:logback-classic:1.5.6")
|
||||
implementation("dev.dirs:directories:26")
|
||||
|
||||
implementation("com.fifesoft:rsyntaxtextarea:3.4.0")
|
||||
implementation(files("libs/jfontchooser-1.0.5.jar"))
|
||||
|
@ -1,24 +1,15 @@
|
||||
package jadx.gui.utils.files;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import dev.dirs.ProjectDirectories;
|
||||
|
||||
import jadx.core.utils.files.FileUtils;
|
||||
import jadx.commons.app.JadxCommonFiles;
|
||||
|
||||
public class JadxFiles {
|
||||
|
||||
private static final ProjectDirectories DIRS = ProjectDirectories.from("io.github", "skylot", "jadx");
|
||||
private static final String CONFIG_DIR = DIRS.configDir;
|
||||
private static final Path CONFIG_DIR = JadxCommonFiles.getConfigDir();
|
||||
public static final Path GUI_CONF = CONFIG_DIR.resolve("gui.json");
|
||||
public static final Path CACHES_LIST = CONFIG_DIR.resolve("caches.json");
|
||||
|
||||
public static final Path GUI_CONF = Paths.get(CONFIG_DIR, "gui.json");
|
||||
public static final Path CACHES_LIST = Paths.get(CONFIG_DIR, "caches.json");
|
||||
|
||||
public static final Path CACHE_DIR = Paths.get(DIRS.cacheDir);
|
||||
public static final Path CACHE_DIR = JadxCommonFiles.getCacheDir();
|
||||
public static final Path PROJECTS_CACHE_DIR = CACHE_DIR.resolve("projects");
|
||||
|
||||
static {
|
||||
FileUtils.makeDirs(Paths.get(CONFIG_DIR));
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ plugins {
|
||||
dependencies {
|
||||
api(project(":jadx-core"))
|
||||
|
||||
implementation("dev.dirs:directories:26")
|
||||
implementation(project(":jadx-commons:jadx-app-commons"))
|
||||
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
}
|
||||
|
@ -1,22 +1,19 @@
|
||||
package jadx.plugins.tools.utils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import dev.dirs.ProjectDirectories;
|
||||
import jadx.commons.app.JadxCommonFiles;
|
||||
|
||||
import static jadx.core.utils.files.FileUtils.makeDirs;
|
||||
|
||||
public class PluginFiles {
|
||||
private static final ProjectDirectories DIRS = ProjectDirectories.from("io.github", "skylot", "jadx");
|
||||
|
||||
private static final Path PLUGINS_DIR = Paths.get(DIRS.configDir, "plugins");
|
||||
private static final Path PLUGINS_DIR = JadxCommonFiles.getConfigDir().resolve("plugins");
|
||||
public static final Path PLUGINS_JSON = PLUGINS_DIR.resolve("plugins.json");
|
||||
public static final Path INSTALLED_DIR = PLUGINS_DIR.resolve("installed");
|
||||
public static final Path DROPINS_DIR = PLUGINS_DIR.resolve("dropins");
|
||||
|
||||
private static final Path CACHE_DIR = Paths.get(DIRS.cacheDir);
|
||||
public static final Path PLUGINS_LIST_CACHE = CACHE_DIR.resolve("plugin-list.json");
|
||||
public static final Path PLUGINS_LIST_CACHE = JadxCommonFiles.getCacheDir().resolve("plugin-list.json");
|
||||
|
||||
static {
|
||||
makeDirs(INSTALLED_DIR);
|
||||
|
@ -5,6 +5,7 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":jadx-plugins:jadx-script:jadx-script-runtime"))
|
||||
implementation(project(":jadx-commons:jadx-app-commons"))
|
||||
|
||||
implementation(kotlin("scripting-common"))
|
||||
implementation(kotlin("scripting-jvm"))
|
||||
@ -12,8 +13,5 @@ dependencies {
|
||||
|
||||
implementation("io.github.oshai:kotlin-logging-jvm:6.0.9")
|
||||
|
||||
// path for scripts cache
|
||||
implementation("dev.dirs:directories:26")
|
||||
|
||||
testImplementation(project(":jadx-core"))
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package jadx.plugins.script
|
||||
|
||||
import dev.dirs.ProjectDirectories
|
||||
import jadx.commons.app.JadxCommonFiles
|
||||
import java.io.File
|
||||
import java.security.MessageDigest
|
||||
import kotlin.script.experimental.api.CompiledScript
|
||||
@ -61,8 +61,7 @@ class ScriptCache {
|
||||
}
|
||||
|
||||
private fun getCacheDir(): File {
|
||||
val dirs = ProjectDirectories.from("io.github", "skylot", "jadx")
|
||||
val cacheBaseDir = File(dirs.cacheDir, "scripts")
|
||||
val cacheBaseDir = JadxCommonFiles.getCacheDir().resolve("scripts").toFile()
|
||||
cacheBaseDir.mkdirs()
|
||||
return cacheBaseDir
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ include("jadx-gui")
|
||||
|
||||
include("jadx-plugins-tools")
|
||||
|
||||
include("jadx-commons:jadx-app-commons")
|
||||
|
||||
include("jadx-plugins:jadx-input-api")
|
||||
include("jadx-plugins:jadx-dex-input")
|
||||
include("jadx-plugins:jadx-java-input")
|
||||
|
Loading…
x
Reference in New Issue
Block a user