GithubHelp home page GithubHelp logo

working on ART runtime about dexposed HOT 17 OPEN

alibaba avatar alibaba commented on July 2, 2024
working on ART runtime

from dexposed.

Comments (17)

libfetion avatar libfetion commented on July 2, 2024

加油, Dexposed 是一个好东西,必将造福程序猿界!

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

Thank you very much! These suggestions are valuable. I will improve after evaluation.

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

There was some obstacle on uploading snapshot version to JCenter, so I upload 0.2.2 version for android 5.0 test. Can anybody help me to test this version, thank you!. Notice, 0.2.2 is still a snapshot version!

dependencies {
compile( 'com.taobao.android:dexposed:0.1.2@aar')
}

from dexposed.

frank-fan avatar frank-fan commented on July 2, 2024

@hwjump I found a problem when use dexposed on Android 5.1 System.
I found a 0.1.17 version of Dexposed in Maven Central, it support 5.1 system by default.
It seems that dexposed did not automatically load system api classes, like Toast.
First, I writed a test Patch, which hoke a ToastUtil, which code is below:

public class ToastUtil {
    private static Handler sMainHandler = new Handler(Looper.getMainLooper());

    public static void showMessage(final String text, final int duration) {
        if (Thread.currentThread().getId() != 1) {
            sMainHandler.post(new Runnable() {
                @Override
                public void run() {
                    showMessage(text, duration);
                }
            });
            return;
        }
        if (TextUtil.isEmptyOrNull(text)) {
            showMessage(R.string.action_error);
            return;
        }

        Toast t = Toast.makeText(APP.getInstance(), text, duration);
        t.setGravity(Gravity.CENTER, 0, 0);
        TextView tv = (TextView) t.getView().findViewById(android.R.id.message);
        if (tv != null) tv.setTextColor(APP.getInstance().getResources().getColor(R.color.white_light));

        t.getView().setBackgroundResource(R.drawable.progress_hud_bg);
        t.show();
    }
}

It's easy, just some utils code for Toast.

The patch code is like this:

public class TestPatch implements IPatch {

    private Handler mHandler = new Handler(Looper.getMainLooper());

    @Override
    public void handlePatch(PatchParam patchParam) throws Throwable {
        DexposedBridge.findAndHookMethod(
                Class.forName("cn.app.meiya.aa.util.ToastUtil"),
                "showMessage",
                String.class, int.class,
                new XC_MethodReplacement() {
                    @Override
                    protected Object replaceHookedMethod(final MethodHookParam methodHookParam) throws Throwable {
                        if (Thread.currentThread().getId() != 1) {
                            mHandler.post(new Runnable() {
                                @Override
                                public void run() {
                                    showFakeMessage(methodHookParam);
                                }
                            });
                        } else {
                            showFakeMessage(methodHookParam);
                        }
                        return null;
                    }
                }
        );
    }

    private void showFakeMessage(XC_MethodHook.MethodHookParam methodHookParam) {
        try {
            Context app = (Context) XposedHelpers.callStaticMethod(
                    Class.forName("com.meiyaapp.meiya.APP"), "getInstance");
            String text = (String) methodHookParam.args[0];
            int duration = (int) methodHookParam.args[1];

            Toast.makeText(app, "FAKE: \n" + text, Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Then, I package a "Test-Patch" apk and load it on main app, but it crashed when Call "ToastUtil.showMessage".

The crash only print this, can not find any stacktrace.

10-08 09:43:55.422  17987-17987/com.meiyaapp.meiya A/libc﹕ Fatal signal 11 (SIGSEGV), code 1, fault addr 0xbe98e2f4 in tid 17987 (.meiyaapp.meiya)

And I found strange that when I CALL this before a next ToastUtil.showMessage, the patch code WORK!

Toast.makeText(context, "Load success", Toast.LENGTH_LONG).show();

So I think, maybe Dexposed DID NOT automatically load system api classes.

I know currently Dexposed only support dalvik runtime for now, I post this just want to help to test ART Runtime.

from dexposed.

frank-fan avatar frank-fan commented on July 2, 2024

@hwjump
update:
I try to load classes in patch apk, but still NOT work.

 private void showFakeMessage(ClassLoader loader, XC_MethodHook.MethodHookParam methodHookParam) {
        try {
            Context app = (Context) XposedHelpers.callStaticMethod(
                    Class.forName("com.meiyaapp.meiya.APP"), "getInstance");
            String text = (String) methodHookParam.args[0];
            int duration = (int) methodHookParam.args[1];
            Log.d(TAG, "showFakeMessage: " + "before");
            Object toast = XposedHelpers.callStaticMethod(loader.loadClass("android.widget.Toast"), "makeText", "FAKE: \n" + text, 1);
            Log.d(TAG, "showFakeMessage: " + "Toast.makeText");
            XposedHelpers.callMethod(toast, "show");
            Log.d(TAG, "showFakeMessage: " + "Toast.show");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

It crashed on this line:
Object toast = XposedHelpers.callStaticMethod(loader.loadClass("android.widget.Toast"), "makeText", "FAKE: \n" + text, 1);

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

@fanxu123 could you tell me your phone type and android version, 5.0 or 5.1?

from dexposed.

frank-fan avatar frank-fan commented on July 2, 2024

@hwjump Nexus 5, Android 5.1, Stock

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

thank you! dexposed 0.1.7 was still a snapshot for art. I found it cann't do some system ui relative class in XC_MethodReplacement.

from dexposed.

frank-fan avatar frank-fan commented on July 2, 2024

@hwjump Btw, if I want use it on my product version only for pre-5.0, arm device, which version should I use, 0.1.1? 0.1.7?

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

@fanxu123 sorry,If I support art, I will change the README.md. for pre-5.0, you can use 0.1.1

from dexposed.

frank-fan avatar frank-fan commented on July 2, 2024

@hwjump Thanks!

from dexposed.

owenchow avatar owenchow commented on July 2, 2024

我想问下,dexposed支持混淆后的包么?混淆后类名方法名会被修改了,怎么hook呢?

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

@owenchow You should keep the proguard mapping. Then hook the method with proguarded name.
Plz refer this #5

from dexposed.

owenchow avatar owenchow commented on July 2, 2024

再问下,怎么修改重载函数,findAndHookMethod只能找到方法名,如果是重载了,怎么区分?

from dexposed.

jhdxr avatar jhdxr commented on July 2, 2024

@owenchow findAndHookMethod的函数原型是findAndHookMethod(类名, 方法名, 参数1的class, 参数2的class, ... , Hook func)
所以是可以区分重载的。。。

from dexposed.

hwjump avatar hwjump commented on July 2, 2024

Now I rewriter the hook core for Art, it may still have some crash, it need test, you can get it on "dev_art" branch.

from dexposed.

deadlineOvO avatar deadlineOvO commented on July 2, 2024

问题来了,在一年多后的今天
dexposed还会有更新吗?

from dexposed.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.