package com.fei_ke.crashreport;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

public class Hook implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam)
            throws Throwable {
        if (loadPackageParam.packageName.equals("android")) {
            Class<?> classAppError = XposedHelpers.findClass("com.android.server.am.AppErrors",
                    loadPackageParam.classLoader);
            XposedBridge.hookAllMethods(classAppError, "crashApplicationInner",
                    new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                            Object processRecord = param.args[0];
                            ApplicationInfo info = (ApplicationInfo) XposedHelpers.getObjectField(
                                    processRecord, "info");
                            String packageName = info.packageName;

                            Object crashInfo = param.args[1];
                            String message = (String) XposedHelpers.getObjectField(crashInfo,
                                    "exceptionMessage");
                            String stackTrace = (String) XposedHelpers.getObjectField(crashInfo,
                                    "stackTrace");

                            Context context = (Context) XposedHelpers.getObjectField(
                                    param.thisObject, "mContext");

                            Intent intent = CrashReportReceiver.getCrashBroadCastIntent(packageName,
                                    message, stackTrace);
                            context.sendBroadcast(intent);
                        }
                    });
        }
    }
}

@@ -718,36 +718,16 @@
 Errors%22,
-%0A                   
  loadPac
@@ -829,36 +829,16 @@
 nInner%22,
-%0A                   
  new XC_
@@ -868,24 +868,16 @@
         
- 
-       
 @Overrid
@@ -878,24 +878,16 @@
 verride%0A
-        
         
@@ -986,32 +986,24 @@
             
-      
-  
 Object proce
@@ -1028,24 +1028,16 @@
 rgs%5B0%5D;%0A
-        
         
@@ -1122,45 +1122,8 @@
 eld(
-%0A                                    
 proc
@@ -1138,32 +1138,24 @@
 d, %22info%22);%0A
-        
             
@@ -1218,32 +1218,24 @@
             
-      
-  
 Object crash
@@ -1256,24 +1256,16 @@
 rgs%5B1%5D;%0A
-        
         
@@ -1345,44 +1345,8 @@
 nfo,
-%0A                                   
  %22ex
@@ -1359,32 +1359,24 @@
 nMessage%22);%0A
-        
             
@@ -1455,44 +1455,8 @@
 nfo,
-%0A                                   
  %22st
@@ -1464,32 +1464,24 @@
 ckTrace%22);%0A%0A
-        
             
@@ -1549,45 +1549,8 @@
 eld(
-%0A                                    
 para
@@ -1573,32 +1573,24 @@
 Context%22);%0A%0A
-        
             
@@ -1673,44 +1673,8 @@
 ame,
-%0A                                   
  mes
@@ -1692,24 +1692,16 @@
 Trace);%0A
-        
         
@@ -1763,26 +1763,10 @@
     
-        %7D%0A        
+%7D%0A
     

format code