标签 android 下的文章

XposedHelpers.findAndHookMethod(ClassLoader.class,
        "loadClass", String.class,
        new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                if ("com.example.MainActivity".equals(param.args[0])) {
                    param.setResult(getClass().getClassLoader()
                            .loadClass("com.example.TargetActivity"));
                }
            }
        });

阅读全文

摸索了一天,Method.invoke() 会无限套娃,不知道还有没有其他方法。

public class MainHook implements IXposedHookLoadPackage {

    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

        // 要 Hook 的子类
        Class<?> clazzActivity = XposedHelpers.findClassIfExists(
            "com.example.MainActivity",
            lpparam.classLoader
        );
        
        // 要 Hook 的父类
        Class<?> clazzSuperActivity = clazzActivity.getSuperclass();

        // Hook 父类方法
        XposedHelpers.findAndHookMethod(clazzSuperActivity,
                "onCreate", Bundle.class,
                new XC_MethodHook() {});

        // Hook 子类方法
        XposedHelpers.findAndHookMethod(clazzActivity,
                "onCreate", Bundle.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        param.setResult(null);
                        Method method = clazzSuperActivity.getDeclaredMethod("onCreate", Bundle.class);
                        XposedBridge.invokeOriginalMethod(method, param.thisObject, param.args);
                    }
                });
       }
}

阅读全文

为 ssh 设置 shell

最近用 termux + tsu + sshd + zsh 远程,发现连接后使用的是 bash 而不是我默认的 zsh。

修改 /ect/profile~/.profile

# Force use zsh
zsh="/data/data/com.termux/files/usr/bin/zsh"
if [ "$SHELL" != "$zsh" -a -n "$SSH_TTY" -a -x "$zsh" ]; then
        export SHELL="$zsh"
        exec $zsh -l
fi

# ......

参考:bash - specify shell for ssh session

ssh 密码连接 Termux

网上都说只能通过秘钥连接,实则不然。用 passwd 命令设置一下密码就行了,用户名都不用。

# 设置 Termux 密码
$ passwd
New password:
Retype new password:
New password was successfully set.

# ssh 密码连接 Termux
$ ssh -p 8022 example.com
The authenticity of host '[example.com]:8022' can't be established.
ECDSA key fingerprint is SHA256:ABCDEFGHIJKLMNOPQRSTUVWXYZ+0123456789abcdef.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
[email protected]'s password: 

Welcome to Termux!

阅读全文