feat: make resource mapping patch aware of types (#77)
This commit is contained in:
parent
7519895348
commit
188491a707
|
@ -62,8 +62,8 @@ class GeneralBytecodeAdsPatch : BytecodePatch(
|
||||||
"endscreen_element_layout_icon",
|
"endscreen_element_layout_icon",
|
||||||
"promoted_video_item_land",
|
"promoted_video_item_land",
|
||||||
"promoted_video_item_full_bleed",
|
"promoted_video_item_full_bleed",
|
||||||
).map {
|
).map { name ->
|
||||||
ResourceIdMappingProviderResourcePatch.resourceMappings[it]!!
|
ResourceIdMappingProviderResourcePatch.resourceMappings.first { it.name == name }.id
|
||||||
}
|
}
|
||||||
|
|
||||||
private val stringReferences = arrayOf(
|
private val stringReferences = arrayOf(
|
||||||
|
|
|
@ -38,11 +38,11 @@ class CreateButtonRemoverPatch : BytecodePatch(
|
||||||
// Get the required register which holds the view object we need to pass to the method hideCreateButton
|
// Get the required register which holds the view object we need to pass to the method hideCreateButton
|
||||||
val implementation = result.mutableMethod.implementation!!
|
val implementation = result.mutableMethod.implementation!!
|
||||||
|
|
||||||
val imageOnlyLayout = ResourceIdMappingProviderResourcePatch.resourceMappings["image_only_tab"]
|
val imageOnlyLayout =
|
||||||
?: return PatchResultError("Required resource could not be found in the map")
|
ResourceIdMappingProviderResourcePatch.resourceMappings.first { it.type == "layout" && it.name == "image_only_tab" }
|
||||||
|
|
||||||
val imageOnlyLayoutConstIndex =
|
val imageOnlyLayoutConstIndex =
|
||||||
implementation.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == imageOnlyLayout }
|
implementation.instructions.indexOfFirst { (it as? WideLiteralInstruction)?.wideLiteral == imageOnlyLayout.id }
|
||||||
|
|
||||||
val (instructionIndex, instruction) = implementation.instructions.drop(imageOnlyLayoutConstIndex).withIndex()
|
val (instructionIndex, instruction) = implementation.instructions.drop(imageOnlyLayoutConstIndex).withIndex()
|
||||||
.first {
|
.first {
|
||||||
|
@ -63,4 +63,4 @@ class CreateButtonRemoverPatch : BytecodePatch(
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,26 @@ import org.w3c.dom.Element
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class ResourceIdMappingProviderResourcePatch : ResourcePatch() {
|
class ResourceIdMappingProviderResourcePatch : ResourcePatch() {
|
||||||
companion object {
|
companion object {
|
||||||
internal lateinit var resourceMappings: Map<String, Long>
|
internal lateinit var resourceMappings: List<ResourceElement>
|
||||||
private set
|
private set
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun execute(data: ResourceData): PatchResult {
|
override fun execute(data: ResourceData): PatchResult {
|
||||||
data.xmlEditor["res/values/public.xml"].use { editor ->
|
data.xmlEditor["res/values/public.xml"].use { editor ->
|
||||||
resourceMappings = buildMap {
|
resourceMappings = buildList {
|
||||||
editor.file.documentElement.doRecursively { node ->
|
editor.file.documentElement.doRecursively { node ->
|
||||||
if (node !is Element) return@doRecursively
|
if (node !is Element) return@doRecursively
|
||||||
val nameAttribute = node.getAttribute("name")
|
val nameAttribute = node.getAttribute("name")
|
||||||
|
val typeAttribute = node.getAttribute("type")
|
||||||
if (node.nodeName != "public" || nameAttribute.startsWith("APKTOOL")) return@doRecursively
|
if (node.nodeName != "public" || nameAttribute.startsWith("APKTOOL")) return@doRecursively
|
||||||
this[nameAttribute] = node.getAttribute("id").substring(2).toLong(16)
|
val id = node.getAttribute("id").substring(2).toLong(16)
|
||||||
|
add(ResourceElement(typeAttribute, nameAttribute, id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ResourceElement(val type: String, val name: String, val id: Long)
|
||||||
|
|
Loading…
Reference in a new issue