XposedHookMethods

public class Main implements IXposedHookLoadPackage
{
    /*
         :
      hook  :  hook          
    hook_method(  ,    ,   ,        )
           : java    java   
    Object...   :  java varag  ,                 ,               
    */
    private void hook_method(String className,ClassLoader classLoader,String methodName,Object...parameterTypesAndCall){
        try{
            //                
            XposedHelpers.findAndHookMethod(className,classLoader,methodName,parameterTypesAndCallback);
        }catch(Exception e){
            XposedBridge.log(e);
        }
    }
    /*
         :
      hook  :       hook   

    hook_methods(  ,   ,    )
           XC_MethodHook   XC_MethodReplacement

    Class>clazz = Class.forName(className);
      :  JVM        ,     java.lang.Class           。         ,      Class  。
      java.lang.Class      forName()       className,          。
        clazz.newInstance()    className       。
        
       Class>clazz    clazz         Class  。

    java.lang.reflect.Modifier.isPublic(int mod)        mod    public   ,   true,    false

    java.lang.reflect.Modifier.isAbstract(int mod)            abstract   ,   true,    false

    java.lang.reflect.Method.getModifiers()      Method        Java           。 Modifier         。

    java.lang.Class.getDeclaredMethods()       Method     ,    ,  ,  ( )       ,
             。          0   ,         

    */
    private void hook_methods(String className, String methodName, XC_MethodHook xc_methodHook) {
        try {
            Class> clazz = Class.forName(className); //  
            for (Method method : clazz.getDeclaredMethods())
                //   (             hook       &&             abstract   ,   true,    false &&
                //             public   ,   true,    false )
                if (method.getName().equals(methodName) && !Modifier.isAbstract(method.getModifiers()) && Modifier.isPublic(method.getModifiers())) {
                    XposedBridge.hookMethod(method, xc_methodHook); 
                }
        } catch (Exception e) {
            XposedBridge.log(e);
        }
    }
    
    /*
    java.lang.Throwable    Java             。      (       )      Java     ,    Java throw    

             MethodHookParam param     2   :
    1.param.args[0]:             ,    Object
    2.param.getResult():            ,    Object

    */

    @Override
    public void handleLoadPackage(final LoadPackageParam lpp )throws Throwable{
        //            ,            ,            hook  ,            
        hook_method("android.telephony.TelephonyManager",lpp.classLoader,"getDeviceId",new XC_MethodHook(){
            @Override //MethodHookParam       
            protected void afterHookedMethod(MethodHookParam param) throws Throwable{
                /*
                     
                  :
                Object obj = param.getResult();
                param.setResult("chen sheng");
                */
            }
        });

    }
}

***********************************************************************************************************************************
   hook    imei  ,   Hook         :
  1:         getLastKnowLocation()                  。
  2:               onLocationChanged()    
    LocationListener locationListener = new LocationListener(){
    ....
    ....
    ....
        //    
        @Override
        public void onLocationChanged(Location location){
            showLocation(location);
        }
    }
    

    Hook   :
    hook_methods("android.location.LocationManager","getLastKnowLocation",new XC_MethodHook(){
        @Override
        protected void afterHookMethod(MethodHookParam param) throws Throwable{
            Location l = new Location(LocationManager.PASSIVE_PROVIEDR);
            double lo = -10000d;
            double la = -10000d;
            l.setLatitude(lo);
            l.setLongitude(la);
            param.setResult(l);
        }
    });

    Hook   :
      :
                 requestLocationUpdates()
                  ,       
                Location      ,        
    hook_methods("android.location.LocationManager","getLastKnowLocation",new XC_MethodHook(){
        @Override
        protected void afterHookMethod(MethodHookParam param) throws Throwable{
            if(param.args.length == 4 && (param.args[0] instanceof String)){
                LocationListener ll = (LocationListener)param.args[3];
                Class> clazz = LocationListener.class;
                Method m = null;
                for(Method method: clazz.getDeclaredMethods()){
                    if(method.getName.equals("onLocationChanged")){
                        m = method;
                        break;
                    }
                }
                try{
                    if(m != null){
                        Object[] args = new Object[1];
                        Location l = new Location(LocationManager.PASSIVE_PROVIDER);
                        double lo = -10000d;
                        double la = -10000d;
                        l.setLatitude(lo);
                        l.setLongitude(la);
                        args[0]=l;
                        m.invoke(ll,args);
                    }
                }catch(Exception e){
                    XposedBridge.log(e);
                }
            }
        }
    });

 
다음으로 전송:https://www.cnblogs.com/zuimeiyujianni/p/8511719.html

좋은 웹페이지 즐겨찾기