From 0aba374b02d557d20730895d90c40cf6f87fa8f0 Mon Sep 17 00:00:00 2001 From: Fankesyooni Date: Mon, 14 Feb 2022 04:21:18 +0800 Subject: [PATCH] Release 1.0 available --- README.md | 3 +- yukihookapi-ksp-xposed/build.gradle | 26 +++++-- yukihookapi/build.gradle | 25 ++++-- .../hook/utils/ReflectionUtils.java | 76 +++---------------- 4 files changed, 45 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index abe0ca83..6ae1a4c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Yuki Hook API (完善中) +# Yuki Hook API ![Eclipse Marketplace](https://img.shields.io/badge/build-passing-brightgreen) ![Eclipse Marketplace](https://img.shields.io/badge/license-MIT-blue) @@ -49,7 +49,6 @@ # Get Started -- ❗相关依赖暂未上传 Maven,将在稍后完成。 - 你可以点击[快速开始](https://github.com/fankes/YukiHookAPI/wiki#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B),集成 `YukiHookAPI` 并开始使用。 - 更多使用教程及 API 文档请[前往 Wiki 主页](https://github.com/fankes/YukiHookAPI/wiki)进行查看。 diff --git a/yukihookapi-ksp-xposed/build.gradle b/yukihookapi-ksp-xposed/build.gradle index 9d32e761..e8d179c7 100644 --- a/yukihookapi-ksp-xposed/build.gradle +++ b/yukihookapi-ksp-xposed/build.gradle @@ -9,6 +9,13 @@ plugins { java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 + withJavadocJar() + withSourcesJar() +} + +javadoc { + options.addStringOption("charset", "UTF-8") + if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption('html5', true) } kotlin { sourceSets.main { kotlin.srcDir("src/api/kotlin") } } @@ -61,14 +68,8 @@ publishing { url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" } credentials { - BufferedReader buff_USERNAME = new BufferedReader(new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/OSSRH_USERNAME")) - String OSSRH_USERNAME = buff_USERNAME.readLine() - buff_USERNAME.close() - BufferedReader buff_PASSWORD = new BufferedReader(new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/OSSRH_PASSWORD")) - String OSSRH_PASSWORD = buff_PASSWORD.readLine() - buff_PASSWORD.close() - username = OSSRH_USERNAME - password = OSSRH_PASSWORD + username = getFileContent("OSSRH_USERNAME") + password = getFileContent("OSSRH_PASSWORD") } } } @@ -76,4 +77,13 @@ publishing { signing { sign(publishing.publications.mavenJava) +} + +private static String getFileContent(String name) { + FileReader reader = new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/" + name) + BufferedReader buff = new BufferedReader(reader) + String result = buff.readLine() + buff.close() + reader.close() + return result } \ No newline at end of file diff --git a/yukihookapi/build.gradle b/yukihookapi/build.gradle index 61940647..18f32d33 100644 --- a/yukihookapi/build.gradle +++ b/yukihookapi/build.gradle @@ -9,9 +9,15 @@ java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 sourceSets.main { java.srcDir("src/api/kotlin") } + withJavadocJar() withSourcesJar() } +javadoc { + options.addStringOption("charset", "UTF-8") + if (JavaVersion.current().isJava9Compatible()) options.addBooleanOption('html5', true) +} + kotlin { sourceSets.main { kotlin.srcDir("src/api/kotlin") } } dependencies { @@ -63,14 +69,8 @@ publishing { url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" } credentials { - BufferedReader buff_USERNAME = new BufferedReader(new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/OSSRH_USERNAME")) - String OSSRH_USERNAME = buff_USERNAME.readLine() - buff_USERNAME.close() - BufferedReader buff_PASSWORD = new BufferedReader(new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/OSSRH_PASSWORD")) - String OSSRH_PASSWORD = buff_PASSWORD.readLine() - buff_PASSWORD.close() - username = OSSRH_USERNAME - password = OSSRH_PASSWORD + username = getFileContent("OSSRH_USERNAME") + password = getFileContent("OSSRH_PASSWORD") } } } @@ -78,4 +78,13 @@ publishing { signing { sign(publishing.publications.mavenJava) +} + +private static String getFileContent(String name) { + FileReader reader = new FileReader("/Users/fankes/ProjectPath/AndroidStudioProjects/YukiHookAPI/.gradle/" + name) + BufferedReader buff = new BufferedReader(reader) + String result = buff.readLine() + buff.close() + reader.close() + return result } \ No newline at end of file diff --git a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionUtils.java b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionUtils.java index 4b7f7818..d12386e3 100644 --- a/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionUtils.java +++ b/yukihookapi/src/api/kotlin/com/highcapable/yukihookapi/hook/utils/ReflectionUtils.java @@ -49,10 +49,6 @@ public class ReflectionUtils { private static final HashMap fieldCache = new HashMap<>(); private static final HashMap methodCache = new HashMap<>(); - /** - * @param clazzes - * @return String - */ private static String getParametersString(Class... clazzes) { StringBuilder sb = new StringBuilder("("); boolean first = true; @@ -72,70 +68,13 @@ public class ReflectionUtils { } /** - * @param clazz - * @param fieldType - * @param fieldName - * @param value - * @return Field - */ - @Deprecated - public static void setStaticObjectField(Class clazz, Class fieldType, String fieldName, Object value) - throws NoSuchFieldException, IllegalAccessException { - findFieldIfExists(clazz, fieldType, fieldName).set(null, value); - } - - /** - * @param fieldType - * @param fieldName - * @param value - * @param obj - * @return Field - */ - @Deprecated - public static void setObjectField(Object obj, Class fieldType, String fieldName, Object value) - throws NoSuchFieldException, IllegalAccessException { - if (obj != null) { - Field field = findFieldIfExists(obj.getClass(), fieldType, fieldName); - if (field != null) { - field.set(obj, value); - } - } - } - - private static Field findFieldIfExists(Class clazz, Class fieldType, String fieldName) - throws NoSuchFieldException { - return findFieldIfExists(clazz, fieldType.getName(), fieldName); - } - - private static boolean isCallingFrom(String className) { - StackTraceElement[] stackTraceElements = Thread.currentThread() - .getStackTrace(); - for (StackTraceElement element : stackTraceElements) { - if (element.getClassName() - .contains(className)) { - return true; - } - } - return false; - } - - private static boolean isCallingFromEither(String... classname) { - StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); - for (StackTraceElement element : stackTraceElements) { - for (String name : classname) { - if (element.toString().contains(name)) { - return true; - } - } - } - return false; - } - - /** - * @param clazz - * @param typeName - * @param fieldName + * 适用于查找混淆类型的 abcd 变量 + * + * @param clazz 变量所在类 + * @param typeName 类型名称 + * @param fieldName 变量名 * @return Field + * @throws NoSuchFieldException 如果找不到变量 */ public static Field findFieldIfExists(Class clazz, String typeName, String fieldName) throws NoSuchFieldException { String fullFieldName = "name:[" + fieldName + "] type:[" + typeName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder"; @@ -172,6 +111,7 @@ public class ReflectionUtils { * @param returnType 返回类型 * @param methodName 方法名 * @return Method + * @throws NoSuchMethodError 如果找不到方法 */ public static Method findMethodNoParam(Class clazz, Class returnType, String methodName) { String fullMethodName = "name:[" + methodName + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder"; @@ -192,6 +132,7 @@ public class ReflectionUtils { * @param methodName 方法名 * @param parameterTypes 方法参数类型数组 * @return Method + * @throws NoSuchMethodError 如果找不到方法 */ public static Method findMethodBestMatch(Class clazz, Class returnType, String methodName, Class... parameterTypes) { String fullMethodName = "name:[" + methodName + "] paramType:[" + getParametersString(parameterTypes) + "] in Class [" + clazz.getName() + "] by YukiHookAPI#finder"; @@ -210,6 +151,7 @@ public class ReflectionUtils { * @param clazz 构造类所在类 * @param parameterTypes 构造类方法参数类型数组 * @return Constructor + * @throws NoSuchMethodError 如果找不到构造类 */ public static Constructor findConstructorExact(Class clazz, Class... parameterTypes) { String fullConstructorName = "paramType:[" + getParametersString(parameterTypes) + "in Class [" + clazz.getName() + "] by YukiHookAPI#finder";