Commit 59cb90c1 authored by Administrator's avatar Administrator

udpate

parent 6f57a0a6
include ':XposedDriver' include ':XposedDriver', ':stub'
include 'super-appium' include 'super-appium'
apply plugin: 'java-library'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'com.google.android:android:4.1.1.4'
}
sourceCompatibility = "7"
targetCompatibility = "7"
package android.util;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
public class ArrayMap <K, V> implements Map<K, V> {
@Override
public int size() {
return 0;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean containsKey(Object o) {
return false;
}
@Override
public boolean containsValue(Object o) {
return false;
}
@Override
public V get(Object o) {
return null;
}
@Override
public V put(K k, V v) {
return null;
}
@Override
public V remove(Object o) {
return null;
}
@Override
public void putAll(Map<? extends K, ? extends V> map) {
}
@Override
public void clear() {
}
@Override
public Set<K> keySet() {
return null;
}
@Override
public Collection<V> values() {
return null;
}
@Override
public Set<Entry<K, V>> entrySet() {
return null;
}
}
...@@ -6,6 +6,7 @@ dependencies { ...@@ -6,6 +6,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly 'com.google.android:android:4.1.1.4' compileOnly 'com.google.android:android:4.1.1.4'
compileOnly 'org.projectlombok:lombok:1.18.2' compileOnly 'org.projectlombok:lombok:1.18.2'
compileOnly project(':stub')
annotationProcessor 'org.projectlombok:lombok:1.18.2' annotationProcessor 'org.projectlombok:lombok:1.18.2'
} }
......
...@@ -9,6 +9,9 @@ import com.virjar.superappium.traversor.Collector; ...@@ -9,6 +9,9 @@ import com.virjar.superappium.traversor.Collector;
import com.virjar.superappium.traversor.Evaluator; import com.virjar.superappium.traversor.Evaluator;
import com.virjar.superappium.util.Constants; import com.virjar.superappium.util.Constants;
import com.virjar.superappium.util.Lists; import com.virjar.superappium.util.Lists;
import com.virjar.superappium.xpath.XpathParser;
import com.virjar.superappium.xpath.model.XNode;
import com.virjar.superappium.xpath.model.XNodes;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -183,4 +186,13 @@ public class ViewImage { ...@@ -183,4 +186,13 @@ public class ViewImage {
} }
return jsonObject.toString(); return jsonObject.toString();
} }
public ViewImages xpath(String xpath) {
return XpathParser.compileNoError(xpath).evaluateToElement(new XNodes(XNode.e(this)));
}
public String xpath4String(String xpath) {
return XpathParser.compileNoError(xpath).evaluateToSingleString(new XNodes(XNode.e(this)));
}
} }
package com.virjar.superappium.promise;
import android.app.Activity;
import com.virjar.superappium.ViewImage;
public interface ActivityObserver {
void onActivity(Activity activity, ViewImage viewImage);
}
package com.virjar.superappium.promise;
import android.app.Activity;
public interface FocusActivityOccurEvent {
boolean onFocusActivityOccur(Activity activity);
void onActivityEmpty();
//onLostFocus
void onAppBackend();
}
package com.virjar.superappium.promise;
import android.app.Activity;
import android.os.Handler;
import android.os.Looper;
import android.util.ArrayMap;
import com.virjar.superappium.util.ReflectUtil;
public class MainThreadEventLoop {
private static Object mainThread = ReflectUtil.getMainThread();
private static Handler mainThreadHandler = new Handler(Looper.getMainLooper());
// private static LinkedList<EventTaskDriver> mTaskQueue = new LinkedList<>();
//
//
// private static class EventTaskDriver implements Runnable {
// @Override
// public void run() {
// if (mTaskQueue.size() == 0) {
// mainThreadHandler.postDelayed(this, 500);
// return;
// }
// mainThreadHandler.post(mTaskQueue.removeFirst());
// }
// }
public static void runOnFocusActivity(FocusActivityOccurEvent focusActivityOccurEvent) {
if (Looper.myLooper() == Looper.getMainLooper()) {
findAndFire(focusActivityOccurEvent);
} else {
mainThreadHandler.post(() -> findAndFire(focusActivityOccurEvent));
}
}
private static void findAndFire(FocusActivityOccurEvent focusActivityOccurEvent) {
ArrayMap mActivities = ReflectUtil.getObjectField(mainThread, "mActivities");
Activity topActivity = null;
if (mActivities.values().size() == 0) {
focusActivityOccurEvent.onActivityEmpty();
return;
}
for (Object activityClientRecord : mActivities.values()) {
Activity tempActivity = ReflectUtil.getObjectField(activityClientRecord, "activity");
if (tempActivity.hasWindowFocus()) {
topActivity = tempActivity;
break;
}
}
if (topActivity == null) {
focusActivityOccurEvent.onAppBackend();
return;
}
focusActivityOccurEvent.onFocusActivityOccur(topActivity);
}
}
package com.virjar.superappium.util;
import android.util.Log;
import java.lang.reflect.Method;
//
// Created by Swift Gan on 2019/3/15.
//
//bypass hidden api on Android 9 - 10
public class HiddenAPIEnforcementPolicyUtils {
private static Method forNameMethod;
private static Method getMethodMethod;
static Class vmRuntimeClass;
static Method addWhiteListMethod;
static Object vmRuntime;
static {
try {
getMethodMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
forNameMethod = Class.class.getDeclaredMethod("forName", String.class);
vmRuntimeClass = (Class) forNameMethod.invoke(null, "dalvik.system.VMRuntime");
addWhiteListMethod = (Method) getMethodMethod.invoke(vmRuntimeClass, "setHiddenApiExemptions", new Class[]{String[].class});
Method getVMRuntimeMethod = (Method) getMethodMethod.invoke(vmRuntimeClass, "getRuntime", null);
vmRuntime = getVMRuntimeMethod.invoke(null);
} catch (Exception e) {
Log.e("ReflectionUtils", "error get methods", e);
}
}
public static boolean passApiCheck() {
try {
addReflectionWhiteList("Landroid/",
"Lcom/android/",
"Ljava/lang/",
"Ldalvik/system/",
"Llibcore/io/",
"Lsun/misc/"
);
return true;
} catch (Throwable throwable) {
Log.w(Constants.TAG, "pass Hidden API enforcement policy failed", throwable);
return false;
}
}
//methidSigs like Lcom/swift/sandhook/utils/ReflectionUtils;->vmRuntime:java/lang/Object; (from hidden policy list)
private static void addReflectionWhiteList(String... memberSigs) throws Throwable {
addWhiteListMethod.invoke(vmRuntime, new Object[]{memberSigs});
}
}
...@@ -3,6 +3,7 @@ package com.virjar.superappium.util; ...@@ -3,6 +3,7 @@ package com.virjar.superappium.util;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Application; import android.app.Application;
import android.os.Handler;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
...@@ -33,6 +34,15 @@ public class ReflectUtil { ...@@ -33,6 +34,15 @@ public class ReflectUtil {
return (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); return (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
} }
@SuppressLint("PrivateApi")
public static Object getMainThread() {
try {
return Class.forName("android.app.ActivityThread").getMethod("currentActivityThread").invoke(null);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static void makeAccessible(Field field) { private static void makeAccessible(Field field) {
if (!Modifier.isPublic(field.getModifiers())) { if (!Modifier.isPublic(field.getModifiers())) {
field.setAccessible(true); field.setAccessible(true);
...@@ -52,7 +62,7 @@ public class ReflectUtil { ...@@ -52,7 +62,7 @@ public class ReflectUtil {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> T getFieldValue(Object object, String fieldName) { public static <T> T getObjectField(Object object, String fieldName) {
try { try {
return (T) findField(object.getClass(), fieldName).get(object); return (T) findField(object.getClass(), fieldName).get(object);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
...@@ -934,4 +944,7 @@ public class ReflectUtil { ...@@ -934,4 +944,7 @@ public class ReflectUtil {
} }
return toClass.isAssignableFrom(cls); return toClass.isAssignableFrom(cls);
} }
} }
...@@ -21,7 +21,16 @@ public abstract class XpathEvaluator { ...@@ -21,7 +21,16 @@ public abstract class XpathEvaluator {
return XpathUtil.transformToString(evaluate(xNodes)); return XpathUtil.transformToString(evaluate(xNodes));
} }
public List<ViewImage> evaluateToElement(XNodes xNodes) {
public String evaluateToSingleString(XNodes xNodes) {
List<String> strings = evaluateToString(xNodes);
if (strings.size() == 0) {
return null;
}
return strings.get(0);
}
public ViewImages evaluateToElement(XNodes xNodes) {
return XpathUtil.transformToElement(evaluate(xNodes)); return XpathUtil.transformToElement(evaluate(xNodes));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment