fix:实现自动获取handler类以及创建实例,减少手动创建handler实例的工作

This commit is contained in:
lateautumn4lin 2020-09-15 16:11:25 +08:00
parent 087152a4a6
commit a1fc988c48
6 changed files with 21 additions and 30 deletions

View File

@ -24,11 +24,15 @@ android {
exclude 'META-INF/INDEX.LIST' exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/io.netty.versions.properties' exclude 'META-INF/io.netty.versions.properties'
} }
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
} }
repositories { repositories {
jcenter() jcenter()
maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
@ -37,6 +41,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
implementation 'org.apache.commons:commons-lang3:3.9'
compileOnly 'de.robv.android.xposed:api:82' compileOnly 'de.robv.android.xposed:api:82'
compileOnly 'de.robv.android.xposed:api:82:sources' compileOnly 'de.robv.android.xposed:api:82:sources'
androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.ext:junit:1.1.2'

View File

@ -27,21 +27,6 @@ import static java.util.Arrays.asList;
*/ */
public class Config { public class Config {
private static HashMap propertiesAssistant = PropertiesAssistant.getJsonProperties(); private static HashMap propertiesAssistant = PropertiesAssistant.getJsonProperties();
// 预先把handlers文件夹下面的类实现
private static List<SekiroRequestHandler> handlers = asList(
(SekiroRequestHandler) new KuaishouHandler()
);
private static HashMap<String, SekiroRequestHandler> handlers_map = GenerateHandlersMap();
private static HashMap<String, SekiroRequestHandler> GenerateHandlersMap() {
HashMap<String, SekiroRequestHandler> map = new HashMap<String, SekiroRequestHandler>();
for (SekiroRequestHandler obj : handlers) {
map.put(obj.getClass().getName(), obj);
}
return map;
}
private static String client_id = null; private static String client_id = null;
/** /**
* The Groups. * The Groups.
@ -142,15 +127,4 @@ public class Config {
} }
return inner_hook_packages; return inner_hook_packages;
} }
/**
* Get hanler instance list.
*
* @param class_name the class name
* @return the list
*/
public static SekiroRequestHandler GetHanlerInstance(String class_name) {
return handlers_map.get(class_name);
}
} }

View File

@ -11,6 +11,7 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import com.lateautumn4lin.headwolf.MyApplication;
import com.lateautumn4lin.headwolf.commons.Logger; import com.lateautumn4lin.headwolf.commons.Logger;
import java.io.File; import java.io.File;
@ -33,11 +34,14 @@ import de.robv.android.xposed.callbacks.XC_LoadPackage;
* The type Base entry. 第一层Hook入口 * The type Base entry. 第一层Hook入口
*/ */
public class BaseEntry implements IXposedHookLoadPackage { public class BaseEntry implements IXposedHookLoadPackage {
private String modulePackage = "com.lateautumn4lin.headwolf"; private static String modulePackage = MyApplication.class.getPackage().getName();
private static List<String> hookPackages = new ArrayList<String>(); private static List<String> hookPackages = new ArrayList<String>();
private final String handleHookClass = RealEntry.class.getName(); private final String handleHookClass = RealEntry.class.getName();
private final String handleHookMethod = "handleLoadPackage"; private final String handleHookMethod = "handleLoadPackage";
private static BlockingQueue blockingQueue = new ArrayBlockingQueue<>(30); private static BlockingQueue blockingQueue = new ArrayBlockingQueue<>(30);
/**
* The constant threadPoolExecutor.
*/
public static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(50, 50, 1, TimeUnit.MINUTES, blockingQueue); public static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(50, 50, 1, TimeUnit.MINUTES, blockingQueue);
static { static {

View File

@ -29,7 +29,7 @@ public class RealEntry implements IXposedHookLoadPackage {
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable { public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam loadPackageParam) throws Throwable {
try { try {
// 测试 // 测试
Logger.logi("5555"); Logger.logi("999");
Logger.logi(String.format("Begin Real Hook Logic About:%s", loadPackageParam.packageName)); Logger.logi(String.format("Begin Real Hook Logic About:%s", loadPackageParam.packageName));
// step1:获取context // step1:获取context
Context context = (Context) XposedHelpers.callMethod( Context context = (Context) XposedHelpers.callMethod(

View File

@ -11,9 +11,12 @@ import android.os.Bundle;
import com.lateautumn4lin.headwolf.Config; import com.lateautumn4lin.headwolf.Config;
import com.lateautumn4lin.headwolf.commons.Logger; import com.lateautumn4lin.headwolf.commons.Logger;
import com.lateautumn4lin.headwolf.entry.RealEntry;
import com.lateautumn4lin.headwolf.handlers.KuaishouHandler;
import com.virjar.sekiro.api.SekiroClient; import com.virjar.sekiro.api.SekiroClient;
import com.virjar.sekiro.api.SekiroRequestHandler; import com.virjar.sekiro.api.SekiroRequestHandler;
import java.lang.reflect.Constructor;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;

View File

@ -13,6 +13,8 @@ import android.content.Context;
import com.lateautumn4lin.headwolf.Config; import com.lateautumn4lin.headwolf.Config;
import com.lateautumn4lin.headwolf.commons.Logger; import com.lateautumn4lin.headwolf.commons.Logger;
import com.lateautumn4lin.headwolf.entry.RealEntry;
import com.lateautumn4lin.headwolf.handlers.KuaishouHandler;
import com.virjar.sekiro.api.SekiroRequestHandler; import com.virjar.sekiro.api.SekiroRequestHandler;
import java.io.File; import java.io.File;
@ -107,7 +109,10 @@ public final class ClassesReaderAssistant {
if (((String) belong_name).equals(associateName)) { if (((String) belong_name).equals(associateName)) {
Method getAction = cls.getDeclaredMethod("getAction"); Method getAction = cls.getDeclaredMethod("getAction");
Object action = getAction.invoke(instance); Object action = getAction.invoke(instance);
associate_handlers.put((String) action, Config.GetHanlerInstance(cls.getName())); Class classloader = RealEntry.class.getClassLoader().loadClass(cls.getName());
Constructor handler_constructor = classloader.getConstructor();
Object handler = handler_constructor.newInstance();
associate_handlers.put((String) action, (SekiroRequestHandler) handler);
} }
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
Logger.loge(String.format("Can't Find Method:getBelong For %s", packageName)); Logger.loge(String.format("Can't Find Method:getBelong For %s", packageName));