Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private static boolean isEntryIdRemove(String entryId) {
String[] split = entryId.split("-");
String entryId2 = split[0];
if (!entryId2.equals("cursor") && !entryId2.equals("Guide") && !entryId2.startsWith("semantic_core")) {
if (entryId.contains("promoted") || ((entryId2.equals("conversationthread") && split.length == 3)) && hideAds) {
if (entryId.contains("promoted") || (entryId2.equals("conversationthread") && split.length == 3) && hideAds) {
return true;
}
if ((entryId2.equals("superhero") || entryId2.equals("eventsummary")) && hideAds) {
Expand Down Expand Up @@ -108,5 +108,12 @@ public static JsonSensitiveMediaWarning sensitiveMedia(JsonSensitiveMediaWarning
return jsonSensitiveMediaWarning;
}

public static boolean hidePromotedTrend(Object data) {
if (data != null && hideAds) {
return true;
}
return false;
}

//end
}
5 changes: 3 additions & 2 deletions patches/api/patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public final class app/crimera/utils/UtilsKt {
public static final fun getMethodName (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Ljava/lang/String;
public static final fun getReference (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Fingerprint;I)Lcom/android/tools/smali/dexlib2/iface/reference/Reference;
public static final fun instructionToString (Lcom/android/tools/smali/dexlib2/iface/instruction/Instruction;)Ljava/lang/String;
public static final fun replaceStringsInFile (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;Ljava/util/Map;)V
public static final fun replaceStringsInFile (Lapp/revanced/patcher/patch/ResourcePatchContext;[Lapp/revanced/util/ResourceGroup;Ljava/util/Map;)V
public static final fun replaceXmlResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;)V
}

Expand Down Expand Up @@ -445,7 +445,8 @@ public final class app/revanced/util/ResourceGroup {
public final class app/revanced/util/ResourceUtilsKt {
public static final fun asSequence (Lorg/w3c/dom/NodeList;)Lkotlin/sequences/Sequence;
public static final fun childElementsSequence (Lorg/w3c/dom/Node;)Lkotlin/sequences/Sequence;
public static final fun copyResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;)V
public static final fun copyResources (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;Z)V
public static synthetic fun copyResources$default (Lapp/revanced/patcher/patch/ResourcePatchContext;Ljava/lang/String;[Lapp/revanced/util/ResourceGroup;ZILjava/lang/Object;)V
public static final fun copyXmlNode (Ljava/lang/String;Lapp/revanced/patcher/util/Document;Lapp/revanced/patcher/util/Document;)Ljava/lang/AutoCloseable;
public static final fun doRecursively (Lorg/w3c/dom/Node;Lkotlin/jvm/functions/Function1;)V
public static final fun forEachChildElement (Lorg/w3c/dom/Node;Lkotlin/jvm/functions/Function1;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ val hideAds =
method.addInstructionsWithLabels(
return_loc,
"""
sget-boolean v$reg,${Constants.PATCHES_DESCRIPTOR}/TimelineEntry;->hideAds:Z
invoke-static {v$reg},${Constants.PATCHES_DESCRIPTOR}/TimelineEntry;->hidePromotedTrend(Ljava/lang/Object;)Z
move-result v$reg
if-eqz v$reg, :cond_1212
const v$return_reg, 0x0
""".trimIndent(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,30 @@ val bringBackTwitterPatch =

// region Change app icons

val mipmapIcons = arrayOf(
"ic_launcher_twitter.webp",
"ic_launcher_twitter_round.webp",
"ic_launcher_twitter_foreground.webp",
)

val drawableIcons = arrayOf(
"ic_vector_twitter.xml",
"ic_vector_home.xml",
"ic_vector_twitter_white.xml",
"ic_vector_home_stroke.xml",
"splash_screen_icon.xml",
)

val sizes = arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi",
)
val mipmapIcons =
arrayOf(
"ic_launcher_twitter.webp",
"ic_launcher_twitter_round.webp",
"ic_launcher_twitter_foreground.webp",
)

val drawableIcons =
arrayOf(
"ic_vector_twitter.xml",
"ic_vector_home.xml",
"ic_vector_twitter_white.xml",
"ic_vector_home_stroke.xml",
"splash_screen_icon.xml",
)

val sizes =
arrayOf(
"xxxhdpi",
"xxhdpi",
"xhdpi",
"hdpi",
"mdpi",
)

// drawable icons
sizes
Expand Down Expand Up @@ -122,14 +125,21 @@ val bringBackTwitterPatch =
"tr",
"zh-rCN",
"zh-rTW",
"",
).map { "values-$it" }

languages.forEach {
val vDirectory = get("res").resolve(it)
var folderName = it
if (folderName.endsWith("-"))
{
folderName = it.replace("-", "")
}
val vDirectory = get("res").resolve(folderName)
if (!vDirectory.isDirectory) {
Files.createDirectories(vDirectory.toPath())
}
replaceXmlResources(basePath, ResourceGroup(it, "strings.xml"))
val resGroup = ResourceGroup(folderName, "strings.xml")
replaceXmlResources(basePath, resGroup)

/*
* The Java XML API on Android has a bug that converts surrogate pair characters
Expand All @@ -139,12 +149,13 @@ val bringBackTwitterPatch =
*/
if (isRunningOnManager) {
replaceStringsInFile(
"res/$it/strings.xml",
mapOf(
"��" to "Twitter",
"��" to "🔥",
"��" to "🎁",
),
resGroup,
replacements =
mapOf(
"��" to "Twitter",
"��" to "🔥",
"��" to "🎁",
),
)
}
}
Expand All @@ -153,17 +164,19 @@ val bringBackTwitterPatch =
* Instead of defining strings in the map, replaces texts directly.
* Reason: https://t.me/pikopatches/1/17339
*/
setOf(
"res/values-ja/strings.xml",
"res/values-ja/arrays.xml"
).forEach {
replaceStringsInFile(
it,
mapOf(
"X" to "Twitter",
"ポスト" to "ツイート",
),
)
if (isRunningOnManager) {
setOf(
ResourceGroup("values-ja", "strings.xml", "arrays.xml"),
).forEach {
replaceStringsInFile(
it,
replacements =
mapOf(
"X" to "Twitter",
"ポスト" to "ツイート",
),
)
}
}

// endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ internal val settingsResourcePatch =
parent.appendChild(sideBtn)
}

copyResources("twitter/settings", ResourceGroup("values", "piko_strings.xml"))
copyResources("twitter/settings", ResourceGroup("values", "piko_arrays.xml"))
val basePath = "twitter/settings/strings"

copyResources(basePath, ResourceGroup("values", "strings.xml", "arrays.xml"), appendPiko = true)

/**
* create directory for the untranslated language resources
Expand Down Expand Up @@ -75,10 +76,10 @@ internal val settingsResourcePatch =
if (!vDirectory.isDirectory) {
Files.createDirectories(vDirectory.toPath())
if (it.contains("v21")) {
copyResources("twitter/settings", ResourceGroup(it, "piko_arrays.xml"))
copyResources(basePath, ResourceGroup(it, "arrays.xml"), appendPiko = true)
}
}
copyResources("twitter/settings", ResourceGroup(it, "piko_strings.xml"))
copyResources(basePath, ResourceGroup(it, "strings.xml"), appendPiko = true)
}

// execute end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,5 @@ val nativeReaderModePatch =
val functionReference = "/readerMode/ReaderModeUtils;->launchReaderMode"
val statusFunctionName = "nativeReaderMode"
shareMenuButtonInjection(actionName, prefFunctionName, stringId, iconId, functionReference, statusFunctionName)

// val actionName = "ReaderMode"
//
// val viewDebugDialogReference =
// (
// shareMenuButtonAddHook
// .method
// .implementation
// ?.instructions
// ?.last { it.opcode == Opcode.SGET_OBJECT } as Instruction21c
// ).reference
// // Add action
// val downloadActionReference = addAction(actionName)
//
// // Register button
// registerButton(actionName, "enableNativeReaderMode")
//
// // Set Button Text
// setButtonText(actionName, "piko_title_native_reader_mode")
// setButtonIcon(actionName, "ic_vector_book_stroke_on")
//
// // TODO: handle possible nulls
// val buttonFuncMethod =
// shareMenuButtonFuncCallFingerprint.method
// .implementation
// ?.instructions
// ?.toList()
// val deleteStatusLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "Delete Status" }?.index!!
// val OkLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "OK" }?.index!!
// val conversationalRepliesLoc =
// shareMenuButtonFuncCallFingerprint.stringMatches
// ?.first {
// it.string ==
// "conversational_replies_android_pinned_replies_creation_enabled"
// }?.index
//
// val timelineRef =
// (
// buttonFuncMethod
// ?.filterIndexed { i, ins ->
// i > conversationalRepliesLoc!! && ins.opcode == Opcode.IGET_OBJECT
// }?.first() as Instruction22c?
// ) ?: throw PatchException("Failed to find timelineRef")
// val timelineRefReg = (buttonFuncMethod?.get(deleteStatusLoc - 1) as Instruction35c).registerD
//
// val activityRefReg = (buttonFuncMethod[OkLoc - 3] as Instruction35c).registerD
//
// // Add Button function
// addButtonInstructions(
// downloadActionReference,
// """
// check-cast v$timelineRefReg, ${timelineRef.reference.extractDescriptors()[0]}
// iget-object v1, v$timelineRefReg, ${timelineRef.reference}
//
// invoke-static {v$activityRefReg, v1}, $NATIVE_DESCRIPTOR/readerMode/ReaderModeUtils;->launchReaderMode(Landroid/content/Context;Ljava/lang/Object;)V
// """.trimIndent(),
// viewDebugDialogReference,
// )
//
// settingsStatusLoadFingerprint.enableSettings("nativeReaderMode")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,5 @@ val nativeTranslatorModePatch =
val functionReference = "/translator/NativeTranslator;->translate"
val statusFunctionName = "nativeTranslator"
shareMenuButtonInjection(actionName, prefFunctionName, stringId, iconId, functionReference, statusFunctionName)
//
// val viewDebugDialogReference =
// (
// shareMenuButtonAddHook
// .method
// .implementation
// ?.instructions
// ?.last { it.opcode == Opcode.SGET_OBJECT } as Instruction21c
// ).reference
//
// // Add action
// val downloadActionReference = addAction(actionName)
//
// // Register button
// registerButton(actionName, "enableNativeTranslator")
//
// // Set Button Text
// setButtonText(actionName, "translate_tweet_show")
// setButtonIcon(actionName, "ic_vector_sparkle")
//
// // TODO: handle possible nulls
// val buttonFuncMethod =
// shareMenuButtonFuncCallFingerprint.method
// .implementation
// ?.instructions
// ?.toList()
// val deleteStatusLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "Delete Status" }?.index!!
// val OkLoc = shareMenuButtonFuncCallFingerprint.stringMatches?.first { it.string == "OK" }?.index!!
// val conversationalRepliesLoc =
// shareMenuButtonFuncCallFingerprint.stringMatches
// ?.first {
// it.string ==
// "conversational_replies_android_pinned_replies_creation_enabled"
// }?.index
//
// val timelineRef =
// (
// buttonFuncMethod
// ?.filterIndexed { i, ins ->
// i > conversationalRepliesLoc!! && ins.opcode == Opcode.IGET_OBJECT
// }?.first() as Instruction22c?
// ) ?: throw PatchException("Failed to find timelineRef")
// val timelineRefReg = (buttonFuncMethod?.get(deleteStatusLoc - 1) as Instruction35c).registerD
//
// val activityRefReg = (buttonFuncMethod[OkLoc - 3] as Instruction35c).registerD
//
// // Add Button function
// addButtonInstructions(
// downloadActionReference,
// """
// check-cast v$timelineRefReg, ${timelineRef.reference.extractDescriptors()[0]}
// iget-object v1, v$timelineRefReg, ${timelineRef.reference}
//
// invoke-static {v$activityRefReg, v1}, $NATIVE_DESCRIPTOR(Landroid/content/Context;Ljava/lang/Object;)V
// """.trimIndent(),
// viewDebugDialogReference,
// )
//
// settingsStatusLoadFingerprint.enableSettings("")
}
}
21 changes: 14 additions & 7 deletions patches/src/main/kotlin/app/crimera/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ fun ResourcePatchContext.replaceXmlResources(
}

fun ResourcePatchContext.replaceStringsInFile(
filePath: String,
vararg resourceGroups: ResourceGroup,
replacements: Map<String, String>,
) {
val file = get(filePath)
var content = file.readText()
resourceGroups.forEach { resourceGroup ->
resourceGroup.resources.forEach { resource ->
val sourcePath = "${resourceGroup.resourceDirectoryName}/$resource"
val sourceFile = get("res").resolve(sourcePath)
if (sourceFile.exists()) {
var content = sourceFile.readText()

replacements.forEach { (from, to) ->
content = content.replace(from, to)
}
replacements.forEach { (from, to) ->
content = content.replace(from, to)
}

file.writeText(content)
sourceFile.writeText(content)
}
}
}
}

context(BytecodePatchContext)
Expand Down
11 changes: 8 additions & 3 deletions patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,20 @@ fun Node.insertFirst(node: Node) {
fun ResourcePatchContext.copyResources(
sourceResourceDirectory: String,
vararg resources: ResourceGroup,
appendPiko: Boolean = false,
) {
val targetResourceDirectory = this["res", false]

for (resourceGroup in resources) {
resourceGroup.resources.forEach { resource ->
val resourceFile = "${resourceGroup.resourceDirectoryName}/$resource"

val resourcePath = "${resourceGroup.resourceDirectoryName}/$resource"
var targetPath = resourcePath
if (appendPiko) targetPath = "${resourceGroup.resourceDirectoryName}/piko_$resource"

Files.copy(
inputStreamFromBundledResource(sourceResourceDirectory, resourceFile)!!,
targetResourceDirectory.resolve(resourceFile).toPath(),
inputStreamFromBundledResource(sourceResourceDirectory, resourcePath)!!,
targetResourceDirectory.resolve(targetPath).toPath(),
StandardCopyOption.REPLACE_EXISTING,
)
}
Expand Down
Loading