Skip to content

Commit

Permalink
Merge pull request #6 from Strange-IPmart/master
Browse files Browse the repository at this point in the history
Bug Fix
  • Loading branch information
Strange-IPmart authored May 14, 2024
2 parents 9cb9bda + 2cfe269 commit 5da0204
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.util.Arrays;
import java.util.HashSet;
import java.util.stream.Collectors;

import rikka.core.util.IOUtils;

Expand Down Expand Up @@ -151,7 +152,8 @@ private void importConfigs(Context context) {
if (value instanceof String stringValue) {
if (stringValue.startsWith("[") && stringValue.endsWith("]")) {
if (stringValue.length() > 2) {
prefs.edit().putStringSet(keyName, new HashSet<>(Arrays.asList(stringValue.substring(1, stringValue.length() - 1).split(",")))).apply();
var arr = Arrays.stream(stringValue.substring(1, stringValue.length() - 1).split(",")).map(String::trim).collect(Collectors.toList());
prefs.edit().putStringSet(keyName, new HashSet<>(arr)).apply();
}
} else {
prefs.edit().putString(keyName, value.toString()).apply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ public static void replaceColor(Drawable drawable, HashMap<String, String> color
var color = getNinePatchDrawableColor(ninePatchDrawable);
var sColor = IColors.toString(color);
var newColor = colors.get(sColor);
if (newColor != null && newColor.contains("121212")){
XposedBridge.log(new Throwable());
}
if (newColor != null) {
ninePatchDrawable.setTintList(ColorStateList.valueOf(parseColor(newColor)));
}
Expand All @@ -88,9 +85,6 @@ public static void replaceColor(Drawable drawable, HashMap<String, String> color
var color = getColor(drawable);
var sColor = IColors.toString(color);
var newColor = colors.get(sColor);
if (newColor != null && newColor.contains("121212")){
XposedBridge.log(new Throwable());
}
if (newColor != null) {
drawable.setColorFilter(new PorterDuffColorFilter(parseColor(newColor), PorterDuff.Mode.SRC_IN));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ private void init(Context context) {
}
}

@Override
public void addView(View child) {
super.addView(child);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ public static boolean isCalledFromString(String contains) {
return text.contains(contains);
}

public static boolean isCalledFromStrings(String... contains) {
var trace = Thread.currentThread().getStackTrace();
var text = Arrays.toString(trace);
for (String s : contains) {
if (text.contains(s)) return true;
}
return false;
}


// TODO: Classes and Methods for FreezeSeen
public static Method loadFreezeSeenMethod(ClassLoader classLoader) throws Exception {
Expand Down Expand Up @@ -196,6 +205,17 @@ public static Method loadReceiptMethod2(ClassLoader classLoader) throws Exceptio
});
}

public static Method loadReceiptMethod3(ClassLoader classLoader) throws Exception {
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> {
var method = loadReceiptMethod(classLoader);
var classList = dexkit.findClass(new FindClass().matcher(new ClassMatcher().addUsingString("callCreatorJid")));
if (classList.isEmpty()) throw new Exception("Receipt method not found");
var methodDataList = dexkit.findMethod(new FindMethod().searchInClass(classList).matcher(new MethodMatcher().addInvoke(DexSignUtil.getMethodDescriptor(method))));
if (methodDataList.isEmpty()) throw new Exception("Receipt method not found");
return methodDataList.get(0).getMethodInstance(classLoader);
});
}

// TODO: Classes and Methods for HideForward

public static Method loadForwardTagMethod(ClassLoader classLoader) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.wmods.wppenhacer.xposed.features.customization;

import static com.wmods.wppenhacer.utils.ColorReplacement.replaceColors;
import static com.wmods.wppenhacer.utils.DrawableColors.replaceColor;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

import android.Manifest;
Expand All @@ -15,6 +17,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
Expand All @@ -23,15 +26,22 @@
import androidx.core.content.ContextCompat;

import com.wmods.wppenhacer.utils.IColors;
import com.wmods.wppenhacer.views.WallpaperView;
import com.wmods.wppenhacer.xposed.core.DesignUtils;
import com.wmods.wppenhacer.xposed.core.Feature;
import com.wmods.wppenhacer.xposed.core.Unobfuscator;
import com.wmods.wppenhacer.xposed.features.general.ShowEditMessage;

import org.xmlpull.v1.XmlPullParser;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class CustomTheme extends Feature {
Expand Down Expand Up @@ -127,16 +137,16 @@ private void hookColors() throws Exception {
}
isWallpaper = prefs.getBoolean("wallpaper", false);

// findAndHookMethod(Activity.class.getName(), loader, "onCreate", Bundle.class, new XC_MethodHook() {
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// super.afterHookedMethod(param);
// var colors = getAlpha();
// var activity = (Activity) param.thisObject;
// var view = activity.findViewById(android.R.id.content).getRootView();
// replaceColors(view,colors);
// }
// });
findAndHookMethod(Activity.class.getName(), loader, "onCreate", Bundle.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
var colors = getAlpha();
var activity = (Activity) param.thisObject;
var view = activity.findViewById(android.R.id.content).getRootView();
replaceColors(view, colors);
}
});

var intBgHook = new IntBgColorHook();
findAndHookMethod(Paint.class.getName(), loader, "setColor", int.class, intBgHook);
Expand All @@ -159,11 +169,11 @@ private void hookColors() throws Exception {

findAndHookMethod(customDrawable3, "setTintList", ColorStateList.class, colorStateListHook);

// var inflaterHook = (XC_MethodHook) new LayoutInflaterHook();
// findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", int.class, ViewGroup.class, inflaterHook);
// findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", XmlPullParser.class, ViewGroup.class, inflaterHook);
// findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", int.class, ViewGroup.class, boolean.class, inflaterHook);
// findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", XmlPullParser.class, ViewGroup.class, boolean.class, inflaterHook);
var inflaterHook = (XC_MethodHook) new LayoutInflaterHook();
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", int.class, ViewGroup.class, inflaterHook);
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", XmlPullParser.class, ViewGroup.class, inflaterHook);
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", int.class, ViewGroup.class, boolean.class, inflaterHook);
findAndHookMethod(LayoutInflater.class.getName(), loader, "inflate", XmlPullParser.class, ViewGroup.class, boolean.class, inflaterHook);

// findAndHookMethod(View.class.getName(), loader, "setBackground", Drawable.class, new XC_MethodHook() {
// @Override
Expand All @@ -179,25 +189,28 @@ private HashMap<String, String> getAlpha() {
if (!isWallpaper) return IColors.colors;
// if (!Unobfuscator.isCalledFromString("HomeActivity.onCreate")) return IColors.colors;
if (Unobfuscator.isCalledFromClass(Window.class)) return IColors.colors;
if (Unobfuscator.isCalledFromString("setStatusBarColor")) return IColors.colors;
if (Unobfuscator.isCalledFromString("WDSToolbar")) return IColors.colors;
if (Unobfuscator.isCalledFromString("WDSFab")) return IColors.colors;
if (Unobfuscator.isCalledFromString("onPreparePanel")) return IColors.colors;
if (Unobfuscator.isCalledFromString("onCreateOptionsMenu")) return IColors.colors;
if (Unobfuscator.isCalledFromString("onLongClick")) return IColors.colors;
if (Unobfuscator.isCalledFromStrings(
"setStatusBarColor", "WDSToolbar", "WDSFab", "onPreparePanel"
, "onCreateOptionsMenu", "onLongClick", "PhoneWindow", "Image"))
return IColors.colors;
if (Unobfuscator.isCalledFromClass(ShowEditMessage.class)) return IColors.colors;
if (Unobfuscator.isCalledFromClass(DesignUtils.class)) return IColors.colors;
return newColors;
}

private void injectWallpaper(View view) {
var content = (ViewGroup) view;
var context = content.getContext();
try {
Bitmap bitmap = BitmapFactory.decodeFile(prefs.getString("wallpaper_file", ""));
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
content.setBackground(drawable);
} catch (Exception e) {
log(e.toString());
var rootView = (ViewGroup) content.getChildAt(0);
var views = new ArrayList<View>();
while (rootView.getChildCount() > 0) {
views.add(rootView.getChildAt(0));
rootView.removeView(rootView.getChildAt(0));
}
var frameLayout = new WallpaperView(rootView.getContext(), prefs);
for (var v : views) {
frameLayout.addView(v);
}
rootView.addView(frameLayout);
}

@NonNull
Expand All @@ -206,15 +219,15 @@ public String getPluginName() {
return "Change Colors";
}

// public class LayoutInflaterHook extends XC_MethodHook {
// @Override
// protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// var colors = getAlpha();
// var view = (View) param.getResult();
// if (view == null) return;
// replaceColors(view, colors);
// }
// }
public class LayoutInflaterHook extends XC_MethodHook {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
var colors = getAlpha();
var view = (View) param.getResult();
if (view == null) return;
replaceColors(view, colors);
}
}

public class ColorStateListHook extends XC_MethodHook {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public HideReceipt(ClassLoader loader, XSharedPreferences preferences) {
public void doHook() throws Exception {
var method = Unobfuscator.loadReceiptMethod(loader);
var method2 = Unobfuscator.loadReceiptMethod2(loader);
var method3 = Unobfuscator.loadReceiptMethod3(loader);
logDebug(Unobfuscator.getMethodDescriptor(method));
XposedBridge.hookMethod(method, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (!prefs.getBoolean("hidereceipt", false)) return;
if (!Unobfuscator.isCalledFromMethod(method2)) return;
if (!Unobfuscator.isCalledFromMethod(method2) && !Unobfuscator.isCalledFromMethod(method3)) return;
var jid = WppCore.getRawString(param.args[0]);
if ((jid == null || jid.contains("@lid")) && param.args[4] != "sender") {
param.args[4] = "inactive";
Expand Down

0 comments on commit 5da0204

Please sign in to comment.