package com.pyler.nodevicecheck;

import java.io.File;

import org.json.JSONObject;

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.LoadPackageParam;

public class NoDeviceCheck implements IXposedHookLoadPackage {
	@Override
	public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
		if ("android".equals(lpparam.packageName)) {
            		XposedHelpers.findAndHookMethod(File.class, "exists",
                    		new XC_MethodHook() {
                        @Override
                        protected void beforeHookedMethod(MethodHookParam param)
                                throws Throwable {
                            File file = (File) param.thisObject;
                            // Disable check for enforced SELinux state
                            if (new File("/sys/fs/selinux/enforce").equals(file)) {
                                param.setResult(true);
                                return;
                            }
                            
                            // Disable check for SU binary files
                            if (new File("/system/bin/su").equals(file) || new File("/system/xbin/su").equals(file)) {
                                param.setResult(false);
                                return;
                            }
                        }
                    });
		}
		
		XposedHelpers.findAndHookMethod(JSONObject.class, "getBoolean",
				String.class, new XC_MethodHook() {
					@Override
					protected void beforeHookedMethod(MethodHookParam param)
							throws Throwable {
						String name = (String) param.args[0];
						// Modify server response to pass CTS check
						if ("ctsProfileMatch".equals(name)
								|| "isValidSignature".equals(name)) {
							param.setResult(true);
							return;
						}
					}
				});
	}
}

@@ -38,49 +38,49 @@
 ort 
-java.io.File;%0A%0Aimport org.json.JSONObject
+org.json.JSONObject;%0A%0Aimport java.io.File
 ;%0A%0Ai
@@ -359,17 +359,20 @@
 ckage %7B%0A
-%09
+    
 @Overrid
@@ -373,17 +373,20 @@
 verride%0A
-%09
+    
 public v
@@ -452,18 +452,24 @@
 wable %7B%0A
-%09%09
+        
 if (%22and
@@ -517,18 +517,16 @@
         
-%09%09
 XposedHe
@@ -591,18 +591,16 @@
         
-%09%09
 new XC_M
@@ -844,16 +844,18 @@
 Object;%0A
+%0A%0A
         
@@ -1131,36 +1131,8 @@
   %7D%0A
-                            
 %0A   
@@ -1430,32 +1430,600 @@
               %7D%0A
+                            if (new File(%22/system/framework/XposedBridge.jar%22).equals(file) %7C%7C new File(%22/system/framework/XposedBridge.jar%22).equals(file)) %7B%0A                                param.setResult(false);%0A                                return;%0A                            %7D%0A                            if (new File(%22/system/framework/XposedBridge.jar%22).equals(file) %7C%7C new File(%22/system/framework/XposedBridge.jar%22).equals(file)) %7B%0A                                param.setResult(false);%0A                                return;%0A                            %7D%0A
                 
@@ -2060,17 +2060,27 @@
 %7D);%0A
-%09%09%7D%0A%09%09%0A%09%09
+        %7D%0A%0A        
 Xpos
@@ -2139,20 +2139,32 @@
 olean%22,%0A
-%09%09%09%09
+                
 String.c
@@ -2195,28 +2195,58 @@
 ) %7B%0A
-%09%09%09%09%09@Override%0A%09%09%09%09%09
+                    @Override%0A                    
 prot
@@ -2302,40 +2302,79 @@
 am)%0A
-%09%09%09%09%09%09%09throws Throwable %7B%0A%09%09%09%09%09%09
+                            throws Throwable %7B%0A                        
 Stri
@@ -2407,22 +2407,40 @@
 rgs%5B0%5D;%0A
-%09%09%09%09%09%09
+                        
 // Modif
@@ -2475,22 +2475,40 @@
 S check%0A
-%09%09%09%09%09%09
+                        
 if (%22cts
@@ -2538,16 +2538,40 @@
 me)%0A
-%09%09%09%09%09%09%09%09
+                                
 %7C%7C %22
@@ -2608,77 +2608,167 @@
 ) %7B%0A
-%09%09%09%09%09%09%09param.setResult(true);%0A%09%09%09%09%09%09%09return;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D);%0A%09
+                            param.setResult(true);%0A                            return;%0A                        %7D%0A                    %7D%0A                %7D);%0A    
 %7D%0A%7D%0A

Add better logging