chore: lint code

This commit is contained in:
inotia00
2024-06-07 21:44:22 +09:00
parent e374fa306b
commit ecd6fbdf5b
95 changed files with 804 additions and 405 deletions

View File

@ -35,7 +35,8 @@ abstract class BaseAutoCaptionsPatch(
}
SubtitleTrackFingerprint.resultOrThrow().let {
val targetMethod = it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1)
val targetMethod =
it.getWalkerMethod(context, it.scanResult.patternScanResult!!.startIndex + 1)
targetMethod.apply {
val targetIndex = indexOfFirstInstruction {

View File

@ -52,7 +52,7 @@ abstract class BaseGmsCoreSupportPatch(
) : BytecodePatch(
name = "GmsCore support",
description = "Allows patched Google apps to run without root and under a different package name " +
"by using GmsCore instead of Google Play Services.",
"by using GmsCore instead of Google Play Services.",
dependencies = setOf(
PackageNamePatch::class,
gmsCoreSupportResourcePatch::class,
@ -116,36 +116,43 @@ abstract class BaseGmsCoreSupportPatch(
.replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"")
}
private fun BytecodeContext.transformStringReferences(transform: (str: String) -> String?) = classes.forEach {
val mutableClass by lazy {
proxy(it).mutableClass
}
it.methods.forEach classLoop@{ methodDef ->
val implementation = methodDef.implementation ?: return@classLoop
val mutableMethod by lazy {
mutableClass.methods.first { method -> MethodUtil.methodSignaturesMatch(method, methodDef) }
private fun BytecodeContext.transformStringReferences(transform: (str: String) -> String?) =
classes.forEach {
val mutableClass by lazy {
proxy(it).mutableClass
}
implementation.instructions.forEachIndexed insnLoop@{ index, instruction ->
val string = ((instruction as? Instruction21c)?.reference as? StringReference)?.string
?: return@insnLoop
it.methods.forEach classLoop@{ methodDef ->
val implementation = methodDef.implementation ?: return@classLoop
// Apply transformation.
val transformedString = transform(string) ?: return@insnLoop
val mutableMethod by lazy {
mutableClass.methods.first { method ->
MethodUtil.methodSignaturesMatch(
method,
methodDef
)
}
}
mutableMethod.replaceInstruction(
index,
BuilderInstruction21c(
Opcode.CONST_STRING,
instruction.registerA,
ImmutableStringReference(transformedString),
),
)
implementation.instructions.forEachIndexed insnLoop@{ index, instruction ->
val string =
((instruction as? Instruction21c)?.reference as? StringReference)?.string
?: return@insnLoop
// Apply transformation.
val transformedString = transform(string) ?: return@insnLoop
mutableMethod.replaceInstruction(
index,
BuilderInstruction21c(
Opcode.CONST_STRING,
instruction.registerA,
ImmutableStringReference(transformedString),
),
)
}
}
}
}
// region Collection of transformations that are applied to all strings.
@ -180,14 +187,20 @@ abstract class BaseGmsCoreSupportPatch(
// gms also has a 'subscribedfeeds' authority, check for that one too
val subFeedsUriPrefix = "content://subscribedfeeds"
if (str.startsWith(subFeedsUriPrefix)) {
return str.replace(subFeedsUriPrefix, "content://$gmsCoreVendorGroupId.subscribedfeeds")
return str.replace(
subFeedsUriPrefix,
"content://$gmsCoreVendorGroupId.subscribedfeeds"
)
}
}
return null
}
private fun packageNameTransform(fromPackageName: String, toPackageName: String): (String) -> String? = { string ->
private fun packageNameTransform(
fromPackageName: String,
toPackageName: String
): (String) -> String? = { string ->
when (string) {
"$fromPackageName.SuggestionsProvider",
"$fromPackageName.fileprovider",

View File

@ -53,12 +53,18 @@ abstract class BaseGmsCoreSupportResourcePatch(
// Spoof package name and signature.
applicationNode.adoptChild("meta-data") {
setAttribute("android:name", "$gmsCoreVendorGroupId.android.gms.SPOOFED_PACKAGE_NAME")
setAttribute(
"android:name",
"$gmsCoreVendorGroupId.android.gms.SPOOFED_PACKAGE_NAME"
)
setAttribute("android:value", fromPackageName)
}
applicationNode.adoptChild("meta-data") {
setAttribute("android:name", "$gmsCoreVendorGroupId.android.gms.SPOOFED_PACKAGE_SIGNATURE")
setAttribute(
"android:name",
"$gmsCoreVendorGroupId.android.gms.SPOOFED_PACKAGE_SIGNATURE"
)
setAttribute("android:value", spoofedPackageSignature)
}

View File

@ -113,7 +113,8 @@ object LithoFilterPatch : BytecodePatch(
if ((instruction as? ReferenceInstruction)?.reference.toString() != pathBuilderMethodCall)
continue
val insertRegister = getInstruction<OneRegisterInstruction>(index + 1).registerA
val insertRegister =
getInstruction<OneRegisterInstruction>(index + 1).registerA
val insertIndex = index + 2
addInstructionsWithLabels(
@ -134,13 +135,16 @@ object LithoFilterPatch : BytecodePatch(
"""
}
val stringBuilderIndex = getTargetIndexWithFieldReferenceType("Ljava/lang/StringBuilder;")
val stringBuilderRegister = getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
val stringBuilderIndex =
getTargetIndexWithFieldReferenceType("Ljava/lang/StringBuilder;")
val stringBuilderRegister =
getInstruction<TwoRegisterInstruction>(stringBuilderIndex).registerA
val emptyStringIndex = getEmptyStringInstructionIndex()
val identifierIndex = getTargetIndexReversed(emptyStringIndex, Opcode.IPUT_OBJECT)
val identifierRegister = getInstruction<TwoRegisterInstruction>(identifierIndex).registerA
val identifierRegister =
getInstruction<TwoRegisterInstruction>(identifierIndex).registerA
val objectIndex = getTargetIndex(emptyStringIndex, Opcode.INVOKE_VIRTUAL)
val objectRegister = getInstruction<BuilderInstruction35c>(objectIndex).registerC

View File

@ -14,7 +14,7 @@ import kotlin.properties.Delegates
abstract class BaseMainActivityResolvePatch(
private val mainActivityOnCreateFingerprint: MethodFingerprint
): BytecodePatch(
) : BytecodePatch(
setOf(mainActivityOnCreateFingerprint)
) {
lateinit var mainActivityMutableClass: MutableClass
@ -41,10 +41,18 @@ abstract class BaseMainActivityResolvePatch(
}
fun injectConstructorMethodCall(classDescriptor: String, methodDescriptor: String) =
constructorMethod.injectMethodCall(classDescriptor, methodDescriptor, constructorMethodIndex)
constructorMethod.injectMethodCall(
classDescriptor,
methodDescriptor,
constructorMethodIndex
)
fun injectOnBackPressedMethodCall(classDescriptor: String, methodDescriptor: String) =
onBackPressedMethod.injectMethodCall(classDescriptor, methodDescriptor, onBackPressedMethodIndex)
onBackPressedMethod.injectMethodCall(
classDescriptor,
methodDescriptor,
onBackPressedMethodIndex
)
fun injectOnCreateMethodCall(classDescriptor: String, methodDescriptor: String) =
onCreateMethod.injectMethodCall(classDescriptor, methodDescriptor)

View File

@ -13,8 +13,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.Reference
@Deprecated("This patch is generally not required for the latest versions of YouTube and YouTube Music." +
"For YouTube Music, if user spoofs the app version to v4.27.53, mp4a codec is still used, this is the patch for some of these users.")
@Deprecated(
"This patch is generally not required for the latest versions of YouTube and YouTube Music." +
"For YouTube Music, if user spoofs the app version to v4.27.53, mp4a codec is still used, this is the patch for some of these users."
)
abstract class BaseOpusCodecsPatch(
private val descriptor: String
) : BytecodePatch(

View File

@ -20,10 +20,14 @@ object OverlayBackgroundUtils {
arrayOf("height", "width").forEach replacement@{ replacement ->
if (it !is Element) return@replacement
if (it.attributes.getNamedItem("android:id")?.nodeValue?.endsWith(identifier) == true) {
it.getAttributeNode("android:layout_$replacement")?.let { attribute ->
attribute.textContent = "0.0dip"
}
if (it.attributes.getNamedItem("android:id")?.nodeValue?.endsWith(
identifier
) == true
) {
it.getAttributeNode("android:layout_$replacement")
?.let { attribute ->
attribute.textContent = "0.0dip"
}
}
}
}

View File

@ -60,7 +60,8 @@ abstract class BaseSpoofUserAgentPatch(
// IndexOutOfBoundsException is not possible here,
// but no such occurrences are present in the app.
val referee = getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
val referee =
getInstruction(instructionIndex + 2).getReference<MethodReference>()?.toString()
// This can technically also match non-user agent string builder append methods,
// but no such occurrences are present in the app.

View File

@ -21,9 +21,10 @@ abstract class BaseTransformInstructionsPatch<T> : BytecodePatch(emptySet()) {
// Returns the patch indices as a Sequence, which will execute lazily.
fun findPatchIndices(classDef: ClassDef, method: Method): Sequence<T>? {
return method.implementation?.instructions?.asSequence()?.withIndex()?.mapNotNull { (index, instruction) ->
filterMap(classDef, method, instruction, index)
}
return method.implementation?.instructions?.asSequence()?.withIndex()
?.mapNotNull { (index, instruction) ->
filterMap(classDef, method, instruction, index)
}
}
override fun execute(context: BytecodeContext) {
@ -48,8 +49,9 @@ abstract class BaseTransformInstructionsPatch<T> : BytecodePatch(emptySet()) {
val mutableClass = context.proxy(classDef).mutableClass
methods.map(mutableClass::findMutableMethodOf).forEach methods@{ mutableMethod ->
val patchIndices = findPatchIndices(mutableClass, mutableMethod)?.toCollection(ArrayDeque())
?: return@methods
val patchIndices =
findPatchIndices(mutableClass, mutableMethod)?.toCollection(ArrayDeque())
?: return@methods
while (!patchIndices.isEmpty()) transform(mutableMethod, patchIndices.removeLast())
}

View File

@ -16,7 +16,10 @@ object TranslationsUtils {
this["res/$directory"].mkdir()
Files.copy(
inputStreamFromBundledResource("$sourceDirectory/translations", "$language/strings.xml")!!,
inputStreamFromBundledResource(
"$sourceDirectory/translations",
"$language/strings.xml"
)!!,
this["res"].resolve("$directory/strings.xml").toPath(),
StandardCopyOption.REPLACE_EXISTING
)