Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 36 additions & 11 deletions app/src/main/java/ps/reso/instaeclipse/Xposed/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import org.luckypray.dexkit.DexKitBridge;

import java.util.Arrays;
import java.util.List;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
Expand Down Expand Up @@ -42,6 +45,28 @@ public class Module implements IXposedHookLoadPackage, IXposedHookZygoteInit {
private static String moduleSourceDir;
private static String moduleLibDir;

// List of supported Instagram package names
private static final List<String> SUPPORTED_PACKAGES = Arrays.asList(
CommonUtils.IG_PACKAGE_NAME, // Original package name
"com.instagram.android",
"com.instagold.android",
"com.instaflux.app",
"com.myinsta.android",
"cc.honista.app",
"com.instaprime.android",
"com.instafel.android",
"com.instadm.android",
"com.dfistagram.android",
"com.Instander.android",
"com.aero.instagram",
"com.instapro.android",
"com.instaflow.android",
"com.instagram1.android",
"com.instagram2.android",
"com.instagramclone.android",
"com.instaclone.android"
);

// for dev usage
/*
public static void showToast(final String text) {
Expand Down Expand Up @@ -102,27 +127,27 @@ public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) {
}
}

// Hook into Instagram
if (lpparam.packageName.equals(CommonUtils.IG_PACKAGE_NAME)) {
// Hook into Instagram and its clones
if (SUPPORTED_PACKAGES.contains(lpparam.packageName)) {
try {
if (dexKitBridge == null) {
// Load the .so file from your module (if not already loaded)
System.load(moduleLibDir + "/libdexkit.so");
// XposedBridge.log("libdexkit.so loaded successfully.");

// Initialize DexKitBridge with Instagram's APK
// Initialize DexKitBridge with the target app's APK
dexKitBridge = DexKitBridge.create(lpparam.appInfo.sourceDir);
// XposedBridge.log("DexKitBridge initialized with Instagram's APK: " + lpparam.appInfo.sourceDir);
// XposedBridge.log("DexKitBridge initialized with target APK: " + lpparam.appInfo.sourceDir);
}

// Use Instagram's ClassLoader
// Use the target app's ClassLoader
hostClassLoader = lpparam.classLoader;

// Call the method to hook Instagram
// Call the method to hook the target app
hookInstagram(lpparam);

} catch (Exception e) {
XposedBridge.log("(InstaEclipse): Failed to initialize DexKitBridge for Instagram: " + e.getMessage());
XposedBridge.log("(InstaEclipse): Failed to initialize DexKitBridge for " + lpparam.packageName + ": " + e.getMessage());
}
}
}
Expand All @@ -144,7 +169,7 @@ private void hookInstagram(XC_LoadPackage.LoadPackageParam lpparam) {
@Override
protected void afterHookedMethod(MethodHookParam param) {

XposedBridge.log("InstaEclipse: Settings loaded via Application.attach");
XposedBridge.log("InstaEclipse: Settings loaded via Application.attach for " + lpparam.packageName);

// Setup context, preferences
Context context = (Context) param.args[0];
Expand All @@ -155,7 +180,7 @@ protected void afterHookedMethod(MethodHookParam param) {
UIHookManager instagramUI = new UIHookManager();
instagramUI.mainActivity(hostClassLoader);

XposedBridge.log("(InstaEclipse): Instagram package detected. Starting feature hooks...");
XposedBridge.log("(InstaEclipse): " + lpparam.packageName + " package detected. Starting feature hooks...");

Interceptor interceptor = new Interceptor();

Expand Down Expand Up @@ -263,7 +288,7 @@ protected void afterHookedMethod(MethodHookParam param) {
});

} catch (Exception e) {
XposedBridge.log("(InstaEclipse): Failed to hook Instagram: " + e.getMessage());
XposedBridge.log("(InstaEclipse): Failed to hook " + lpparam.packageName + ": " + e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private static LinearLayout buildMainMenuLayout(Context context) {
mainLayout.addView(createClickableSection(context, "ℹ️ About", () -> showAboutDialog(context)));

// 6 - Restart Instagram => OPEN PAGE
mainLayout.addView(createClickableSection(context, "🔁 Restart Instagram", () -> showRestartSection(context)));
mainLayout.addView(createClickableSection(context, "🔁 Restart App", () -> showRestartSection(context)));

mainLayout.addView(createDivider(context));

Expand Down Expand Up @@ -256,39 +256,58 @@ private static View createDivider(Context context) {
return divider;
}

private static void restartInstagram(Context context) { // Restart Instagram and Remove its cache
/**
* Clears the application's cache and restarts it.
* Works for any package name this module is running in.
*
* @param context The application context.
*/
private static void restartApp(Context context) {
try {
Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.instagram.android");
clearInstagramCache(context);
String packageName = context.getPackageName();
Intent intent = context.getPackageManager().getLaunchIntentForPackage(packageName);

if (intent != null) {
clearAppCache(context); // Clear cache first
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
// Forcibly kill the current process to ensure a clean restart
Runtime.getRuntime().exit(0);
} else {
Toast.makeText(context, "Instagram not found", Toast.LENGTH_SHORT).show();
Toast.makeText(context, "Could not find the app to restart.", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
XposedBridge.log("InstaEclipse: Restart failed - " + e.getMessage());
String packageName = context.getPackageName();
XposedBridge.log("InstaEclipse: Restart failed for " + packageName + " - " + e.getMessage());
Toast.makeText(context, "Restart failed: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}

private static void clearInstagramCache(Context context) { // Clear Instagram Cache
/**
* Clears the cache directory for the current application.
*
* @param context The application context.
*/
private static void clearAppCache(Context context) {
try {
File cacheDir = context.getCacheDir();
if (cacheDir != null && cacheDir.exists()) {
XposedBridge.log("");
if (cacheDir != null && cacheDir.isDirectory()) {
deleteRecursive(cacheDir);
XposedBridge.log("InstaEclipse: Cache cleared");
XposedBridge.log("InstaEclipse: Cache cleared for " + context.getPackageName());
} else {
XposedBridge.log("InstaEclipse: Cache dir not found");
XposedBridge.log("InstaEclipse: Cache directory not found for " + context.getPackageName());
}
} catch (Exception e) {
XposedBridge.log("InstaEclipse: Failed to clear cache - " + e.getMessage());
XposedBridge.log("InstaEclipse: Failed to clear cache for " + context.getPackageName() + " - " + e.getMessage());
}
}

private static void deleteRecursive(File fileOrDirectory) { // Helper method
/**
* Recursively deletes a file or directory.
*
* @param fileOrDirectory The file or directory to delete.
*/
private static void deleteRecursive(File fileOrDirectory) {
if (fileOrDirectory.isDirectory()) {
File[] children = fileOrDirectory.listFiles();
if (children != null) {
Expand All @@ -297,9 +316,11 @@ private static void deleteRecursive(File fileOrDirectory) { // Helper method
}
}
}
// A direct result for a file or an empty directory
fileOrDirectory.delete();
}


// ==== SECTIONS ====

@SuppressLint("SetTextI18n")
Expand Down Expand Up @@ -755,7 +776,7 @@ private static void showRestartSection(Context context) {
layout.setGravity(Gravity.CENTER_HORIZONTAL);

TextView message = new TextView(context);
message.setText("⚠️ Restart Instagram and remove its cache?!");
message.setText("⚠️ Clear app cache and restart?");
message.setTextColor(Color.WHITE);
message.setTextSize(18f);
message.setGravity(Gravity.CENTER);
Expand All @@ -766,12 +787,12 @@ private static void showRestartSection(Context context) {
restartButton.setTextColor(Color.WHITE);
restartButton.setPadding(40, 20, 40, 20);

restartButton.setOnClickListener(v -> restartInstagram(context));
restartButton.setOnClickListener(v -> restartApp(context));

layout.addView(message);
layout.addView(restartButton);

showSectionDialog(context, "Restart Instagram", layout, () -> {
showSectionDialog(context, "Restart App", layout, () -> {
});
}

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,21 @@
<resources>
<string-array name="target_app">
<item>com.instagram.android</item>
<item>com.instagold.android</item>
<item>com.instaflux.app</item>
<item>com.myinsta.android</item>
<item>cc.honista.app</item>
<item>com.instaprime.android</item>
<item>com.instafel.android</item>
<item>com.instadm.android</item>
<item>com.dfistagram.android</item>
<item>com.Instander.android</item>
<item>com.aero.instagram</item>
<item>com.instapro.android</item>
<item>com.instaflow.android</item>
<item>com.instagram1.android</item>
<item>com.instagram2.android</item>
<item>com.instagramclone.android</item>
<item>com.instaclone.android</item>
</string-array>
</resources>