package com.fei_ke.crashreport;

import android.app.Application;
import android.content.Intent;

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 Hook implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
        XposedHelpers.findAndHookMethod(Application.class, "onCreate", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                Application context = (Application) param.thisObject;
                hookDefaultExceptionHandle(context);
            }
        });
    }

    private void hookDefaultExceptionHandle(final Application context) {
        Class<?> classHandler = Thread.getDefaultUncaughtExceptionHandler().getClass();
        XposedHelpers.findAndHookMethod(classHandler, "uncaughtException", Thread.class, Throwable.class,
                new XC_MethodHook() {
                    @Override
                    protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                        Intent intent = CrashReportReceiver.getCrashBroadCastIntent((Throwable) param.args[1], context.getPackageName());
                        context.sendBroadcast(intent);
                    }
                });
    }
}

@@ -454,32 +454,118 @@
 ows Throwable %7B%0A
+        if (BuildConfig.APPLICATION_ID.equals(loadPackageParam.packageName)) return;%0A%0A
         XposedHe
@@ -682,38 +682,37 @@
  protected void 
-before
+after
 HookedMethod(Met
@@ -991,240 +991,99 @@
     
-Class%3C?%3E classHandler = Thread.getDefaultUncaughtExceptionHandler().getClass();%0A        XposedHelpers.findAndHookMethod(classHandler, %22uncaughtException%22, Thread.class, Throwable.class,%0A                new XC_MethodHook() %7B%0A        
+Thread.UncaughtExceptionHandler exceptionHandler = new Thread.UncaughtExceptionHandler() %7B%0A
     
@@ -1116,79 +1116,47 @@
     
-    
-    protected void beforeHookedMethod(MethodHookParam param) throws
+public void uncaughtException(Thread t,
  Thr
@@ -1158,34 +1158,29 @@
 , Throwable 
-%7B%0A        
+e) %7B%0A
             
@@ -1247,33 +1247,9 @@
 ent(
-(Throwable) param.args%5B1%5D
+e
 , co
@@ -1273,24 +1273,16 @@
 ame());%0A
-        
         
@@ -1320,32 +1320,56 @@
 ntent);%0A        
+        System.exit(1);%0A
             %7D%0A  
@@ -1374,24 +1374,27 @@
         
+%7D;%0A
         
 %7D);%0A    
@@ -1377,28 +1377,163 @@
      %7D;%0A        
-%7D
+Thread.currentThread().setUncaughtExceptionHandler(exceptionHandler);%0A        Thread.setDefaultUncaughtExceptionHandler(exceptionHandler
 );%0A    %7D%0A%7D%0A

Update Hook