Skip to content

Commit

Permalink
Fix communication hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Chipppppppppp committed Jun 7, 2024
1 parent d6946d8 commit 3526308
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 55 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ android {
versionName "1.8.1"
multiDexEnabled false
proguardFiles += 'proguard-rules.pro'
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"14.7.0"'
buildConfigField 'String', 'HOOK_TARGET_VERSION', '"14.8.0"'
}

signingConfigs {
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/io/github/chipppppppppp/lime/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.hooks.AddRegistrationOptions;
import io.github.chipppppppppp.lime.hooks.BlockTracking;
import io.github.chipppppppppp.lime.hooks.ChangeCommunication;
import io.github.chipppppppppp.lime.hooks.ModifyRequest;
import io.github.chipppppppppp.lime.hooks.CheckHookTargetVersion;
import io.github.chipppppppppp.lime.hooks.Constants;
import io.github.chipppppppppp.lime.hooks.EmbedOptions;
import io.github.chipppppppppp.lime.hooks.IHook;
import io.github.chipppppppppp.lime.hooks.KeepUnread;
import io.github.chipppppppppp.lime.hooks.OutputCommunication;
import io.github.chipppppppppp.lime.hooks.ModifyResponse;
import io.github.chipppppppppp.lime.hooks.OutputRequest;
import io.github.chipppppppppp.lime.hooks.OutputResponse;
import io.github.chipppppppppp.lime.hooks.PreventMarkAsRead;
import io.github.chipppppppppp.lime.hooks.PreventUnsendMessage;
import io.github.chipppppppppp.lime.hooks.RedirectWebView;
Expand All @@ -40,6 +42,8 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
public static LimeOptions limeOptions = new LimeOptions();

static final IHook[] hooks = {
new OutputResponse(),
new ModifyRequest(),
new CheckHookTargetVersion(),
new SpoofAndroidId(),
new SpoofUserAgent(),
Expand All @@ -56,8 +60,8 @@ public class Main implements IXposedHookLoadPackage, IXposedHookInitPackageResou
new SendMuteMessage(),
new KeepUnread(),
new BlockTracking(),
new ChangeCommunication(),
new OutputCommunication()
new ModifyResponse(),
new OutputRequest()
};

public void handleLoadPackage(@NonNull XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.ScrollingMovementMethod;
import android.util.Base64;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
Expand Down Expand Up @@ -115,7 +116,7 @@ else if (name == "open_in_browser") {
android.text.InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editText.setVerticalScrollBarEnabled(true);
editText.setMovementMethod(new ScrollingMovementMethod());
editText.setText(prefs.getString("custom_js", ""));
editText.setText(prefs.getString("encoded_custom_js", ""));

editText.addTextChangedListener(new TextWatcher() {
@Override
Expand All @@ -128,7 +129,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
prefs.edit().putString("custom_js", s.toString()).apply();
prefs.edit().putString("encoded_custom_js", Base64.encodeToString(s.toString().getBytes(), Base64.NO_WRAP)).apply();
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public Communication(Type type, String name, Object value) {

@Override
public String toString() {
return type.toString() + " " + name + ": " + value.toString();
return type.toString() + ": " + name + ", " + value.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.github.chipppppppppp.lime.hooks;

import de.robv.android.xposed.XposedBridge;

public class Console {
public void log(Object arg) {
XposedBridge.log(String.valueOf(arg));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ else if (name.equals("open_in_browser")) {
android.text.InputType.TYPE_TEXT_FLAG_IME_MULTI_LINE);
editText.setVerticalScrollBarEnabled(true);
editText.setMovementMethod(new ScrollingMovementMethod());
editText.setText(prefs.getString("custom_js", ""));
final String script = new String(Base64.decode(prefs.getString("encoded_custom_js", ""), Base64.NO_WRAP));
editText.setText(script);

layout.addView(editText);

Expand All @@ -141,9 +142,9 @@ public void onClick(DialogInterface dialog, int which) {
prefs.edit().putBoolean(limeOptions.options[i].name, switchView.isChecked()).commit();
}
String code = editText.getText().toString();
if (!prefs.getString("custom_js", "").equals(code)) {
if (!code.equals(script)) {
optionChanged = true;
prefs.edit().putString("custom_js", code).commit();
prefs.edit().putString("encoded_custom_js", Base64.encodeToString(code.getBytes(), Base64.NO_WRAP)).commit();
}

if (optionChanged) {
Expand All @@ -163,7 +164,7 @@ public void onDismiss(DialogInterface dialog) {
Switch switchView = (Switch) layout.getChildAt(i);
switchView.setChecked(limeOptions.options[i].checked);
}
editText.setText(prefs.getString("custom_js", ""));
editText.setText(script);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.github.chipppppppppp.lime.hooks;

import android.util.Base64;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;
import io.github.chipppppppppp.lime.Main;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class ModifyRequest implements IHook {
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.REQUEST_HOOK.className),
Constants.REQUEST_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
final String script = new String(Base64.decode(Main.xPrefs.getString("encoded_custom_js", ""), Base64.NO_WRAP));
Context ctx = Context.enter();
ctx.setOptimizationLevel(-1);
try {
Scriptable scope = ctx.initStandardObjects();
Object jsCommunication = Context.javaToJS(new Communication(Communication.Type.REQUEST, param.args[0].toString(), param.args[1]), scope);
ScriptableObject.putProperty(scope, "communication", jsCommunication);
ScriptableObject.putProperty(scope, "console", Context.javaToJS(new Console(), scope));
ctx.evaluateString(scope, script, "Script", 1, null);
} catch (Exception e) {
XposedBridge.log(e.toString());
} finally {
Context.exit();
}
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,37 @@
package io.github.chipppppppppp.lime.hooks;

import android.util.Base64;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;
import io.github.chipppppppppp.lime.Main;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject;

public class ChangeCommunication implements IHook {
public class ModifyResponse implements IHook {
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.outputCommunication.checked) return;

XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.REQUEST_HOOK.className),
Constants.REQUEST_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String script = Main.xPrefs.getString("custom_js", "");
Context ctx = Context.enter();
try {
Scriptable scope = ctx.initStandardObjects();
Object jsCommunication = Context.javaToJS(new Communication(Communication.Type.REQUEST, param.args[0].toString(), param.args[1]), scope);
ScriptableObject.putProperty(scope, "communication", jsCommunication);
ctx.evaluateString(scope, script, "Script", 1, null);
} catch (Exception e) {
e.printStackTrace();
} finally {
Context.exit();
}
}
}
);

XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.RESPONSE_HOOK.className),
Constants.RESPONSE_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
String script = Main.xPrefs.getString("custom_js", "");
final String script = new String(Base64.decode(Main.xPrefs.getString("encoded_custom_js", ""), Base64.NO_WRAP));
Context ctx = Context.enter();
ctx.setOptimizationLevel(-1);
try {
Scriptable scope = ctx.initStandardObjects();
Object jsCommunication = Context.javaToJS(new Communication(Communication.Type.RESPONSE, param.args[0].toString(), param.args[1]), scope);
ScriptableObject.putProperty(scope, "communication", jsCommunication);
ScriptableObject.putProperty(scope, "console", Context.javaToJS(new Console(), scope));
ctx.evaluateString(scope, script, "Script", 1, null);
} catch (Exception e) {
e.printStackTrace();
XposedBridge.log(e.toString());
} finally {
Context.exit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.chipppppppppp.lime.hooks;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;

public class OutputRequest implements IHook {
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.outputCommunication.checked) return;

XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.REQUEST_HOOK.className),
Constants.REQUEST_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log(new Communication(Communication.Type.REQUEST, param.args[0].toString(), param.args[1]).toString());
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import io.github.chipppppppppp.lime.LimeOptions;

public class OutputCommunication implements IHook {
public class OutputResponse implements IHook {
@Override
public void hook(LimeOptions limeOptions, XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
if (!limeOptions.outputCommunication.checked) return;

XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.REQUEST_HOOK.className),
Constants.REQUEST_HOOK.methodName,
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
XposedBridge.log(new Communication(Communication.Type.REQUEST, param.args[0].toString(), param.args[1]).toString());
}
}
);

XposedBridge.hookAllMethods(
loadPackageParam.classLoader.loadClass(Constants.RESPONSE_HOOK.className),
Constants.RESPONSE_HOOK.methodName,
Expand Down

0 comments on commit 3526308

Please sign in to comment.