[原创]记一次中联X科的试岗实战项目
2023-4-4 18:1:26 Author: bbs.pediy.com(查看原文) 阅读量:7 收藏

package com.example.xposeddemo;

import android.app.Activity;

import android.content.ContentResolver;

import android.content.Context;

import android.database.Cursor;

import android.net.Uri;

import android.os.Bundle;

import android.util.Log;

import android.view.Gravity;

import android.view.ViewGroup;

import android.widget.FrameLayout;

import android.widget.TextView;

import android.widget.Toast;

import android.content.ContentResolver;

import java.lang.reflect.Method;

import java.util.ArrayList;

import java.util.List;

import de.robv.android.xposed.IXposedHookLoadPackage;

import de.robv.android.xposed.XC_MethodHook;

import de.robv.android.xposed.XposedHelpers;

import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class Main implements IXposedHookLoadPackage {

    private String packageName = "com.whatsapp";

    private String className = packageName + ".contact.picker.ContactPicker";

    Context context;

    @Override

    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {

        hookMainAcivityInit(loadPackageParam);

        hookAnonymousInternalClass(loadPackageParam);

    }

    private void hookMainAcivityInit(XC_LoadPackage.LoadPackageParam loadPackageParam)

    {

        String packageName = loadPackageParam.packageName;

        if(!packageName.equals(packageName))

            return;

        Class hookClass = XposedHelpers.findClass(

                className,loadPackageParam.classLoader);

        XposedHelpers.findAndHookConstructor(

                hookClass,

                new XC_MethodHook() {

                    @Override

                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

                        super.beforeHookedMethod(param);

                        context = (Context) param.thisObject;

                    }

                }

        );

    }

        private void hookAnonymousInternalClass(XC_LoadPackage.LoadPackageParam loadPackageParam) {

        if(loadPackageParam.packageName.equals(packageName)){

            Log.d("lxz","xposed loading");

            final Class<?> mMainActivity = XposedHelpers.findClass(className,loadPackageParam.classLoader);

            XposedHelpers.findAndHookMethod(mMainActivity, "onCreate", Bundle.class, new XC_MethodHook() {

                @Override

                protected void afterHookedMethod(MethodHookParam param) throws Throwable {

                    super.afterHookedMethod(param);

                    final Activity mActivity = (Activity) param.thisObject;

                    Log.d("lxz","onCreate已加载...");

                    // 创建一个 TextView

                    TextView textView = new TextView(context);

                    // 创建布局,设置参数

                    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(

                            ViewGroup.LayoutParams.WRAP_CONTENT,

                            ViewGroup.LayoutParams.WRAP_CONTENT);

                    // 设置控件到底端的距离

                    params.bottomMargin = 0;

                    // 设置控件的位置

                    params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;

                    List<PersonInfo> personInfoList = new ArrayList<>();

                    ContentResolver resolver = context.getContentResolver();

                    Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");

                    Cursor cursor = resolver.query(uri,new String[]{"_id","display_name"},null,null,null,null);

                    if(cursor != null)

                    {

                        while (cursor.moveToNext())

                        {

                            int id = cursor.getInt(0);

                            String name = cursor.getString(1);

                            Log.d("lxz","id = " + id + "    name = " + name);

                            uri = Uri.parse("content://com.android.contacts/raw_contacts/"+id+"/data");

                            Cursor cursor2 = resolver.query(uri,new String[]{"mimetype","raw_contact_id","data1"},null,null,null,null);

                            PersonInfo personInfo = new PersonInfo();

                            while(cursor2.moveToNext())

                            {

                                String mimetype = cursor2.getString(0);

                                int raw_contact_id = cursor2.getInt(1);

                                String data1 = cursor2.getString(2);

                                Log.d("lxz", "minetype = " + mimetype + " address = " + data1);

                                personInfo.set_id(raw_contact_id);

                                if(mimetype.equals("vnd.android.cursor.item/phone_v2"))

                                {

                                    personInfo.setNumber(data1);

                                } else if (mimetype.equals("vnd.android.cursor.item/postal-address_v2")) {

                                    personInfo.setAddress(data1);

                                } else if (mimetype.equals("vnd.android.cursor.item/email_v2")) {

                                    personInfo.setEmail(data1);

                                } else if (mimetype.equals("vnd.android.cursor.item/name")) {

                                    personInfo.setName(data1);

                                }

                            }

                            personInfoList.add(personInfo);

                        }

                    }

                    String ss = new String();

                    for (PersonInfo personInfo : personInfoList)

                    {

                        Log.d("lxz",personInfo.toString());

                        ss = ss + personInfo.toString();

                    }

                    textView.setText(ss);

                    // 添加 TextView 到 Activity 中

                    mActivity.addContentView(textView,params);

                }

            });

        }

    }

}


文章来源: https://bbs.pediy.com/thread-276749.htm
如有侵权请联系:admin#unsafe.sh