Skip to content

Commit

Permalink
Added tracker signature check in Dex Classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza417 committed Dec 21, 2024
1 parent 35a77ff commit 9410728
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, val keyword: String) : RecyclerView.Adapter<AdapterDexData.Holder>() {
class AdapterDexData(private val dexs: ArrayList<DexClass>, val keyword: String) : RecyclerView.Adapter<AdapterDexData.Holder>() {

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)
}
}

Expand All @@ -94,7 +38,7 @@ class AdapterDexData(private val dexs: ArrayList<String>, val keyword: String) :
}

@SuppressLint("NotifyDataSetChanged")
fun updateData(it: java.util.ArrayList<String>?) {
fun updateData(it: java.util.ArrayList<DexClass>?) {
dexs.clear()
dexs.addAll(it!!)
notifyDataSetChanged()
Expand Down
90 changes: 90 additions & 0 deletions app/src/main/java/app/simple/inure/models/DexClass.java
Original file line number Diff line number Diff line change
@@ -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 <DexClass> CREATOR = new Creator <DexClass>() {
@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 + '\'' +
'}';
}
}
8 changes: 5 additions & 3 deletions app/src/main/java/app/simple/inure/ui/viewers/DexClasses.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,17 +13,20 @@ 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() {

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)
Expand All @@ -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]
Expand All @@ -52,6 +55,7 @@ class DexClasses : SearchBarScopedFragment() {
}

dexDataViewModel.getDexClasses().observe(viewLifecycleOwner) {
loader.gone(animate = true)
setCount(it.size)

if (recyclerView.adapter.isNull()) {
Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,20 +16,37 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag

private val classes = ArrayList<String>()

private val dexData: MutableLiveData<ArrayList<String>> by lazy {
MutableLiveData<ArrayList<String>>().also {
private val dexData: MutableLiveData<ArrayList<DexClass>> by lazy {
MutableLiveData<ArrayList<DexClass>>().also {
loadDexData()
}
}

fun getDexClasses(): MutableLiveData<ArrayList<String>> {
fun getDexClasses(): MutableLiveData<ArrayList<DexClass>> {
return dexData
}

private fun loadDexData() {
viewModelScope.launch(Dispatchers.Default) {
kotlin.runCatching {
dexData.postValue(getClassesOfPackage(packageInfo.packageName))
val classes: ArrayList<String> = getClassesOfPackage(packageInfo.packageName)
val dexClasses = ArrayList<DexClass>()
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)
}
Expand All @@ -52,15 +71,17 @@ class DexDataViewModel(application: Application, private val packageInfo: Packag

fun filterClasses(query: String) {
viewModelScope.launch(Dispatchers.Default) {
val filteredClasses = ArrayList<String>()
runCatching {
val filteredClasses = ArrayList<DexClass>()

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)
}
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/layout/adapter_resources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
10 changes: 10 additions & 0 deletions app/src/main/res/layout/fragment_dex_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@

</LinearLayout>

<app.simple.inure.decorations.views.CustomProgressBar
android:id="@+id/loader"
style="?android:attr/progressBarStyleSmall"
android:layout_width="@dimen/panel_icon_size"
android:layout_height="@dimen/panel_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="5dp"
android:indeterminateTint="?attr/colorAppAccent"
android:padding="10dp" />

<app.simple.inure.decorations.ripple.DynamicRippleImageButton
android:id="@+id/search"
android:layout_width="@dimen/button_size"
Expand Down

0 comments on commit 9410728

Please sign in to comment.