Skip to content

Commit

Permalink
Embed resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipppppppppp committed Feb 16, 2024
1 parent 2caa368 commit 8c78aec
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 88 deletions.
13 changes: 12 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.APPLICATION_PREFERENCES" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name=".Main"
Expand All @@ -30,4 +41,4 @@
android:value="jp.naver.line.android" />
</application>

</manifest>
</manifest>
60 changes: 60 additions & 0 deletions app/src/main/java/io/github/chipppppppppp/lime/LimeOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.chipppppppppp.lime;

public class LimeOptions {
public class Option {
public final String name;
int id;
public boolean checked;

public Option(String name, int id, boolean checked) {
this.name = name;
this.id = id;
this.checked = checked;
}
}

public Option deleteVoom = new Option("delete_voom", R.string.switch_delete_voom, true);
public Option deleteWallet = new Option("delete_wallet", R.string.switch_delete_wallet, true);
public Option deleteNewsOrCall = new Option("delete_news_or_call", R.string.switch_delete_news_or_call, true);
public Option distributeEvenly = new Option("distribute_evenly", R.string.switch_distribute_evenly, true);
public Option deleteIconLabels = new Option("delete_icon_labels", R.string.switch_delete_icon_labels, true);
public Option deleteAds = new Option("delete_ads", R.string.switch_delete_ads, true);
public Option deleteRecommendation = new Option("delete_recommendation", R.string.switch_delete_recommendation, true);
public Option deleteReplyMute = new Option("delete_reply_mute", R.string.switch_delete_reply_mute, true);
public Option redirectWebView = new Option("redirect_webview", R.string.switch_redirect_webview, true);
public Option openInBrowser = new Option("open_in_browser", R.string.switch_open_in_browser, false);
public Option preventMarkAsRead = new Option("prevent_mark_as_read", R.string.switch_prevent_mark_as_read, false);
public Option preventUnsendMessage = new Option("prevent_unsend_message", R.string.switch_prevent_unsend_message, false);
public static final int size = 12;

public Option getByIndex(int idx) {
switch (idx) {
case 0:
return deleteVoom;
case 1:
return deleteWallet;
case 2:
return deleteNewsOrCall;
case 3:
return distributeEvenly;
case 4:
return deleteIconLabels;
case 5:
return deleteAds;
case 6:
return deleteRecommendation;
case 7:
return deleteReplyMute;
case 8:
return redirectWebView;
case 9:
return openInBrowser;
case 10:
return preventMarkAsRead;
case 11:
return preventUnsendMessage;
default:
throw new IllegalArgumentException("Invalid index: " + idx);
}
}
}
122 changes: 39 additions & 83 deletions app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.net.Uri;
Expand Down Expand Up @@ -40,80 +41,23 @@

public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResources, IXposedHookZygoteInit {
public String MODULE_PATH;
public final String PACKAGE = "jp.naver.line.android";

public class LimeOptions {
public class LimeOption {
String name;
public int id;
public boolean checked;

private LimeOption(String name, int id, boolean checked) {
this.name = name;
this.id = id;
this.checked = checked;
}
}

public LimeOption deleteVoom = new LimeOption("delete_voom", R.string.switch_delete_voom, true);
public LimeOption deleteWallet = new LimeOption("delete_wallet", R.string.switch_delete_wallet, true);
public LimeOption deleteNewsOrCall = new LimeOption("delete_news_or_call", R.string.switch_delete_news_or_call, true);
public LimeOption distributeEvenly = new LimeOption("distribute_evenly", R.string.switch_distribute_evenly, true);
public LimeOption deleteIconLabels = new LimeOption("delete_icon_labels", R.string.switch_delete_icon_labels, true);
public LimeOption deleteAds = new LimeOption("delete_ads", R.string.switch_delete_ads, true);
public LimeOption deleteRecommendation = new LimeOption("delete_recommendation", R.string.switch_delete_recommendation, true);
public LimeOption deleteReplyMute = new LimeOption("delete_reply_mute", R.string.switch_delete_reply_mute, true);
public LimeOption redirectWebView = new LimeOption("redirect_webview", R.string.switch_redirect_webview, true);
public LimeOption openInBrowser = new LimeOption("open_in_browser", R.string.switch_open_in_browser, false);
public LimeOption preventMarkAsRead = new LimeOption("prevent_mark_as_read", R.string.switch_prevent_mark_as_read, false);
public LimeOption preventUnsendMessage = new LimeOption("prevent_unsend_message", R.string.switch_prevent_unsend_message, false);
public static final int size = 12;

LimeOption getByIndex(int idx) {
switch (idx) {
case 0:
return deleteVoom;
case 1:
return deleteWallet;
case 2:
return deleteNewsOrCall;
case 3:
return distributeEvenly;
case 4:
return deleteIconLabels;
case 5:
return deleteAds;
case 6:
return deleteRecommendation;
case 7:
return deleteReplyMute;
case 8:
return redirectWebView;
case 9:
return openInBrowser;
case 10:
return preventMarkAsRead;
case 11:
return preventUnsendMessage;
default:
throw new IllegalArgumentException("Invalid index: " + idx);
}
}
}
public static final String PACKAGE = "jp.naver.line.android";
public static final String MODULE = "io.github.chipppppppppp.lime";

public LimeOptions limeOptions = new LimeOptions();

private int dpToPx(int dp, Context context) {
float density = context.getResources().getDisplayMetrics().density;
return Math.round((float) dp * density);
}

public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lparam) throws Throwable {
if (!lparam.packageName.equals(PACKAGE)) return;

XSharedPreferences xPrefs = new XSharedPreferences(PACKAGE, "io.github.chipppppppppp.lime-options");
final XSharedPreferences xModulePrefs = new XSharedPreferences(MODULE, "options");
XSharedPreferences xPrefs;
if (xModulePrefs.getBoolean("unembed_options", false)) {
xPrefs = xModulePrefs;
} else {
xPrefs = new XSharedPreferences(PACKAGE, MODULE + "-options");
}
for (int i = 0; i < limeOptions.size; ++i) {
LimeOptions.LimeOption option = limeOptions.getByIndex(i);
LimeOptions.Option option = limeOptions.getByIndex(i);
option.checked = xPrefs.getBoolean(option.name, option.checked);
}

Expand All @@ -125,16 +69,27 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lparam) throws Thr
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
ViewGroup viewGroup = ((ViewGroup) param.args[0]);
Context context = viewGroup.getContext();
Context moduleContext;

Method method = AssetManager.class.getDeclaredMethod("addAssetPath", String.class);
method.setAccessible(true);
method.invoke(context.getResources().getAssets(), MODULE_PATH);

SharedPreferences prefs;
try {
moduleContext = AndroidAppHelper.currentApplication().createPackageContext("io.github.chipppppppppp.lime", Context.CONTEXT_IGNORE_SECURITY);
prefs = AndroidAppHelper.currentApplication().getSharedPreferences("io.github.chipppppppppp.lime-options", Context.MODE_PRIVATE);
prefs = AndroidAppHelper.currentApplication().getSharedPreferences(MODULE + "-options", Context.MODE_PRIVATE);
} catch (Exception e) {
XposedBridge.log(e.toString());
return;
}

if (xModulePrefs.getBoolean("unembed_options", false)) {
for (int i = 0; i < limeOptions.size; ++i) {
LimeOptions.Option option = limeOptions.getByIndex(i);
prefs.edit().putBoolean(option.name, xModulePrefs.getBoolean(option.name, option.checked));
}
return;
}

FrameLayout frameLayout = new FrameLayout(context);
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
Expand All @@ -146,31 +101,32 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT);
layoutParams.gravity = Gravity.TOP | Gravity.END;
layoutParams.rightMargin = dpToPx(10, context);
layoutParams.topMargin = dpToPx(5, context);
layoutParams.rightMargin = Utils.dpToPx(10, context);
layoutParams.topMargin = Utils.dpToPx(5, context);
button.setLayoutParams(layoutParams);

AlertDialog.Builder builder = new AlertDialog.Builder(context)
.setTitle(moduleContext.getString(R.string.option))
.setTitle(context.getString(R.string.options_title))
.setCancelable(false);

LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(dpToPx(20, context), dpToPx(20, context), dpToPx(20, context), dpToPx(20, context));
layout.setPadding(Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context), Utils.dpToPx(20, context));

Switch switchRedirectWebView = null;
for (int i = 0; i < limeOptions.size; ++i) {
LimeOptions.LimeOption option = limeOptions.getByIndex(i);
String name = option.name;
LimeOptions.Option option = limeOptions.getByIndex(i);
final String name = option.name;

Switch switchView = new Switch(context);
switchView.setText(moduleContext.getString(option.id));
switchView.setText(context.getString(option.id));
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.topMargin = dpToPx(20, context);
params.topMargin = Utils.dpToPx(20, context);
switchView.setLayoutParams(params);

switchView.setChecked(option.checked);
Expand Down Expand Up @@ -198,10 +154,10 @@ else if (name == "open_in_browser") {
scrollView.addView(layout);
builder.setView(scrollView);

builder.setPositiveButton(moduleContext.getString(R.string.ok), new DialogInterface.OnClickListener() {
builder.setPositiveButton(context.getString(R.string.dialog_positive), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(context.getApplicationContext(), moduleContext.getString(R.string.need_restart), Toast.LENGTH_SHORT).show();
Toast.makeText(context.getApplicationContext(), context.getString(R.string.need_restart), Toast.LENGTH_SHORT).show();
}
});

Expand Down Expand Up @@ -432,15 +388,15 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
});

hookTarget = lparam.classLoader.loadClass("nl5.jo");
hookTarget = lparam.classLoader.loadClass("tn5.go");
XposedBridge.hookAllMethods(hookTarget, "write", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (limeOptions.preventMarkAsRead.checked) param.setResult(null);
}
});

hookTarget = lparam.classLoader.loadClass("nl5.kd");
hookTarget = lparam.classLoader.loadClass("tn5.id");
final Method valueOf = hookTarget.getMethod("valueOf", String.class);
final Object dummy = valueOf.invoke(null, "DUMMY");
final Object notifiedDestroyMessage = valueOf.invoke(null, "NOTIFIED_DESTROY_MESSAGE");
Expand All @@ -450,7 +406,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (limeOptions.preventUnsendMessage.checked && param.getResult() == notifiedDestroyMessage) param.setResult(dummy);
}
});
hookTarget = lparam.classLoader.loadClass("kk5.b");
hookTarget = lparam.classLoader.loadClass("om5.c");
XposedHelpers.findAndHookMethod(hookTarget, "u", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Expand Down
Loading

0 comments on commit 8c78aec

Please sign in to comment.