mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-29 13:20:13 +02:00
refactor: get rid of all useless let blocks
This commit is contained in:
parent
31815ca9ea
commit
22267883b1
@ -64,11 +64,10 @@ class Patcher(
|
|||||||
androlib.decodeResourcesFull(extInputFile, outDir, resourceTable)
|
androlib.decodeResourcesFull(extInputFile, outDir, resourceTable)
|
||||||
|
|
||||||
// read additional metadata from the resource table
|
// read additional metadata from the resource table
|
||||||
packageMetadata.metaInfo.usesFramework = UsesFramework().let { usesFramework ->
|
packageMetadata.metaInfo.usesFramework = UsesFramework().also { framework ->
|
||||||
usesFramework.ids = resourceTable.listFramePackages().map { it.id }.sorted()
|
framework.ids = resourceTable.listFramePackages().map { it.id }.sorted()
|
||||||
|
|
||||||
usesFramework
|
|
||||||
}
|
}
|
||||||
|
|
||||||
packageMetadata.metaInfo.doNotCompress = buildList {
|
packageMetadata.metaInfo.doNotCompress = buildList {
|
||||||
androlib.recordUncompressedFiles(extInputFile, this)
|
androlib.recordUncompressedFiles(extInputFile, this)
|
||||||
}
|
}
|
||||||
@ -97,12 +96,9 @@ class Patcher(
|
|||||||
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
|
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
|
||||||
|
|
||||||
// read dex files
|
// read dex files
|
||||||
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null).let { dexFile ->
|
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
|
||||||
// get the opcodes
|
// get the opcodes
|
||||||
opcodes = dexFile.opcodes
|
opcodes = dexFile.opcodes
|
||||||
|
|
||||||
dexFile
|
|
||||||
}
|
|
||||||
|
|
||||||
// finally create patcher data
|
// finally create patcher data
|
||||||
data = PatcherData(
|
data = PatcherData(
|
||||||
@ -120,22 +116,19 @@ class Patcher(
|
|||||||
files: List<File>, allowedOverwrites: Iterable<String> = emptyList(), throwOnDuplicates: Boolean = false
|
files: List<File>, allowedOverwrites: Iterable<String> = emptyList(), throwOnDuplicates: Boolean = false
|
||||||
) {
|
) {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
MultiDexIO.readDexFile(true, file, NAMER, null, null).let { dexFile ->
|
for (classDef in MultiDexIO.readDexFile(true, file, NAMER, null, null).classes) {
|
||||||
for (classDef in dexFile.classes) {
|
val e = data.bytecodeData.classes.internalClasses.findIndexed { it.type == classDef.type }
|
||||||
val e =
|
if (e != null) {
|
||||||
data.bytecodeData.classes.internalClasses.findIndexed { internalClass -> internalClass.type == classDef.type }
|
if (throwOnDuplicates) {
|
||||||
if (e != null) {
|
throw Exception("Class ${classDef.type} has already been added to the patcher.")
|
||||||
if (throwOnDuplicates) {
|
|
||||||
throw Exception("Class ${classDef.type} has already been added to the patcher.")
|
|
||||||
}
|
|
||||||
val (_, idx) = e
|
|
||||||
if (allowedOverwrites.contains(classDef.type)) {
|
|
||||||
data.bytecodeData.classes.internalClasses[idx] = classDef
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
data.bytecodeData.classes.internalClasses.add(classDef)
|
val (_, idx) = e
|
||||||
|
if (allowedOverwrites.contains(classDef.type)) {
|
||||||
|
data.bytecodeData.classes.internalClasses[idx] = classDef
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
data.bytecodeData.classes.internalClasses.add(classDef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,44 +143,41 @@ class Patcher(
|
|||||||
if (options.patchResources) {
|
if (options.patchResources) {
|
||||||
val cacheDirectory = ExtFile(options.resourceCacheDirectory)
|
val cacheDirectory = ExtFile(options.resourceCacheDirectory)
|
||||||
|
|
||||||
val androlibResources = AndrolibResources().let { resources ->
|
val androlibResources = AndrolibResources().also { resources ->
|
||||||
resources.buildOptions = BuildOptions().let { options ->
|
resources.buildOptions = BuildOptions().also { options ->
|
||||||
// TODO: options.useAapt2 = true
|
// TODO: options.useAapt2 = true
|
||||||
// TODO: options.aaptPath = ""
|
// TODO: options.aaptPath = ""
|
||||||
options.isFramework = metaInfo.isFrameworkApk
|
options.isFramework = metaInfo.isFrameworkApk
|
||||||
options.resourcesAreCompressed = metaInfo.compressionType
|
options.resourcesAreCompressed = metaInfo.compressionType
|
||||||
options.doNotCompress = metaInfo.doNotCompress
|
options.doNotCompress = metaInfo.doNotCompress
|
||||||
|
|
||||||
options
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resources.setSdkInfo(metaInfo.sdkInfo)
|
resources.setSdkInfo(metaInfo.sdkInfo)
|
||||||
resources.setVersionInfo(metaInfo.versionInfo)
|
resources.setVersionInfo(metaInfo.versionInfo)
|
||||||
resources.setSharedLibrary(metaInfo.sharedLibrary)
|
resources.setSharedLibrary(metaInfo.sharedLibrary)
|
||||||
resources.setSparseResources(metaInfo.sparseResources)
|
resources.setSparseResources(metaInfo.sparseResources)
|
||||||
|
|
||||||
resources
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val manifestFile = cacheDirectory.resolve("AndroidManifest.xml")
|
val manifestFile = cacheDirectory.resolve("AndroidManifest.xml")
|
||||||
|
|
||||||
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifestFile)
|
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifestFile)
|
||||||
|
|
||||||
cacheDirectory.resolve("aapt_temp_file").let { temporalFile ->
|
with(cacheDirectory.resolve("aapt_temp_file")) {
|
||||||
val resDirectory = cacheDirectory.resolve("res")
|
val resDirectory = cacheDirectory.resolve("res")
|
||||||
val includedFiles =
|
val includedFiles = metaInfo.usesFramework.ids.map { id ->
|
||||||
metaInfo.usesFramework.ids.map { id -> androlibResources.getFrameworkApk(id, metaInfo.usesFramework.tag) }
|
androlibResources.getFrameworkApk(
|
||||||
.toTypedArray()
|
id,
|
||||||
|
metaInfo.usesFramework.tag
|
||||||
|
)
|
||||||
|
}.toTypedArray()
|
||||||
|
|
||||||
androlibResources.aaptPackage(
|
androlibResources.aaptPackage(
|
||||||
temporalFile, manifestFile, resDirectory, null,
|
this, manifestFile, resDirectory, null,
|
||||||
null, includedFiles
|
null, includedFiles
|
||||||
)
|
)
|
||||||
|
|
||||||
// write packaged resources to cache directory
|
// write packaged resources to cache directory
|
||||||
// TODO: consider returning a list of the files instead of extracting them to the cache directory,
|
ExtFile(this).directory.copyToDir(cacheDirectory.resolve("build/"))
|
||||||
// less disk but more ram usage
|
|
||||||
ExtFile(temporalFile).directory.copyToDir(cacheDirectory.resolve("build/"))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,19 +76,17 @@ internal class MethodSignatureResolver(
|
|||||||
signature.strings?.let { strings ->
|
signature.strings?.let { strings ->
|
||||||
method.implementation ?: return null
|
method.implementation ?: return null
|
||||||
|
|
||||||
method.implementation!!.instructions.let { instructions ->
|
val stringsList = strings.toMutableList()
|
||||||
val stringsList = strings.toMutableList()
|
|
||||||
|
|
||||||
for (instruction in instructions) {
|
for (instruction in method.implementation!!.instructions) {
|
||||||
if (instruction.opcode != Opcode.CONST_STRING) continue
|
if (instruction.opcode != Opcode.CONST_STRING) continue
|
||||||
|
|
||||||
val string = ((instruction as Instruction21c).reference as StringReference).string
|
val string = ((instruction as Instruction21c).reference as StringReference).string
|
||||||
val i = stringsList.indexOfFirst { it == string }
|
val i = stringsList.indexOfFirst { it == string }
|
||||||
if (i != -1) stringsList.removeAt(i)
|
if (i != -1) stringsList.removeAt(i)
|
||||||
}
|
|
||||||
|
|
||||||
if (stringsList.isNotEmpty()) return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (stringsList.isNotEmpty()) return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (signature.opcodes == null) {
|
return if (signature.opcodes == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user