Skip to content

Commit a17ed52

Browse files
committed
Fix bug of class not found
1 parent ccd017a commit a17ed52

File tree

5 files changed

+93
-39
lines changed

5 files changed

+93
-39
lines changed

app/src/main/java/com/wmods/wppenhacer/adapter/IGStatusAdapter.java

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import com.wmods.wppenhacer.views.dialog.TabDialogContent;
2626
import com.wmods.wppenhacer.xposed.core.WppCore;
27+
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
2728
import com.wmods.wppenhacer.xposed.core.devkit.UnobfuscatorCache;
2829
import com.wmods.wppenhacer.xposed.utils.DesignUtils;
2930
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
@@ -70,48 +71,69 @@ public View getView(int position, @Nullable View convertView, @NonNull ViewGroup
7071
var tabdialog = new TabDialogContent(activity);
7172
tabdialog.setTitle(activity.getString(ResId.string.select_status_type));
7273
tabdialog.addTab(UnobfuscatorCache.getInstance().getString("mystatus"), DesignUtils.getIconByName("ic_status", true), (view) -> {
73-
var intent = new Intent(WppCore.getCurrentActivity(), XposedHelpers.findClass("com.whatsapp.status.playback.MyStatusesActivity", getContext().getClassLoader()));
74-
WppCore.getCurrentActivity().startActivity(intent);
74+
try {
75+
var clazz = Unobfuscator.getClassByName("MyStatusesActivity", getContext().getClassLoader());
76+
var intent = new Intent(WppCore.getCurrentActivity(), clazz);
77+
WppCore.getCurrentActivity().startActivity(intent);
78+
} catch (Exception e) {
79+
Utils.showToast(e.getMessage(), 1);
80+
}
7581
dialog.dismissDialog();
7682
});
7783

7884
// Botão da camera
7985
var iconCamera = DesignUtils.getDrawable(ResId.drawable.camera);
8086
DesignUtils.coloredDrawable(iconCamera, DesignUtils.isNightMode() ? Color.WHITE : Color.BLACK);
8187
tabdialog.addTab(activity.getString(ResId.string.open_camera), iconCamera, (view) -> {
82-
Intent A09 = new Intent();
83-
A09.setClassName(activity.getPackageName(), "com.whatsapp.camera.CameraActivity");
84-
A09.putExtra("jid", "status@broadcast");
85-
A09.putExtra("camera_origin", 4);
86-
A09.putExtra("is_coming_from_chat", false);
87-
A09.putExtra("media_sharing_user_journey_origin", 32);
88-
A09.putExtra("media_sharing_user_journey_start_target", 9);
89-
A09.putExtra("media_sharing_user_journey_chat_type", 4);
90-
activity.startActivity(A09);
88+
try {
89+
Intent intent = new Intent();
90+
var clazz = Unobfuscator.getClassByName("CameraActivity", getContext().getClassLoader());
91+
intent.setClassName(activity.getPackageName(), clazz.getName());
92+
intent.putExtra("jid", "status@broadcast");
93+
intent.putExtra("camera_origin", 4);
94+
intent.putExtra("is_coming_from_chat", false);
95+
intent.putExtra("media_sharing_user_journey_origin", 32);
96+
intent.putExtra("media_sharing_user_journey_start_target", 9);
97+
intent.putExtra("media_sharing_user_journey_chat_type", 4);
98+
activity.startActivity(intent);
99+
} catch (Exception e) {
100+
Utils.showToast(e.getMessage(), 1);
101+
}
91102
dialog.dismissDialog();
92-
93103
});
94104
// Botão de editar
95105
var iconEdit = DesignUtils.getDrawable(ResId.drawable.edit2);
96106
DesignUtils.coloredDrawable(iconEdit, DesignUtils.isNightMode() ? Color.WHITE : Color.BLACK);
97107

98108
tabdialog.addTab(activity.getString(ResId.string.edit_text), iconEdit, (view) -> {
99-
Intent A09 = new Intent();
100-
if (XposedHelpers.findClassIfExists("com.whatsapp.textstatuscomposer.TextStatusComposerActivity", activity.getClassLoader()) != null) {
101-
A09.setClassName(activity.getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivity");
102-
} else {
103-
A09.setClassName(activity.getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivityV2");
109+
try {
110+
Intent intent = new Intent();
111+
Class clazz;
112+
try {
113+
clazz = Unobfuscator.getClassByName("TextStatusComposerActivity", activity.getClassLoader());
114+
} catch (Exception ignored) {
115+
clazz = Unobfuscator.getClassByName("ConsolidatedStatusComposerActivity", getContext().getClassLoader());
116+
intent.putExtra("status_composer_mode",2);
117+
}
118+
intent.setClassName(activity.getPackageName(), clazz.getName());
119+
activity.startActivity(intent);
120+
} catch (Exception e) {
121+
Utils.showToast(e.getMessage(), 1);
104122
}
105-
activity.startActivity(A09);
106123
dialog.dismissDialog();
107124
});
108125
dialog.setContentView(tabdialog);
109126
dialog.showDialog();
110127
return;
111128
}
112-
var intent = new Intent(WppCore.getCurrentActivity(), XposedHelpers.findClass("com.whatsapp.status.playback.StatusPlaybackActivity", getContext().getClassLoader()));
113-
intent.putExtra("jid", holder.jid);
114-
WppCore.getCurrentActivity().startActivity(intent);
129+
try {
130+
var clazz = Unobfuscator.getClassByName("StatusPlaybackActivity", getContext().getClassLoader());
131+
var intent = new Intent(WppCore.getCurrentActivity(), clazz);
132+
intent.putExtra("jid", holder.jid);
133+
WppCore.getCurrentActivity().startActivity(intent);
134+
} catch (Exception e) {
135+
Utils.showToast(e.getMessage(), 1);
136+
}
115137
});
116138

117139
return convertView;

app/src/main/java/com/wmods/wppenhacer/preference/ContactPickerPreference.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import androidx.preference.PreferenceManager;
1212

1313
import com.wmods.wppenhacer.R;
14-
import com.wmods.wppenhacer.xposed.features.others.ActivityController;
14+
import com.wmods.wppenhacer.xposed.utils.Utils;
1515

1616
import java.util.ArrayList;
1717
import java.util.Arrays;
@@ -58,12 +58,28 @@ public boolean onPreferenceClick(@NonNull Preference preference) {
5858
}
5959

6060
private void startSelectContacts(String packageName) {
61-
Intent intent = new Intent();
62-
intent.setClassName(packageName, ActivityController.EXPORTED_ACTIVITY);
63-
intent.putExtra("key", getKey());
64-
intent.putExtra("contact_mode", true);
65-
intent.putStringArrayListExtra("contacts", mContacts);
66-
((Activity) getContext()).startActivityForResult(intent, REQUEST_CONTACT_PICKER);
61+
try {
62+
Intent intent = new Intent();
63+
var pInfo = getContext().getApplicationContext().getPackageManager().getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
64+
assert pInfo.activities != null;
65+
String className = null;
66+
for (var activity : pInfo.activities) {
67+
if (activity.name.endsWith("SettingsNotifications")) {
68+
className = activity.name;
69+
break;
70+
}
71+
}
72+
if (className == null) {
73+
throw new Exception("Class SettingsNotifications not found");
74+
}
75+
intent.setClassName(packageName, className);
76+
intent.putExtra("key", getKey());
77+
intent.putExtra("contact_mode", true);
78+
intent.putStringArrayListExtra("contacts", mContacts);
79+
((Activity) getContext()).startActivityForResult(intent, REQUEST_CONTACT_PICKER);
80+
} catch (Exception e) {
81+
Utils.showToast(e.getMessage(), 1);
82+
}
6783
}
6884

6985
private void init(Context context, AttributeSet attrs) {

app/src/main/java/com/wmods/wppenhacer/xposed/core/devkit/Unobfuscator.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class Unobfuscator {
6262
private static final String TAG = "Unobfuscator";
6363
private static DexKitBridge dexkit;
6464

65-
public static final HashMap<String, Object> cache = new HashMap<>();
65+
public static final HashMap<String, Class<?>> cacheClasses = new HashMap<>();
6666

6767
static {
6868
System.loadLibrary("dexkit");
@@ -1217,7 +1217,7 @@ public synchronized static Method loadOnMenuItemSelected(ClassLoader loader) thr
12171217

12181218
public synchronized static Method loadOnUpdateStatusChanged(ClassLoader loader) throws Exception {
12191219
return UnobfuscatorCache.getInstance().getMethod(loader, () -> {
1220-
var clazz = XposedHelpers.findClass("com.whatsapp.updates.viewmodels.UpdatesViewModel", loader);
1220+
var clazz = getClassByName("UpdatesViewModel", loader);
12211221
var clazzData = dexkit.getClassData(clazz);
12221222
var methodSeduleche = XposedHelpers.findMethodBestMatch(Timer.class, "schedule", TimerTask.class, long.class, long.class);
12231223
var result = dexkit.findMethod(new FindMethod().searchInClass(List.of(clazzData)).matcher(new MethodMatcher().addInvoke(DexSignUtil.getMethodDescriptor(methodSeduleche))));
@@ -1356,7 +1356,8 @@ public synchronized static Method loadAudioProximitySensorMethod(ClassLoader loa
13561356

13571357
public synchronized static Method loadGroupAdminMethod(ClassLoader loader) throws Exception {
13581358
var method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "P Message");
1359-
if (method == null) method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "ConversationRow/setUpUsernameInGroupViewContainer/not allowed state");
1359+
if (method == null)
1360+
method = findFirstMethodUsingStrings(loader, StringMatchType.Contains, "ConversationRow/setUpUsernameInGroupViewContainer/not allowed state");
13601361
if (method == null) throw new RuntimeException("GroupAdmin method not found");
13611362
return method;
13621363
}
@@ -1934,4 +1935,16 @@ public static Class<?> loadRefreshStatusClass(ClassLoader classLoader) throws Ex
19341935
public static Method loadTcTokenMethod(ClassLoader classLoader) throws Exception {
19351936
return UnobfuscatorCache.getInstance().getMethod(classLoader, () -> findFirstMethodUsingStrings(classLoader, StringMatchType.Contains, "GET_RECEIVED_TOKEN_AND_TIMESTAMP_BY_JID"));
19361937
}
1938+
1939+
public static Class<?> getClassByName(String className, ClassLoader classLoader) throws ClassNotFoundException {
1940+
if (cacheClasses.containsKey(className))
1941+
return cacheClasses.get(className);
1942+
var classDataList = dexkit.findClass(FindClass.create().matcher(ClassMatcher.create().className(className, StringMatchType.EndsWith)));
1943+
if (classDataList.isEmpty())
1944+
throw new RuntimeException("Class " + className + " not found!");
1945+
var clazz = classDataList.get(0).getInstance(classLoader);
1946+
cacheClasses.put(className, clazz);
1947+
return clazz;
1948+
}
1949+
19371950
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/IGStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
7979
}
8080
});
8181

82-
var clazz2 = XposedHelpers.findClass("com.whatsapp.updates.viewmodels.UpdatesViewModel", classLoader);
82+
var clazz2 = Unobfuscator.getClassByName("UpdatesViewModel", classLoader);
8383
var onUpdateStatusChanged = Unobfuscator.loadOnUpdateStatusChanged(classLoader);
8484
logDebug(Unobfuscator.getMethodDescriptor(onUpdateStatusChanged));
8585
var statusInfoClass = Unobfuscator.loadStatusInfoClass(classLoader);

app/src/main/java/com/wmods/wppenhacer/xposed/features/media/StatusDownload.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.wmods.wppenhacer.xposed.core.Feature;
1515
import com.wmods.wppenhacer.xposed.core.WppCore;
1616
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
17+
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
1718
import com.wmods.wppenhacer.xposed.features.general.MenuStatus;
1819
import com.wmods.wppenhacer.xposed.utils.MimeTypeUtils;
1920
import com.wmods.wppenhacer.xposed.utils.ResId;
@@ -74,21 +75,23 @@ public void onClick(MenuItem item, Object fragmentInstance, FMessageWpp fMessage
7475
private void sharedStatus(FMessageWpp fMessageWpp) {
7576
try {
7677
if (!fMessageWpp.isMediaFile()) {
77-
7878
Intent intent = new Intent();
79-
var textStatusComposerActivity = XposedHelpers.findClassIfExists("com.whatsapp.textstatuscomposer.TextStatusComposerActivity", classLoader);
80-
if (textStatusComposerActivity != null) {
81-
intent.setClassName(Utils.getApplication().getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivity");
82-
} else {
83-
intent.setClassName(Utils.getApplication().getPackageName(), "com.whatsapp.textstatuscomposer.TextStatusComposerActivityV2");
79+
Class clazz;
80+
try {
81+
clazz = Unobfuscator.getClassByName("TextStatusComposerActivity", classLoader);
82+
} catch (Exception ignored) {
83+
clazz = Unobfuscator.getClassByName("ConsolidatedStatusComposerActivity", classLoader);
84+
intent.putExtra("status_composer_mode", 2);
8485
}
86+
intent.setClassName(Utils.getApplication().getPackageName(), clazz.getName());
8587
intent.putExtra("android.intent.extra.TEXT", fMessageWpp.getMessageStr());
8688
WppCore.getCurrentActivity().startActivity(intent);
8789
return;
8890
}
8991
var file = fMessageWpp.getMediaFile();
9092
Intent intent = new Intent();
91-
intent.setClassName(Utils.getApplication().getPackageName(), "com.whatsapp.mediacomposer.MediaComposerActivity");
93+
var clazz = Unobfuscator.getClassByName("MediaComposerActivity", classLoader);
94+
intent.setClassName(Utils.getApplication().getPackageName(), clazz.getName());
9295
intent.putExtra("jids", new ArrayList<>(Collections.singleton("status@broadcast")));
9396
intent.putExtra("android.intent.extra.STREAM", new ArrayList<>(Collections.singleton(Uri.fromFile(file))));
9497
intent.putExtra("android.intent.extra.TEXT", fMessageWpp.getMessageStr());

0 commit comments

Comments
 (0)