From 9410728ed116f1a40a13077a9b357146c2e8b99c Mon Sep 17 00:00:00 2001 From: Hamza417 <23103729+Hamza417@users.noreply.github.com> Date: Sat, 21 Dec 2024 23:30:18 +0530 Subject: [PATCH] Added tracker signature check in Dex Classes --- .../inure/adapters/viewers/AdapterDexData.kt | 78 +++------------- .../app/simple/inure/models/DexClass.java | 90 +++++++++++++++++++ .../app/simple/inure/ui/viewers/DexClasses.kt | 8 +- .../viewmodels/viewers/DexDataViewModel.kt | 41 ++++++--- app/src/main/res/layout/adapter_resources.xml | 2 + app/src/main/res/layout/fragment_dex_data.xml | 10 +++ 6 files changed, 149 insertions(+), 80 deletions(-) create mode 100644 app/src/main/java/app/simple/inure/models/DexClass.java diff --git a/app/src/main/java/app/simple/inure/adapters/viewers/AdapterDexData.kt b/app/src/main/java/app/simple/inure/adapters/viewers/AdapterDexData.kt index 9a75429c2..fd77a5259 100644 --- a/app/src/main/java/app/simple/inure/adapters/viewers/AdapterDexData.kt +++ b/app/src/main/java/app/simple/inure/adapters/viewers/AdapterDexData.kt @@ -8,84 +8,28 @@ import androidx.recyclerview.widget.RecyclerView import app.simple.inure.R import app.simple.inure.decorations.condensed.CondensedDynamicRippleTextView import app.simple.inure.decorations.overscroll.VerticalListViewHolder +import app.simple.inure.models.DexClass import app.simple.inure.util.AdapterUtils -class AdapterDexData(private val dexs: ArrayList, val keyword: String) : RecyclerView.Adapter() { +class AdapterDexData(private val dexs: ArrayList, val keyword: String) : RecyclerView.Adapter() { var onDetailsClicked: ((String) -> Unit)? = null override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { - return Holder(LayoutInflater.from(parent.context).inflate(R.layout.adapter_resources, parent, false)) + return Holder(LayoutInflater.from(parent.context) + .inflate(R.layout.adapter_resources, parent, false)) } override fun onBindViewHolder(holder: Holder, position: Int) { - holder.name.text = dexs[position] + holder.name.text = dexs[position].className + holder.name.setTrackingIcon(dexs[position].isTracker) AdapterUtils.searchHighlighter(holder.name, keyword, ignoreCasing = true) - // holder.packageName.text = dexs[position].packageName - // holder.superClass.text = dexs[position].superClass - // - // var status = "" - // - // status = if (dexs[position].isPublic) { - // StringBuilder() - // .append(status) - // .append(holder.itemView.context.getString(R.string.public_identifier)) - // .toString() - // } else { - // StringBuilder() - // .append(status) - // .append(holder.itemView.context.getString(R.string.private_identifier)) - // .toString() - // } - // - // if (dexs[position].isProtected) { - // status = StringBuilder() - // .append(status) - // .append(" | ") - // .append(holder.itemView.context.getString(R.string.protected_identifier)) - // .toString() - // } - // - // if (dexs[position].isStatic) { - // status = StringBuilder() - // .append(status) - // .append(" | ") - // .append(holder.itemView.context.getString(R.string.static_identifier)) - // .toString() - // } - // - // if (dexs[position].isAnnotation) { - // status = StringBuilder() - // .append(status) - // .append(" | ") - // .append(holder.itemView.context.getString(R.string.annotation_identifier)) - // .toString() - // } - // - // if (dexs[position].isInterface) { - // status = StringBuilder() - // .append(status) - // .append(" | ") - // .append(holder.itemView.context.getString(R.string.interface_identifier)) - // .toString() - // } - // - // if (dexs[position].isEnum) { - // status = StringBuilder() - // .append(status) - // .append(" | ") - // .append(holder.itemView.context.getString(R.string.enum_identifier)) - // .toString() - // } - // - // if (status.isEmpty()) { - // status = holder.itemView.context.getString(R.string.not_available) - // } - // - // holder.status.text = status + if (dexs[position].isTracker) { + AdapterUtils.searchHighlighter(holder.name, dexs[position].trackerSignature, ignoreCasing = true) + } holder.name.setOnClickListener { - onDetailsClicked?.invoke(dexs[position]) + onDetailsClicked?.invoke(dexs[position].className) } } @@ -94,7 +38,7 @@ class AdapterDexData(private val dexs: ArrayList, val keyword: String) : } @SuppressLint("NotifyDataSetChanged") - fun updateData(it: java.util.ArrayList?) { + fun updateData(it: java.util.ArrayList?) { dexs.clear() dexs.addAll(it!!) notifyDataSetChanged() diff --git a/app/src/main/java/app/simple/inure/models/DexClass.java b/app/src/main/java/app/simple/inure/models/DexClass.java new file mode 100644 index 000000000..9f116ec3d --- /dev/null +++ b/app/src/main/java/app/simple/inure/models/DexClass.java @@ -0,0 +1,90 @@ +package app.simple.inure.models; + +import android.os.Parcel; +import android.os.Parcelable; + +import androidx.annotation.NonNull; + +public class DexClass implements Parcelable { + + private String className; + private boolean isTracker; + private String trackerSignature; + + public DexClass(String className, boolean isTracker, String trackerSignature) { + this.className = className; + this.isTracker = isTracker; + this.trackerSignature = trackerSignature; + } + + public DexClass() { + } + + public DexClass(String className) { + this.className = className; + } + + protected DexClass(Parcel in) { + className = in.readString(); + isTracker = in.readByte() != 0; + trackerSignature = in.readString(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(className); + dest.writeByte((byte) (isTracker ? 1 : 0)); + dest.writeString(trackerSignature); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator () { + @Override + public DexClass createFromParcel(Parcel in) { + return new DexClass(in); + } + + @Override + public DexClass[] newArray(int size) { + return new DexClass[size]; + } + }; + + public String getClassName() { + return className; + } + + public void setClassName(String className) { + this.className = className; + } + + public boolean isTracker() { + return isTracker; + } + + public void setTracker(boolean tracker) { + isTracker = tracker; + } + + public String getTrackerSignature() { + return trackerSignature; + } + + public void setTrackerSignature(String trackerSignature) { + this.trackerSignature = trackerSignature; + } + + @NonNull + @Override + public String toString() { + return "DexClass{" + + "className='" + className + '\'' + + ", isTracker=" + isTracker + + ", trackerSignature='" + trackerSignature + '\'' + + '}'; + } +} diff --git a/app/src/main/java/app/simple/inure/ui/viewers/DexClasses.kt b/app/src/main/java/app/simple/inure/ui/viewers/DexClasses.kt index 825200796..9678ee653 100644 --- a/app/src/main/java/app/simple/inure/ui/viewers/DexClasses.kt +++ b/app/src/main/java/app/simple/inure/ui/viewers/DexClasses.kt @@ -3,7 +3,6 @@ package app.simple.inure.ui.viewers import android.content.SharedPreferences import android.content.pm.PackageInfo import android.os.Bundle -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -14,10 +13,12 @@ import app.simple.inure.adapters.viewers.AdapterDexData import app.simple.inure.constants.BundleConstants import app.simple.inure.constants.Warnings import app.simple.inure.decorations.overscroll.CustomVerticalRecyclerView +import app.simple.inure.decorations.views.CustomProgressBar import app.simple.inure.extensions.fragments.SearchBarScopedFragment import app.simple.inure.factories.panels.PackageInfoFactory import app.simple.inure.preferences.DexClassesPreferences import app.simple.inure.util.NullSafety.isNull +import app.simple.inure.util.ViewUtils.gone import app.simple.inure.viewmodels.viewers.DexDataViewModel class DexClasses : SearchBarScopedFragment() { @@ -25,6 +26,7 @@ class DexClasses : SearchBarScopedFragment() { private lateinit var dexDataViewModel: DexDataViewModel private lateinit var packageInfoFactory: PackageInfoFactory private lateinit var recyclerView: CustomVerticalRecyclerView + private lateinit var loader: CustomProgressBar override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater.inflate(R.layout.fragment_dex_data, container, false) @@ -33,6 +35,7 @@ class DexClasses : SearchBarScopedFragment() { searchBox = view.findViewById(R.id.search_edit_text) title = view.findViewById(R.id.dex_title) recyclerView = view.findViewById(R.id.dexs_recycler_view) + loader = view.findViewById(R.id.loader) packageInfoFactory = PackageInfoFactory(packageInfo) dexDataViewModel = ViewModelProvider(this, packageInfoFactory)[DexDataViewModel::class.java] @@ -52,6 +55,7 @@ class DexClasses : SearchBarScopedFragment() { } dexDataViewModel.getDexClasses().observe(viewLifecycleOwner) { + loader.gone(animate = true) setCount(it.size) if (recyclerView.adapter.isNull()) { @@ -68,9 +72,7 @@ class DexClasses : SearchBarScopedFragment() { } searchBox.doOnTextChanged { text, _, _, _ -> - Log.d("DexClasses", "onViewCreated: $text") if (searchBox.isFocused) { - Log.d("DexClasses", "Doin it") dexDataViewModel.filterClasses(text.toString().trim()) } } diff --git a/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt b/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt index d51ce5622..511adf4fa 100644 --- a/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt +++ b/app/src/main/java/app/simple/inure/viewmodels/viewers/DexDataViewModel.kt @@ -6,6 +6,8 @@ import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import app.simple.inure.extensions.viewmodels.WrappedViewModel +import app.simple.inure.models.DexClass +import app.simple.inure.util.TrackerUtils import dalvik.system.DexFile import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -14,20 +16,37 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag private val classes = ArrayList() - private val dexData: MutableLiveData> by lazy { - MutableLiveData>().also { + private val dexData: MutableLiveData> by lazy { + MutableLiveData>().also { loadDexData() } } - fun getDexClasses(): MutableLiveData> { + fun getDexClasses(): MutableLiveData> { return dexData } private fun loadDexData() { viewModelScope.launch(Dispatchers.Default) { kotlin.runCatching { - dexData.postValue(getClassesOfPackage(packageInfo.packageName)) + val classes: ArrayList = getClassesOfPackage(packageInfo.packageName) + val dexClasses = ArrayList() + val trackerSignatures = TrackerUtils.getTrackerSignatures() + val trackerSignaturesPattern = trackerSignatures.joinToString("|") { + Regex.escape(it.lowercase()) + }.toRegex() + + for (className in classes) { + val dexClass = DexClass(className) + val lowerCaseClassName = className.lowercase() + + dexClass.trackerSignature = trackerSignaturesPattern.find(lowerCaseClassName)?.value + dexClass.isTracker = dexClass.trackerSignature != null + + dexClasses.add(dexClass) + } + + dexData.postValue(dexClasses) }.getOrElse { postError(it) } @@ -52,15 +71,17 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag fun filterClasses(query: String) { viewModelScope.launch(Dispatchers.Default) { - val filteredClasses = ArrayList() + runCatching { + val filteredClasses = ArrayList() - for (className in classes) { - if (className.lowercase().contains(query.lowercase(), true)) { - filteredClasses.add(className) + for (dexClass in dexData.value!!) { + if (dexClass.className.lowercase().contains(query.lowercase(), true)) { + filteredClasses.add(dexClass) + } } - } - dexData.postValue(filteredClasses) + dexData.postValue(filteredClasses) + } } } } diff --git a/app/src/main/res/layout/adapter_resources.xml b/app/src/main/res/layout/adapter_resources.xml index 019566db2..f60728bbe 100644 --- a/app/src/main/res/layout/adapter_resources.xml +++ b/app/src/main/res/layout/adapter_resources.xml @@ -8,5 +8,7 @@ android:maxLines="1" android:padding="@dimen/header_padding" android:textSize="@dimen/info_text_medium" + android:drawablePadding="5dp" app:appFontStyle="bold" + app:drawableTintStyle="accent" app:textColorStyle="primary" /> diff --git a/app/src/main/res/layout/fragment_dex_data.xml b/app/src/main/res/layout/fragment_dex_data.xml index 67104f07e..98c0e7374 100644 --- a/app/src/main/res/layout/fragment_dex_data.xml +++ b/app/src/main/res/layout/fragment_dex_data.xml @@ -63,6 +63,16 @@ + +