-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: annotate JadxPlugin with NotNull Allows for better Kotlin support * feat: add support for custom resources loader * feat: add support for xapk resources loading * fix: rename "decode" to "load" * refactor: annotate JadxCodeInput with NotNull * feat: add support for xapk code loading * feat: add xapk support to file filter * fix code formatting * revert NotNull annotation * several improvements * refactor: fix typo --------- Co-authored-by: Skylot <skylot@gmail.com>
- Loading branch information
Showing
16 changed files
with
223 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
jadx-core/src/main/java/jadx/api/plugins/CustomResourcesLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package jadx.api.plugins; | ||
|
||
import java.io.Closeable; | ||
import java.io.File; | ||
import java.util.List; | ||
|
||
import jadx.api.ResourceFile; | ||
import jadx.api.ResourcesLoader; | ||
|
||
public interface CustomResourcesLoader extends Closeable { | ||
/** | ||
* Load resources from file to list of ResourceFile | ||
* | ||
* @param list list to add loaded resources | ||
* @param file file to load | ||
* @return true if file was loaded | ||
*/ | ||
boolean load(ResourcesLoader loader, List<ResourceFile> list, File file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
plugins { | ||
id("jadx-library") | ||
id("jadx-kotlin") | ||
} | ||
|
||
dependencies { | ||
api(project(":jadx-core")) | ||
|
||
implementation(project(":jadx-plugins:jadx-dex-input")) | ||
implementation("com.google.code.gson:gson:2.10.1") | ||
} |
39 changes: 39 additions & 0 deletions
39
jadx-plugins/jadx-xapk-input/src/main/java/jadx/plugins/input/xapk/XapkCustomCodeInput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package jadx.plugins.input.xapk | ||
|
||
import jadx.api.plugins.input.ICodeLoader | ||
import jadx.api.plugins.input.JadxCodeInput | ||
import jadx.api.plugins.utils.CommonFileUtils | ||
import jadx.api.plugins.utils.ZipSecurity | ||
import java.io.File | ||
import java.nio.file.Path | ||
import java.util.zip.ZipFile | ||
|
||
class XapkCustomCodeInput( | ||
private val plugin: XapkInputPlugin, | ||
) : JadxCodeInput { | ||
override fun loadFiles(input: List<Path>): ICodeLoader { | ||
val apkFiles = mutableListOf<File>() | ||
for (file in input.map { it.toFile() }) { | ||
val manifest = XapkUtils.getManifest(file) ?: continue | ||
if (!XapkUtils.isSupported(manifest)) continue | ||
|
||
ZipFile(file).use { zip -> | ||
for (splitApk in manifest.splitApks) { | ||
val splitApkEntry = zip.getEntry(splitApk.file) | ||
if (splitApkEntry != null) { | ||
val tmpFile = ZipSecurity.getInputStreamForEntry(zip, splitApkEntry).use { | ||
CommonFileUtils.saveToTempFile(it, ".apk").toFile() | ||
} | ||
apkFiles.add(tmpFile) | ||
} | ||
} | ||
} | ||
} | ||
|
||
val codeLoader = plugin.dexInputPlugin.loadFiles(apkFiles.map { it.toPath() }) | ||
|
||
apkFiles.forEach { CommonFileUtils.safeDeleteFile(it) } | ||
|
||
return codeLoader | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...lugins/jadx-xapk-input/src/main/java/jadx/plugins/input/xapk/XapkCustomResourcesLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package jadx.plugins.input.xapk | ||
|
||
import jadx.api.ResourceFile | ||
import jadx.api.ResourcesLoader | ||
import jadx.api.plugins.CustomResourcesLoader | ||
import jadx.api.plugins.utils.CommonFileUtils | ||
import jadx.api.plugins.utils.ZipSecurity | ||
import java.io.File | ||
|
||
class XapkCustomResourcesLoader : CustomResourcesLoader { | ||
private val tmpFiles = mutableListOf<File>() | ||
|
||
override fun load(loader: ResourcesLoader, list: MutableList<ResourceFile>, file: File): Boolean { | ||
val manifest = XapkUtils.getManifest(file) ?: return false | ||
if (!XapkUtils.isSupported(manifest)) return false | ||
|
||
val apkEntries = manifest.splitApks.map { it.file }.toHashSet() | ||
ZipSecurity.visitZipEntries(file) { zip, entry -> | ||
if (apkEntries.contains(entry.name)) { | ||
val tmpFile = ZipSecurity.getInputStreamForEntry(zip, entry).use { | ||
CommonFileUtils.saveToTempFile(it, ".apk").toFile() | ||
} | ||
loader.defaultLoadFile(list, tmpFile, entry.name + "/") | ||
tmpFiles += tmpFile | ||
} else { | ||
loader.addEntry(list, file, entry, "") | ||
} | ||
null | ||
} | ||
return true | ||
} | ||
|
||
override fun close() { | ||
tmpFiles.forEach(CommonFileUtils::safeDeleteFile) | ||
tmpFiles.clear() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
jadx-plugins/jadx-xapk-input/src/main/java/jadx/plugins/input/xapk/XapkInputPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jadx.plugins.input.xapk | ||
|
||
import jadx.api.plugins.JadxPlugin | ||
import jadx.api.plugins.JadxPluginContext | ||
import jadx.api.plugins.JadxPluginInfo | ||
import jadx.plugins.input.dex.DexInputPlugin | ||
|
||
class XapkInputPlugin : JadxPlugin { | ||
private val codeInput = XapkCustomCodeInput(this) | ||
private val resourcesLoader = XapkCustomResourcesLoader() | ||
internal var dexInputPlugin = DexInputPlugin() | ||
|
||
override fun getPluginInfo() = JadxPluginInfo( | ||
"xapk-input", | ||
"XAPK Input", | ||
"Load .xapk files", | ||
) | ||
|
||
override fun init(context: JadxPluginContext) { | ||
context.addCodeInput(codeInput) | ||
context.decompiler.addCustomResourcesLoader(resourcesLoader) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
jadx-plugins/jadx-xapk-input/src/main/java/jadx/plugins/input/xapk/XapkManifest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package jadx.plugins.input.xapk | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class XapkManifest( | ||
@SerializedName("xapk_version") | ||
val xapkVersion: Int, | ||
@SerializedName("split_apks") | ||
val splitApks: List<SplitApk>, | ||
) { | ||
data class SplitApk( | ||
@SerializedName("file") | ||
val file: String, | ||
@SerializedName("id") | ||
val id: String, | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
jadx-plugins/jadx-xapk-input/src/main/java/jadx/plugins/input/xapk/XapkUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package jadx.plugins.input.xapk | ||
|
||
import com.google.gson.Gson | ||
import jadx.api.plugins.utils.ZipSecurity | ||
import jadx.core.utils.files.FileUtils | ||
import java.io.File | ||
import java.io.InputStreamReader | ||
import java.util.zip.ZipFile | ||
|
||
object XapkUtils { | ||
fun getManifest(file: File): XapkManifest? { | ||
if (!FileUtils.isZipFile(file)) return null | ||
try { | ||
ZipFile(file).use { zip -> | ||
val manifestEntry = zip.getEntry("manifest.json") ?: return null | ||
return InputStreamReader(ZipSecurity.getInputStreamForEntry(zip, manifestEntry)).use { | ||
Gson().fromJson(it, XapkManifest::class.java) | ||
} | ||
} | ||
} catch (e: Exception) { | ||
return null | ||
} | ||
} | ||
|
||
fun isSupported(manifest: XapkManifest): Boolean { | ||
return manifest.xapkVersion == 2 && manifest.splitApks.isNotEmpty() | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...-plugins/jadx-xapk-input/src/main/resources/META-INF/services/jadx.api.plugins.JadxPlugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
jadx.plugins.input.xapk.XapkInputPlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters