Skip to content

Commit

Permalink
refactor: update stickerPanel and ReflectUtils
Browse files Browse the repository at this point in the history
Signed-off-by: Hicores <me@hicore.cc>
  • Loading branch information
Hicores committed Sep 12, 2023
1 parent 377efd4 commit 207b92d
Show file tree
Hide file tree
Showing 62 changed files with 3,498 additions and 1,050 deletions.
18 changes: 8 additions & 10 deletions app/src/main/java/cc/hicore/QApp/QAppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@

package cc.hicore.QApp;

import cc.hicore.ReflectUtil.MClass;
import cc.hicore.ReflectUtil.MMethod;
import cc.hicore.ReflectUtil.XClass;
import cc.hicore.ReflectUtil.XMethod;
import io.github.qauxv.util.Initiator;

public class QAppUtils {
public static long getServiceTime(){
try {
return MMethod.CallStaticMethod(MClass.loadClass("com.tencent.mobileqq.msf.core.NetConnInfoCenter"),"getServerTimeMillis",long.class);
return XMethod.clz("com.tencent.mobileqq.msf.core.NetConnInfoCenter").name("getServerTimeMillis").ret(long.class).invoke();
} catch (Exception e) {
return 0;
}
}
public static String UserUinToPeerID(String UserUin){
try {
Object convertHelper = MClass.NewInstance(MClass.loadClass("com.tencent.qqnt.kernel.api.impl.UixConvertAdapterApiImpl"));
return MMethod.CallMethod(convertHelper,"getUidFromUin",String.class,new Class[]{long.class},Long.parseLong(UserUin));
Object convertHelper = XClass.newInstance(Initiator.loadClass("com.tencent.qqnt.kernel.api.impl.UixConvertAdapterApiImpl"));
return XMethod.obj(convertHelper).name("getUidFromUin").ret(String.class).param(long.class).invoke(Long.parseLong(UserUin));
}catch (Exception e){
return "";
}
Expand All @@ -52,15 +52,13 @@ public static boolean isQQnt(){
public static String getCurrentUin(){
try {
Object AppRuntime = getAppRuntime();
return MMethod.CallMethodNoParam(AppRuntime, "getCurrentAccountUin", String.class);
return XMethod.obj(AppRuntime).name("getCurrentAccountUin").ret(String.class).invoke();
} catch (Exception e) {
return "";
}
}
public static Object getAppRuntime() throws Exception {
Object sApplication = MMethod.CallStaticMethod(MClass.loadClass("com.tencent.common.app.BaseApplicationImpl"),
"getApplication", MClass.loadClass("com.tencent.common.app.BaseApplicationImpl"));

return MMethod.CallMethodNoParam(sApplication, "getRuntime", MClass.loadClass("mqq.app.AppRuntime"));
Object sApplication = XMethod.clz("com.tencent.common.app.BaseApplicationImpl").name("getApplication").ret(Initiator.load("com.tencent.common.app.BaseApplicationImpl")).invoke();
return XMethod.obj(sApplication).name("getRuntime").ret(Initiator.loadClass("mqq.app.AppRuntime")).invoke();
}
}
133 changes: 0 additions & 133 deletions app/src/main/java/cc/hicore/ReflectUtil/MClass.java

This file was deleted.

147 changes: 0 additions & 147 deletions app/src/main/java/cc/hicore/ReflectUtil/MField.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,6 @@

public class MField {

private static final HashMap<String, Field> FieldCache = new HashMap<>();

public static void SetField(Object CheckObj, String FieldName, Object Value) throws Exception {
SetField(CheckObj, CheckObj.getClass(), FieldName, Value.getClass(), Value);
}

public static void SetField(Object CheckObj, String FieldName, Class<?> CheckClass, Object Value) throws Exception {
SetField(CheckObj, CheckObj.getClass(), FieldName, CheckClass, Value);
}

public static <T> T GetField(Object CheckObj, String FieldName) throws Exception {
Class<?> clz = CheckObj.getClass();
String SignText = clz.getName() + ":" + FieldName;
if (FieldCache.containsKey(SignText)) {
Field f = FieldCache.get(SignText);
return (T) f.get(CheckObj);
}
Class<?> Check = clz;
while (Check != null) {
for (Field f : Check.getDeclaredFields()) {
if (f.getName().equals(FieldName)) {
f.setAccessible(true);
FieldCache.put(SignText, f);
return (T) f.get(CheckObj);
}
}
Check = Check.getSuperclass();
}
throw new RuntimeException("Can't find field " + FieldName + " in class " + clz.getName());
}

public static <T> T GetField(Object CheckObj, String FieldName, Class<?> FieldType) throws Exception {
return GetField(CheckObj, CheckObj.getClass(), FieldName, FieldType);
}

public static <T> T GetStaticField(Class<?> clz, String FieldName) {
try {
Class<?> checkClz = clz;
Expand All @@ -77,116 +42,4 @@ public static <T> T GetStaticField(Class<?> clz, String FieldName) {
}
throw new RuntimeException("Can't find field " + FieldName + " in class " + clz);
}

public static void SetField(Object CheckObj, Class<?> CheckClass, String FieldName, Class<?> FieldClass, Object Value) throws Exception {
String SignText = CheckClass.getName() + ":" + FieldName + "(" + FieldClass.getName() + ")";
if (FieldCache.containsKey(SignText)) {
Field f = FieldCache.get(SignText);
f.set(CheckObj, Value);
return;
}

Class<?> Check = CheckClass;
while (Check != null) {
for (Field f : Check.getDeclaredFields()) {
if (f.getName().equals(FieldName)) {
if (MClass.CheckClass(f.getType(), FieldClass)) {
f.setAccessible(true);
FieldCache.put(SignText, f);
f.set(CheckObj, Value);
return;
}
}
}
Check = Check.getSuperclass();
}
throw new RuntimeException("Can't find field " + FieldName + "(" + FieldClass.getName() + ") in class " + CheckClass.getName());
}

public static <T> T GetField(Object CheckObj, Class<?> CheckClass, String FieldName, Class<?> FieldClass) throws Exception {
String SignText = CheckClass.getName() + ":" + FieldName + "(" + FieldClass.getName() + ")";
if (FieldCache.containsKey(SignText)) {
Field f = FieldCache.get(SignText);
return (T) f.get(CheckObj);
}

Class<?> Check = CheckClass;
while (Check != null) {
for (Field f : Check.getDeclaredFields()) {
if (f.getName().equals(FieldName)) {
if (MClass.CheckClass(f.getType(), FieldClass)) {
f.setAccessible(true);
FieldCache.put(SignText, f);
return (T) f.get(CheckObj);
}
}
}
Check = Check.getSuperclass();
}
throw new RuntimeException("Can't find field " + FieldName + "(" + FieldClass.getName() + ") in class " + CheckClass.getName());
}

public static <T> T GetFirstField(Object CheckObj, Class<?> CheckClass, Class<?> FieldClass) throws Exception {
String SignText = CheckClass.getName() + ":!NoName!" + "(" + FieldClass.getName() + ")";
if (FieldCache.containsKey(SignText)) {
Field f = FieldCache.get(SignText);
return (T) f.get(CheckObj);
}

Class<?> Check = CheckClass;
while (Check != null) {
for (Field f : Check.getDeclaredFields()) {
if (FieldClass == f.getType()) {
f.setAccessible(true);
FieldCache.put(SignText, f);
return (T) f.get(CheckObj);
}
}
Check = Check.getSuperclass();
}
throw new RuntimeException("Can't find field " + "(" + FieldClass.getName() + ") in class " + CheckClass.getName());
}

public static <T> T GetRoundField(Object CheckObj, Class<?> CheckClass, Class<?> FieldClass, int Round) throws Exception {
int pos = 0;
String SignText = CheckClass.getName() + ":!NoName!" + "(" + FieldClass.getName() + ")" + Round;
if (FieldCache.containsKey(SignText)) {
Field f = FieldCache.get(SignText);
return (T) f.get(CheckObj);
}

Class<?> Check = CheckClass;
while (Check != null) {
for (Field f : Check.getDeclaredFields()) {
if (MClass.CheckClass(f.getType(), FieldClass)) {
if (pos != Round) {
pos++;
continue;
}
f.setAccessible(true);
FieldCache.put(SignText, f);
return (T) f.get(CheckObj);
}
}
Check = Check.getSuperclass();
}
throw new RuntimeException("Can't find field " + "(" + FieldClass.getName() + ") in class " + CheckClass.getName());
}

public static <T> T GetFirstField(Object CheckObj, Class<?> FieldClass) throws Exception {
return GetFirstField(CheckObj, CheckObj.getClass(), FieldClass);
}

public static Field FindField(Class<?> ObjClass, String FieldName, Class<?> FieldType) {
Class<?> FindClass = ObjClass;
while (FindClass != null) {
for (Field f : FindClass.getDeclaredFields()) {
if (f.getName().equals(FieldName) && f.getType().equals(FieldType)) {
return f;
}
}
FindClass = FindClass.getSuperclass();
}
return null;
}
}
8 changes: 2 additions & 6 deletions app/src/main/java/cc/hicore/ReflectUtil/MMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ public static <T> T CallMethod(Object obj, Class<?> clz, String MethodName, Clas

private static final HashMap<String, Method> MethodCache = new HashMap<>();

public static Method FindMethod(String FindClass, String MethodName, Class<?> ReturnType, Class<?>[] ParamTypes) {
return FindMethod(MClass.loadClass(FindClass), MethodName, ReturnType, ParamTypes);
}

public static Method FindMethod(Class<?> FindClass, String MethodName, Class<?> ReturnType, Class<?>[] ParamTypes) {
if (FindClass == null) {
return null;
Expand All @@ -146,7 +142,7 @@ public static Method FindMethod(Class<?> FindClass, String MethodName, Class<?>

if (params.length == ParamTypes.length) {
for (int i = 0; i < params.length; i++) {
if (!MClass.CheckClass(params[i], ParamTypes[i])) {
if (!XClass.CheckClass(params[i], ParamTypes[i])) {
continue Loop;
}
}
Expand Down Expand Up @@ -185,7 +181,7 @@ public static Method FindMethod(Class<?> FindClass, String MethodName, Class<?>[

if (params.length == ParamTypes.length) {
for (int i = 0; i < params.length; i++) {
if (!MClass.CheckClass(params[i], ParamTypes[i])) {
if (!XClass.CheckClass(params[i], ParamTypes[i])) {
continue Loop;
}
}
Expand Down
Loading

0 comments on commit 207b92d

Please sign in to comment.