package ca.pr0ps.xposed.entrustunblocker;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

public class Unblocker implements IXposedHookLoadPackage {

  @Override
  public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
    if (!lpparam.packageName.equals("com.entrust.identityGuard.mobile"))
      return;

    //Before 2015-12-15
    try {
      findAndHookMethod("com.entrust.identityGuard.mobile.Splash", lpparam.classLoader, "isDeviceSecure", new XC_MethodReplacement() {
        @Override
        protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
          return false;
        }
      });
      return;
    }
    catch (NoSuchMethodError e){}

    //v3.1.0.32 - Released on 2015-12-15
    try {
      findAndHookMethod("com.entrust.identityGuard.mobile.sdk.PlatformDelegate", lpparam.classLoader, "isDeviceSecure", new XC_MethodReplacement() {
        @Override
        protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable {
          return false;
        }
      });
      return;
    }
    catch (NoSuchMethodError e){}

    XposedBridge.log("WARNING: Found Entrust IdentityGuard app but couldn't find a method to patch - this version of the app probably isn't supported yet");
  }
}

@@ -941,33 +941,39 @@
 SuchMethodError 
-e
+ignored
 )%7B%7D%0A%0A    //v3.1.
@@ -1369,17 +1369,442 @@
 odError 
-e
+ignored)%7B%7D%0A%0A    //v3.2.0.96 - Released on 2017-05-03%0A    try%7B%0A      findAndHookMethod(%22com.entrust.identityGuard.mobile.sdk.PlatformDelegate%22, lpparam.classLoader, %22isDeviceRooted%22, new XC_MethodReplacement() %7B%0A        @Override%0A        protected Object replaceHookedMethod(MethodHookParam methodHookParam) throws Throwable %7B%0A          return false;%0A        %7D%0A      %7D);%0A      return;%0A    %7D%0A    catch (NoSuchMethodError ignored
 )%7B%7D%0A%0A   

Fix incompatibility with Entrust ST v3.2.0.96