Skip to content

Commit 597cdbb

Browse files
authored
Merge pull request #47 from ReSo7200/master
Version 3.1
2 parents b95e4b1 + 8ce8db7 commit 597cdbb

File tree

5 files changed

+98
-78
lines changed

5 files changed

+98
-78
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ android {
66
applicationId "com.chacha.igexperiments"
77
minSdkVersion 26
88
targetSdkVersion 34
9-
versionName '3.0'
9+
versionName '3.1'
1010

1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12-
versionCode 30
12+
versionCode 31
1313
}
1414

1515
buildTypes {

app/src/main/java/com/chacha/igexperiments/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class MainActivity extends AppCompatActivity {
5555

5656

5757
private static final String VERSION_URL = "https://raw.githubusercontent.com/ReSo7200/IGExperimentsHooksUpdates/refs/heads/main/version.json";
58-
private static final String CURRENT_VERSION = "3.0";
58+
private static final String CURRENT_VERSION = "3.1";
5959

6060
private final ExecutorService executor = Executors.newSingleThreadExecutor(); // Executor for background tasks
6161

app/src/main/java/com/chacha/igexperiments/Module.java

Lines changed: 85 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.text.SimpleDateFormat;
2121
import java.util.ArrayList;
2222
import java.util.Date;
23+
import java.util.List;
2324
import java.util.Scanner;
2425

2526
import de.robv.android.xposed.IXposedHookLoadPackage;
@@ -29,6 +30,9 @@
2930
import de.robv.android.xposed.XposedHelpers;
3031
import de.robv.android.xposed.callbacks.XC_LoadPackage;
3132

33+
/**
34+
* @noinspection ALL
35+
*/
3236
public class Module implements IXposedHookLoadPackage, IXposedHookZygoteInit {
3337

3438

@@ -38,39 +42,50 @@ public class Module implements IXposedHookLoadPackage, IXposedHookZygoteInit {
3842
* Init the preferences
3943
*/
4044
private String initPreferences() {
41-
XposedPreferences.loadPreferences();
42-
XposedPreferences.reloadPrefs();
45+
try {
46+
XposedPreferences.loadPreferences();
47+
XposedPreferences.reloadPrefs();
4348

44-
if (XposedPreferences.getPrefs().getString("Mode", "Normal").equals("Normal")) {
45-
XposedBridge.log("(IGExperiments) Using class name from Github");
49+
String mode = XposedPreferences.getPrefs().getString("Mode", "Normal");
4650

47-
return "Normal";
48-
} else if (XposedPreferences.getPrefs().getString("Mode", "Normal").equals("Auto")) {
49-
XposedBridge.log("(IGExperiments) Dynamic searching");
51+
if (mode.equals("Normal")) {
52+
XposedBridge.log("(IGExperiments) Using class name from Github");
53+
return "Normal";
54+
} else if (mode.equals("Auto")) {
55+
XposedBridge.log("(IGExperiments) Dynamic searching");
56+
return "Auto";
57+
}
5058

51-
return "Auto";
52-
}
53-
XposedBridge.log("(IGExperiments) Using class name from preferences");
54-
return "Hecker";
59+
XposedBridge.log("(IGExperiments) Using class name from preferences");
60+
return "Hecker";
5561

62+
} catch (Exception e) {
63+
XposedBridge.log("(IGExperiments) Exception in initPreferences, defaulting to 'Normal': " + e.getMessage());
64+
return "Normal"; // Default to "Normal" if an exception occurs
65+
}
5666
}
5767

5868

5969
/**
6070
* Initialize the class and method to hook
6171
*/
6272
private void initElemToHook() {
63-
className = XposedPreferences.getPrefs().getString("className", "");
64-
methodName = XposedPreferences.getPrefs().getString("methodName", "");
65-
secondClassName = XposedPreferences.getPrefs().getString("secondClassName", "");
73+
try {
74+
className = XposedPreferences.getPrefs().getString("className", "");
75+
methodName = XposedPreferences.getPrefs().getString("methodName", "");
76+
secondClassName = XposedPreferences.getPrefs().getString("secondClassName", "");
6677

6778

68-
if (className.equals("")) {
69-
XposedBridge.log("(IGExperiments) No class name found, using default");
70-
className = Utils.DEFAULT_CLASS_TO_HOOK;
71-
methodName = Utils.DEFAULT_METHOD_TO_HOOK;
72-
secondClassName = Utils.DEFAULT_SECOND_CLASS_TO_HOOK;
79+
if (className.equals("")) {
80+
XposedBridge.log("(IGExperiments) No class name found, using default");
81+
className = Utils.DEFAULT_CLASS_TO_HOOK;
82+
methodName = Utils.DEFAULT_METHOD_TO_HOOK;
83+
secondClassName = Utils.DEFAULT_SECOND_CLASS_TO_HOOK;
84+
}
85+
} catch (Exception ignored) {
86+
7387
}
88+
7489
}
7590

7691
@Override
@@ -174,7 +189,7 @@ protected Object replaceHookedMethod(MethodHookParam param) {
174189

175190
success = true;
176191

177-
// Dynamic search logic
192+
// Dynamic search logic
178193
} else if (type.equals("Auto")) {
179194
try {
180195
// Fixed method and second class
@@ -192,72 +207,83 @@ protected Object replaceHookedMethod(MethodHookParam param) {
192207
String majorVersion = versionParts[0];
193208
int majorVersionNumber = Integer.parseInt(majorVersion);
194209

195-
if (majorVersionNumber >= 334) { // if the instagram version starts with 334 or more it would be compatible with auto mode
210+
if (majorVersionNumber >= 334) { // Check if Instagram version is compatible with auto mode
196211
XposedBridge.log(getTime() + "(IGExperiments) Searching for the correct class to hook...");
197212

198213
// Try to hook into multiple class names incrementally
199-
String characters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
214+
String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
215+
int hookCount = 0; // Counter for successful hooks
216+
217+
// Initialize a list to store the names of successfully hooked classes
218+
List<String> hookedClasses = new ArrayList<>();
200219

201220
outerLoop:
202221
for (char first : characters.toCharArray()) {
203222
for (char second : characters.toCharArray()) {
204223
for (char third : characters.toCharArray()) {
205224
String classToHook = "X." + first + second + third; // Generate class name
206225
try {
207-
// DEV PURPOSES
208-
// XposedBridge.log("(IGExperiments) Attempting to inspect class: " + classToHook);
209-
226+
// Attempt to find the target class and second target class
210227
Class<?> targetClass = XposedHelpers.findClass(classToHook, lpparam.classLoader);
211228
Class<?> secondTargetClass = XposedHelpers.findClass(secondClassToHook, lpparam.classLoader);
212229

213-
// Check if the method returns a Boolean
214-
boolean hasIsEmployee = false;
215-
for (Method method : targetClass.getDeclaredMethods()) {
216-
if (method.getReturnType() == Boolean.TYPE) {
217-
hasIsEmployee = true;
218-
break;
230+
// Catch NoClassDefFoundError within the method inspection loop
231+
try {
232+
//XposedBridge.log("Trying class: " + classToHook);
233+
// Check if the target class has a Boolean-returning method named A00 with one parameter
234+
for (Method method : targetClass.getDeclaredMethods()) {
235+
if (method.getName().equals("A00") &&
236+
method.getReturnType() == Boolean.TYPE &&
237+
method.getParameterCount() == 1) {
238+
239+
XposedBridge.log("(IGExperiments) Hooking into class: " + classToHook);
240+
XposedHelpers.findAndHookMethod(targetClass, "A00", secondTargetClass,
241+
new XC_MethodReplacement() {
242+
@Override
243+
protected Object replaceHookedMethod(MethodHookParam param) {
244+
//XposedBridge.log("(IGExperiments) Successfully Hooked into class: " + classToHook);
245+
return true;
246+
}
247+
});
248+
249+
// Add to the list of hooked classes
250+
hookedClasses.add(classToHook);
251+
hookCount++; // Increment counter for each successful hook
252+
break; // No need to check further methods in this class
253+
}
219254
}
255+
} catch (NoClassDefFoundError e) {
256+
// Log and continue to the next class if NoClassDefFoundError is encountered
257+
//XposedBridge.log("(IGExperiments) Dependency not found while inspecting " + classToHook + ", skipping.");
258+
continue;
220259
}
221260

222-
if (!hasIsEmployee) {
223-
// DEV PURPOSES
224-
// XposedBridge.log("(IGExperiments) Class " + classToHook + " does not return a Boolean, skipping...");
225-
continue; // Skip this class if it doesn't have the expected method
226-
}
227-
228-
XposedBridge.log("(IGExperiments) Found target class with 'is_employee': " + classToHook);
229-
230-
// Hook the method A00 in this class
231-
XposedHelpers.findAndHookMethod(targetClass, methodToHook, secondTargetClass,
232-
new XC_MethodReplacement() {
233-
@Override
234-
protected Object replaceHookedMethod(MethodHookParam param) {
235-
XposedBridge.log("(IGExperiments) Successfully Hooked into class: " + classToHook);
236-
return true;
237-
}
238-
});
239-
240-
success = true; // Mark as successful if a method was hooked
241-
break outerLoop; // Exit loop if successful
242261
} catch (XposedHelpers.ClassNotFoundError e) {
243-
// If the class doesn't exist, continue trying
244-
XposedBridge.log("(IGExperiments) Class " + classToHook + " not found, trying next.");
262+
//XposedBridge.log("(IGExperiments) Class " + classToHook + " not found, trying next.");
245263
} catch (NoSuchMethodError e) {
246-
XposedBridge.log("(IGExperiments) Method A00 not found in class: " + classToHook);
264+
//XposedBridge.log("(IGExperiments) Method A00 not found in class: " + classToHook);
247265
} catch (Exception e) {
248-
XposedBridge.log("(IGExperiments) Failed to hook class: " + classToHook + ", error: " + e.getMessage());
266+
//XposedBridge.log("(IGExperiments) Failed to hook class: " + classToHook + ", error: " + e.getMessage());
249267
}
250268
}
251269
}
252270
}
253271

254-
if (!success) {
272+
// After completing the loop, check if multiple hooks were set and show a toast
273+
if (hookCount > 1) {
274+
showToast("Multiple hooks set. Please disable the module if you encounter issues.");
275+
}
276+
if (!hookedClasses.isEmpty()) {
277+
XposedBridge.log("(IGExperiments) Successfully hooked classes:");
278+
for (String hookedClass : hookedClasses) {
279+
XposedBridge.log("(IGExperiments) Hooked class: " + hookedClass);
280+
}
281+
} else {
255282
XposedBridge.log("(IGExperiments) No matching class found.");
256283
}
257284

258-
259285
} else {
260-
showToast("Versions that are older than 334.x aren't compatible with auto mode!\nTry another mode.");
286+
showToast("Versions older than 334.x aren't compatible with auto mode! Try another mode.");
261287
}
262288

263289

@@ -286,7 +312,7 @@ protected Object replaceHookedMethod(MethodHookParam param) {
286312
private static String getJSONContent() {
287313
try {
288314
Log.println(Log.INFO, "IGexperiments", "Reading raw content from github file");
289-
URL url = new URL("https://raw.githubusercontent.com/ReSo7200/IGexperiments/master/classes_to_hook.json");
315+
URL url = new URL("https://raw.githubusercontent.com/ReSo7200/IGExperimentsUpdates/master/hooks.json");
290316
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
291317
StrictMode.setThreadPolicy(policy);
292318
Scanner s = new Scanner(url.openStream());

app/src/main/java/com/chacha/igexperiments/XposedPreferences.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static XSharedPreferences getLegacyPrefs() {
1818
return new XSharedPreferences(f);
1919
}
2020

21-
public static XSharedPreferences loadPreferences() {
21+
public static void loadPreferences() {
2222
if (XposedBridge.getXposedVersion() < 93) {
2323
pref = getLegacyPrefs();
2424
} else {
@@ -31,13 +31,7 @@ public static XSharedPreferences loadPreferences() {
3131
XposedBridge.log("Can't load preference in the module");
3232
}
3333

34-
return pref;
35-
}
36-
37-
public static boolean hasPrefsChanged() {
38-
return pref.hasFileChanged();
3934
}
40-
4135
public static void reloadPrefs() {
4236
pref.reload();
4337
}

classes_to_hook.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{
22
"ig_versions": [
33
{
4-
"version": "350.1.0.46.93 - S",
5-
"class_to_hook": "X.1AG",
4+
"version": "354.2.0.47.100 - S",
5+
"class_to_hook": "X.4hz",
66
"method_to_hook": "A00",
77
"second_class_to_hook":"com.instagram.common.session.UserSession",
8-
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-350-1-0-46-93-release/"
8+
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-354-2-0-47-100-release/"
99
},
1010
{
11-
"version": "351.0.0.10.106 - B",
12-
"class_to_hook": "X.1B4",
11+
"version": "355.0.0.28.103 - B",
12+
"class_to_hook": "X.3xc",
1313
"method_to_hook": "A00",
1414
"second_class_to_hook":"com.instagram.common.session.UserSession",
15-
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-351-0-0-10-106-release/"
15+
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-355-0-0-28-103-release/"
1616
},
1717
{
18-
"version": "352.0.0.0.9 - A",
19-
"class_to_hook": "X.1BB",
18+
"version": "356.0.0.0.43 - A",
19+
"class_to_hook": "X.4iu",
2020
"method_to_hook": "A00",
2121
"second_class_to_hook":"com.instagram.common.session.UserSession",
22-
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-352-0-0-0-9-release/"
22+
"download": "https://www.apkmirror.com/apk/instagram/instagram-instagram/instagram-instagram-356-0-0-0-43-release/"
2323
}
2424
]
2525
}

0 commit comments

Comments
 (0)