Projects STRLCPY jadx Commits e0f623dc
🤬
  • build: configure spotless for kotlin, apply code style fixes

  • Loading...
  • Skylot committed 1 year ago
    e0f623dc
    1 parent a7b4b88e
  • ■ ■ ■ ■ ■
    build.gradle
     1 +//file:noinspection UnnecessaryQualifiedReference
     2 + 
    1 3  plugins {
    2 4   id 'com.github.ben-manes.versions' version '0.43.0'
    3 5   id 'com.diffplug.spotless' version '6.11.0'
     6 + 
     7 + id 'org.jetbrains.kotlin.jvm' version '1.7.20' // needed for spotless
    4 8  }
    5 9   
    6 10  ext.jadxVersion = System.getenv('JADX_VERSION') ?: "dev"
    skipped 2 lines
    9 13   
    10 14  allprojects {
    11 15   apply plugin: 'java'
     16 + apply plugin: 'kotlin'
    12 17   apply plugin: 'checkstyle'
    13 18   
    14 19   version = jadxVersion
    skipped 34 lines
    49 54   mavenLocal()
    50 55   mavenCentral()
    51 56   google()
    52  - // Commented out for now since we're using a local mapping-io fork atm.
    53  - // maven {
    54  - // name 'FabricMC'
    55  - // url 'https://maven.fabricmc.net/'
    56  - // }
    57 57   }
    58 58  }
    59 59   
    skipped 15 lines
    75 75   trimTrailingWhitespace()
    76 76   endWithNewline()
    77 77   }
     78 + kotlin {
     79 + target fileTree(rootDir).matching {
     80 + include 'jadx-plugins/jadx-script/**/*.kt'
     81 +// include 'jadx-plugins/jadx-script/examples/scripts/**/*.jadx.kts'
     82 + }
     83 + ktlint()
     84 + .setUseExperimental(false)
     85 + .editorConfigOverride([indent_style: "tab"])
     86 + 
     87 + lineEndings(com.diffplug.spotless.LineEnding.UNIX)
     88 + encoding("UTF-8")
     89 + trimTrailingWhitespace()
     90 + endWithNewline()
     91 + }
    78 92   format 'misc', {
    79  - target '**/*.gradle', '**/*.md', '**/*.xml', '**/.gitignore', '**/.properties'
     93 + target '**/*.gradle', '**/*.xml', '**/.gitignore', '**/.properties'
    80 94   targetExclude ".gradle/**", ".idea/**", "*/build/**"
    81 95   
    82 96   lineEndings(com.diffplug.spotless.LineEnding.UNIX)
    skipped 79 lines
  • ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/deobf/DeobfuscatorVisitor.java
    skipped 70 lines
    71 71   }
    72 72   }
    73 73   }
     74 + 
     75 + @Override
     76 + public String toString() {
     77 + return "DeobfuscatorVisitor";
     78 + }
    74 79  }
    75 80   
  • ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/deobf/SaveDeobfMapping.java
    skipped 44 lines
    45 45   LOG.error("Failed to save deobfuscation map file '{}'", deobfMapFile.toAbsolutePath(), e);
    46 46   }
    47 47   }
     48 + 
     49 + @Override
     50 + public String toString() {
     51 + return "SaveDeobfMapping";
     52 + }
    48 53  }
    49 54   
  • ■ ■ ■ ■ ■
    jadx-core/src/main/java/jadx/core/dex/visitors/AbstractVisitor.java
    skipped 21 lines
    22 22   public void visit(MethodNode mth) throws JadxException {
    23 23   // no op implementation
    24 24   }
     25 + 
     26 + @Override
     27 + public String toString() {
     28 + return this.getClass().getSimpleName();
     29 + }
    25 30  }
    26 31   
  • ■ ■ ■ ■ ■ ■
    jadx-gui/src/main/resources/files/script.jadx.kts.tmpl
     1 +/**
     2 + For script usage check https://github.com/skylot/jadx/blob/master/jadx-plugins/jadx-script/readme.md
     3 +*/
     4 + 
    1 5  val jadx = getJadxInstance()
    2 6   
    3 7  jadx.afterLoad {
    skipped 3 lines
  • ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/readme.md jadx-plugins/jadx-script/README.md
    skipped 3 lines
    4 4   
    5 5  ### Examples
    6 6   
    7  -Check script examples in `examples/scripts/` (start with `hello`)
     7 +Check script examples in [`examples/scripts/`](https://github.com/skylot/jadx/tree/master/jadx-plugins/jadx-script/examples/scripts)
     8 +(start with [`hello`](https://github.com/skylot/jadx/blob/master/jadx-plugins/jadx-script/examples/scripts/hello.jadx.kts))
    8 9   
    9 10  ### Script usage
    10 11   
    skipped 10 lines
    21 22   
    22 23  ### Script development
    23 24   
    24  -Jadx-gui for now don't support autocompletion, errors highlighting, docs and code navigation
     25 +Jadx-gui for now don't support ~~autocompletion,~~ errors highlighting, docs and code navigation,
    25 26  so best approach for script editing is to open jadx project in IntelliJ Idea and write your script in `examples/scripts/` folder.
    26 27  Also, this will allow to debug your scripts: for that you need to create run configuration for jadx-cli or jadx-gui
    27 28  add breakpoints and next run it in debug mode (jadx-gui is preferred because of faster script reload).
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/examples/build.gradle.kts
    1  -plugins {
    2  - kotlin("jvm") version "1.7.20"
    3  -}
    4  - 
    5 1  dependencies {
    6 2   implementation(project(":jadx-plugins:jadx-script:jadx-script-runtime"))
    7 3   
    skipped 15 lines
  • jadx-plugins/jadx-script/examples/context/stubs.kt jadx-plugins/jadx-script/examples/context/Stubs.kt
    Content is identical
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-ide/build.gradle.kts
    1  -plugins {
    2  - kotlin("jvm") version "1.7.20"
    3  -}
    4  - 
    5 1  dependencies {
    6 2   implementation("org.jetbrains.kotlin:kotlin-scripting-common")
    7 3   implementation("org.jetbrains.kotlin:kotlin-scripting-jvm")
    skipped 10 lines
  • ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-ide/src/main/kotlin/complete.kt jadx-plugins/jadx-script/jadx-script-ide/src/main/kotlin/Complete.kt
    skipped 2 lines
    3 3  import jadx.plugins.script.runner.ScriptEval
    4 4  import kotlinx.coroutines.runBlocking
    5 5  import org.jetbrains.kotlin.scripting.ide_services.compiler.KJvmReplCompilerWithIdeServices
    6  -import kotlin.script.experimental.api.*
     6 +import kotlin.script.experimental.api.ReplCompletionResult
     7 +import kotlin.script.experimental.api.ResultWithDiagnostics
     8 +import kotlin.script.experimental.api.ScriptDiagnostic
     9 +import kotlin.script.experimental.api.SourceCode
     10 +import kotlin.script.experimental.api.SourceCodeCompletionVariant
     11 +import kotlin.script.experimental.api.valueOrNull
    7 12  import kotlin.script.experimental.host.toScriptSource
    8 13  import kotlin.script.experimental.jvm.util.toSourceCodePosition
    9 14   
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-plugin/build.gradle.kts
    1 1  plugins {
    2 2   id("jadx-library")
    3  - 
    4  - kotlin("jvm") version "1.7.20"
    5 3  }
    6 4   
    7 5  dependencies {
    skipped 11 lines
  • ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-plugin/src/main/kotlin/jadx/plugins/script/runner/ScriptEval.kt
    skipped 6 lines
    7 7  import jadx.plugins.script.runtime.data.JadxScriptAllOptions
    8 8  import mu.KotlinLogging
    9 9  import java.io.File
    10  -import kotlin.script.experimental.api.*
     10 +import kotlin.script.experimental.api.EvaluationResult
     11 +import kotlin.script.experimental.api.ResultValue
     12 +import kotlin.script.experimental.api.ResultWithDiagnostics
     13 +import kotlin.script.experimental.api.ScriptDiagnostic
     14 +import kotlin.script.experimental.api.ScriptEvaluationConfiguration
     15 +import kotlin.script.experimental.api.constructorArgs
    11 16  import kotlin.script.experimental.host.toScriptSource
    12 17  import kotlin.script.experimental.jvmhost.BasicJvmScriptingHost
    13 18  import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromTemplate
    skipped 61 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/build.gradle.kts
    1 1  plugins {
    2 2   id("jadx-library")
    3  - 
    4  - kotlin("jvm") version "1.7.20"
    5 3  }
    6 4   
    7 5  dependencies {
    skipped 20 lines
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/utils.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/Utils.kt
    Content is identical
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/runtime.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/Runtime.kt
    skipped 6 lines
    7 7  import jadx.api.JavaClass
    8 8  import jadx.api.plugins.JadxPluginContext
    9 9  import jadx.api.plugins.pass.JadxPass
    10  -import jadx.plugins.script.runtime.data.*
     10 +import jadx.plugins.script.runtime.data.Debug
     11 +import jadx.plugins.script.runtime.data.Decompile
     12 +import jadx.plugins.script.runtime.data.Gui
     13 +import jadx.plugins.script.runtime.data.JadxScriptAllOptions
     14 +import jadx.plugins.script.runtime.data.JadxScriptOptions
     15 +import jadx.plugins.script.runtime.data.Rename
     16 +import jadx.plugins.script.runtime.data.Replace
     17 +import jadx.plugins.script.runtime.data.Search
     18 +import jadx.plugins.script.runtime.data.Stages
    11 19  import mu.KLogger
    12 20  import mu.KotlinLogging
    13 21  import java.io.File
    14 22   
    15  - 
    16 23  open class JadxScriptBaseClass(private val scriptData: JadxScriptData) {
    17 24   val scriptName = scriptData.scriptName
    18  - val log = KotlinLogging.logger("JadxScript:${scriptName}")
     25 + val log = KotlinLogging.logger("JadxScript:$scriptName")
    19 26   
    20 27   fun getJadxInstance() = JadxScriptInstance(scriptData, log)
    21 28   
    skipped 24 lines
    46 53   private val decompiler = scriptData.jadxInstance
    47 54   
    48 55   val options: JadxScriptOptions by lazy { JadxScriptOptions(this, scriptData.options) }
    49  - val rename: RenamePass by lazy { RenamePass(this) }
     56 + val rename: Rename by lazy { Rename(this) }
    50 57   val stages: Stages by lazy { Stages(this) }
    51 58   val replace: Replace by lazy { Replace(this) }
    52 59   val decompile: Decompile by lazy { Decompile(this) }
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/Script.kt
     1 +package jadx.plugins.script.runtime
     2 + 
     3 +import kotlinx.coroutines.runBlocking
     4 +import kotlin.script.experimental.annotations.KotlinScript
     5 +import kotlin.script.experimental.api.ResultWithDiagnostics
     6 +import kotlin.script.experimental.api.ScriptAcceptedLocation
     7 +import kotlin.script.experimental.api.ScriptCollectedData
     8 +import kotlin.script.experimental.api.ScriptCompilationConfiguration
     9 +import kotlin.script.experimental.api.ScriptConfigurationRefinementContext
     10 +import kotlin.script.experimental.api.acceptedLocations
     11 +import kotlin.script.experimental.api.asSuccess
     12 +import kotlin.script.experimental.api.baseClass
     13 +import kotlin.script.experimental.api.collectedAnnotations
     14 +import kotlin.script.experimental.api.defaultImports
     15 +import kotlin.script.experimental.api.dependencies
     16 +import kotlin.script.experimental.api.ide
     17 +import kotlin.script.experimental.api.onSuccess
     18 +import kotlin.script.experimental.api.refineConfiguration
     19 +import kotlin.script.experimental.api.with
     20 +import kotlin.script.experimental.dependencies.CompoundDependenciesResolver
     21 +import kotlin.script.experimental.dependencies.DependsOn
     22 +import kotlin.script.experimental.dependencies.FileSystemDependenciesResolver
     23 +import kotlin.script.experimental.dependencies.Repository
     24 +import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
     25 +import kotlin.script.experimental.dependencies.resolveFromScriptSourceAnnotations
     26 +import kotlin.script.experimental.jvm.JvmDependency
     27 +import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
     28 +import kotlin.script.experimental.jvm.jvm
     29 + 
     30 +@KotlinScript(
     31 + fileExtension = "jadx.kts",
     32 + compilationConfiguration = JadxScriptConfiguration::class
     33 +)
     34 +abstract class JadxScript
     35 + 
     36 +object JadxScriptConfiguration : ScriptCompilationConfiguration({
     37 + defaultImports(DependsOn::class, Repository::class)
     38 + 
     39 + jvm {
     40 + dependenciesFromCurrentContext(
     41 + wholeClasspath = true
     42 + )
     43 + }
     44 + ide {
     45 + acceptedLocations(ScriptAcceptedLocation.Everywhere)
     46 + }
     47 + 
     48 + baseClass(JadxScriptBaseClass::class)
     49 + 
     50 + refineConfiguration {
     51 + onAnnotations(DependsOn::class, Repository::class, handler = ::configureMavenDepsOnAnnotations)
     52 + }
     53 +})
     54 + 
     55 +private val resolver = CompoundDependenciesResolver(FileSystemDependenciesResolver(), MavenDependenciesResolver())
     56 + 
     57 +fun configureMavenDepsOnAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
     58 + val annotations = context.collectedData?.get(ScriptCollectedData.collectedAnnotations)
     59 + ?.takeIf { it.isNotEmpty() }
     60 + ?: return context.compilationConfiguration.asSuccess()
     61 + return runBlocking { resolver.resolveFromScriptSourceAnnotations(annotations) }
     62 + .onSuccess {
     63 + context.compilationConfiguration.with {
     64 + dependencies.append(JvmDependency(it))
     65 + }.asSuccess()
     66 + }
     67 +}
     68 + 
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/debug.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Debug.kt
    Content is identical
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/decompile.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Decompile.kt
    Content is identical
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/gui.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Gui.kt
    Content is identical
  • ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/options.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Options.kt
    skipped 19 lines
    20 20  class ScriptOption<T>(
    21 21   val name: String,
    22 22   val id: String,
    23  - private val getter: () -> T,
     23 + private val getter: () -> T
    24 24  ) {
    25 25   private var validate: ((T) -> Boolean)? = null
    26 26   
    skipped 76 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Rename.kt
     1 +package jadx.plugins.script.runtime.data
     2 + 
     3 +import jadx.core.dex.attributes.AFlag
     4 +import jadx.core.dex.attributes.IAttributeNode
     5 +import jadx.core.dex.nodes.IDexNode
     6 +import jadx.core.dex.nodes.RootNode
     7 +import jadx.plugins.script.runtime.JadxScriptInstance
     8 + 
     9 +class Rename(private val jadx: JadxScriptInstance) {
     10 + 
     11 + fun all(makeNewName: (String) -> String?) {
     12 + all { name, _ -> makeNewName.invoke(name) }
     13 + }
     14 + 
     15 + fun all(makeNewName: (String, IDexNode) -> String?) {
     16 + jadx.addPass(object : ScriptOrderedPreparePass(
     17 + jadx,
     18 + "RenameAll",
     19 + runBefore = listOf("RenameVisitor")
     20 + ) {
     21 + override fun init(root: RootNode) {
     22 + for (pkgNode in root.packages) {
     23 + rename(makeNewName, pkgNode, pkgNode.pkgInfo.name)
     24 + }
     25 + for (cls in root.classes) {
     26 + rename(makeNewName, cls, cls.name)
     27 + for (mth in cls.methods) {
     28 + if (!mth.isConstructor) {
     29 + rename(makeNewName, mth, mth.name)
     30 + }
     31 + }
     32 + for (fld in cls.fields) {
     33 + rename(makeNewName, fld, fld.name)
     34 + }
     35 + }
     36 + }
     37 + 
     38 + private inline fun <T : IDexNode> rename(
     39 + makeNewName: (String, IDexNode) -> String?,
     40 + node: T,
     41 + name: String
     42 + ) {
     43 + if (node is IAttributeNode && node.contains(AFlag.DONT_RENAME)) {
     44 + return
     45 + }
     46 + makeNewName.invoke(name, node)?.let {
     47 + node.rename(it)
     48 + }
     49 + }
     50 + })
     51 + }
     52 +}
     53 + 
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/replace.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Replace.kt
    Content is identical
  • jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/search.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Search.kt
    Content is identical
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/stages.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Stages.kt
    skipped 13 lines
    14 14   "StageRawInsns",
    15 15   runAfter = listOf("start")
    16 16   ) {
    17  - override fun visit(mth: MethodNode) {
    18  - mth.instructions?.let {
    19  - block.invoke(mth, it)
     17 + override fun visit(mth: MethodNode) {
     18 + mth.instructions?.let {
     19 + block.invoke(mth, it)
     20 + }
    20 21   }
    21  - }
    22  - })
     22 + })
    23 23   }
    24 24   
    25 25   fun mthEarlyBlocks(block: (MethodNode, List<BlockNode>) -> Unit) {
    skipped 9 lines
    35 35   "StageMthBlocks",
    36 36   runBefore = listOf(beforePass)
    37 37   ) {
    38  - override fun visit(mth: MethodNode) {
    39  - mth.basicBlocks?.let {
    40  - block.invoke(mth, it)
     38 + override fun visit(mth: MethodNode) {
     39 + mth.basicBlocks?.let {
     40 + block.invoke(mth, it)
     41 + }
    41 42   }
    42  - }
    43  - })
     43 + })
    44 44   }
    45 45   
    46 46   fun mthRegions(block: (MethodNode, Region) -> Unit) {
    skipped 2 lines
    49 49   "StageMthRegions",
    50 50   runBefore = listOf("PrepareForCodeGen")
    51 51   ) {
    52  - override fun visit(mth: MethodNode) {
    53  - mth.region?.let {
    54  - block.invoke(mth, it)
     52 + override fun visit(mth: MethodNode) {
     53 + mth.region?.let {
     54 + block.invoke(mth, it)
     55 + }
    55 56   }
    56  - }
    57  - })
     57 + })
    58 58   }
    59 59  }
    60 60   
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/wrappers.kt jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Wrappers.kt
    1 1  package jadx.plugins.script.runtime.data
    2 2   
    3  -import jadx.api.plugins.pass.types.JadxDecompilePass
    4 3  import jadx.api.plugins.pass.JadxPass
    5  -import jadx.api.plugins.pass.types.JadxPreparePass
    6 4  import jadx.api.plugins.pass.impl.OrderedJadxPassInfo
    7 5  import jadx.api.plugins.pass.impl.SimpleJadxPassInfo
     6 +import jadx.api.plugins.pass.types.JadxDecompilePass
     7 +import jadx.api.plugins.pass.types.JadxPreparePass
    8 8  import jadx.core.dex.nodes.ClassNode
    9 9  import jadx.core.dex.nodes.MethodNode
    10 10  import jadx.core.dex.nodes.RootNode
    11 11  import jadx.plugins.script.runtime.JadxScriptInstance
    12 12   
    13  -private fun buildScriptName(jadx: JadxScriptInstance, name: String) = "JadxScript${name}(${jadx.scriptName})"
     13 +private fun buildScriptName(jadx: JadxScriptInstance, name: String) = "JadxScript$name(${jadx.scriptName})"
    14 14   
    15 15  private fun buildSimplePassInfo(jadx: JadxScriptInstance, name: String) =
    16 16   SimpleJadxPassInfo(buildScriptName(jadx, name))
    17 17   
    18 18  abstract class ScriptPreparePass(
    19  - private val jadx: JadxScriptInstance, private val name: String
     19 + private val jadx: JadxScriptInstance,
     20 + private val name: String
    20 21  ) : JadxPreparePass {
    21 22   override fun getInfo() = buildSimplePassInfo(jadx, name)
    22 23  }
    23 24   
    24 25  abstract class ScriptDecompilePass(
    25  - private val jadx: JadxScriptInstance, private val name: String
     26 + private val jadx: JadxScriptInstance,
     27 + private val name: String
    26 28  ) : JadxDecompilePass {
    27 29   override fun getInfo() = buildSimplePassInfo(jadx, name)
    28 30   
    skipped 21 lines
    50 52  }
    51 53   
    52 54  abstract class ScriptOrderedPreparePass(
    53  - jadx: JadxScriptInstance, name: String, runAfter: List<String> = listOf(), runBefore: List<String> = listOf()
    54  -) : ScriptOrderedPass(jadx, name, runAfter, runBefore), JadxPreparePass {}
     55 + jadx: JadxScriptInstance,
     56 + name: String,
     57 + runAfter: List<String> = listOf(),
     58 + runBefore: List<String> = listOf()
     59 +) : ScriptOrderedPass(jadx, name, runAfter, runBefore), JadxPreparePass
    55 60   
    56 61  abstract class ScriptOrderedDecompilePass(
    57  - jadx: JadxScriptInstance, name: String, runAfter: List<String> = listOf(), runBefore: List<String> = listOf()
     62 + jadx: JadxScriptInstance,
     63 + name: String,
     64 + runAfter: List<String> = listOf(),
     65 + runBefore: List<String> = listOf()
    58 66  ) : ScriptOrderedPass(jadx, name, runAfter, runBefore), JadxDecompilePass {
    59 67   
    60 68   override fun init(root: RootNode) {
    skipped 10 lines
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/rename.kt
    1  -package jadx.plugins.script.runtime.data
    2  - 
    3  -import jadx.core.dex.attributes.AFlag
    4  -import jadx.core.dex.attributes.IAttributeNode
    5  -import jadx.core.dex.nodes.IDexNode
    6  -import jadx.core.dex.nodes.RootNode
    7  -import jadx.plugins.script.runtime.JadxScriptInstance
    8  - 
    9  -class RenamePass(private val jadx: JadxScriptInstance) {
    10  - 
    11  - fun all(makeNewName: (String) -> String?) {
    12  - all { name, _ -> makeNewName.invoke(name) }
    13  - }
    14  - 
    15  - fun all(makeNewName: (String, IDexNode) -> String?) {
    16  - jadx.addPass(object : ScriptOrderedPreparePass(
    17  - jadx,
    18  - "RenameAll",
    19  - runBefore = listOf("RenameVisitor")
    20  - ) {
    21  - override fun init(root: RootNode) {
    22  - for (pkgNode in root.packages) {
    23  - rename(makeNewName, pkgNode, pkgNode.pkgInfo.name)
    24  - }
    25  - for (cls in root.classes) {
    26  - rename(makeNewName, cls, cls.name)
    27  - for (mth in cls.methods) {
    28  - if (!mth.isConstructor) {
    29  - rename(makeNewName, mth, mth.name)
    30  - }
    31  - }
    32  - for (fld in cls.fields) {
    33  - rename(makeNewName, fld, fld.name)
    34  - }
    35  - }
    36  - }
    37  - 
    38  - private inline fun <T : IDexNode> rename(
    39  - makeNewName: (String, IDexNode) -> String?,
    40  - node: T,
    41  - name: String
    42  - ) {
    43  - if (node is IAttributeNode && node.contains(AFlag.DONT_RENAME)) {
    44  - return
    45  - }
    46  - makeNewName.invoke(name, node)?.let {
    47  - node.rename(it)
    48  - }
    49  - }
    50  - })
    51  - }
    52  -}
    53  - 
  • ■ ■ ■ ■ ■ ■
    jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/script.kt
    1  -package jadx.plugins.script.runtime
    2  - 
    3  -import kotlinx.coroutines.runBlocking
    4  -import kotlin.script.experimental.annotations.KotlinScript
    5  -import kotlin.script.experimental.api.*
    6  -import kotlin.script.experimental.dependencies.*
    7  -import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
    8  -import kotlin.script.experimental.jvm.JvmDependency
    9  -import kotlin.script.experimental.jvm.dependenciesFromCurrentContext
    10  -import kotlin.script.experimental.jvm.jvm
    11  - 
    12  -@KotlinScript(
    13  - fileExtension = "jadx.kts",
    14  - compilationConfiguration = JadxScriptConfiguration::class
    15  -)
    16  -abstract class JadxScript
    17  - 
    18  -object JadxScriptConfiguration : ScriptCompilationConfiguration({
    19  - defaultImports(DependsOn::class, Repository::class)
    20  - 
    21  - jvm {
    22  - dependenciesFromCurrentContext(
    23  - wholeClasspath = true
    24  - )
    25  - }
    26  - ide {
    27  - acceptedLocations(ScriptAcceptedLocation.Everywhere)
    28  - }
    29  - 
    30  - baseClass(JadxScriptBaseClass::class)
    31  - 
    32  - refineConfiguration {
    33  - onAnnotations(DependsOn::class, Repository::class, handler = ::configureMavenDepsOnAnnotations)
    34  - }
    35  -})
    36  - 
    37  -private val resolver = CompoundDependenciesResolver(FileSystemDependenciesResolver(), MavenDependenciesResolver())
    38  - 
    39  -fun configureMavenDepsOnAnnotations(context: ScriptConfigurationRefinementContext): ResultWithDiagnostics<ScriptCompilationConfiguration> {
    40  - val annotations = context.collectedData?.get(ScriptCollectedData.collectedAnnotations)
    41  - ?.takeIf { it.isNotEmpty() }
    42  - ?: return context.compilationConfiguration.asSuccess()
    43  - return runBlocking { resolver.resolveFromScriptSourceAnnotations(annotations) }
    44  - .onSuccess {
    45  - context.compilationConfiguration.with {
    46  - dependencies.append(JvmDependency(it))
    47  - }.asSuccess()
    48  - }
    49  -}
    50  - 
Please wait...
Page is in error, reload to recover