-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # README.md
- Loading branch information
Showing
9 changed files
with
351 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.lu.wxmask.bean | ||
|
||
import androidx.annotation.Keep | ||
import org.json.JSONObject | ||
|
||
@Keep | ||
class PointBean( | ||
var featId: String, | ||
var clazz: String, | ||
var method: String | ||
) { | ||
companion object { | ||
fun fromJson(value: JSONObject): PointBean { | ||
val featId = value.optString("featId", null) | ||
val clazz = value.optString("clazz", null) | ||
val method = value.optString("method", null) | ||
return PointBean(featId, clazz, method) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/lu/wxmask/plugin/point/HideSearchListPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.lu.wxmask.plugin.point; | ||
|
||
import android.content.Context; | ||
|
||
import com.lu.lposed.api2.XC_MethodHook2; | ||
import com.lu.lposed.api2.XposedHelpers2; | ||
import com.lu.lposed.plugin.IPlugin; | ||
import com.lu.lposed.plugin.PluginProviders; | ||
import com.lu.magic.util.log.LogUtil; | ||
import com.lu.wxmask.ClazzN; | ||
import com.lu.wxmask.bean.PointBean; | ||
import com.lu.wxmask.plugin.WXMaskPlugin; | ||
import com.lu.wxmask.plugin.part.HideSearchListUIPluginPart; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import de.robv.android.xposed.callbacks.XC_LoadPackage; | ||
|
||
public class HideSearchListPoint implements IPlugin { | ||
private PointBean mPointBean; | ||
|
||
public HideSearchListPoint(@NotNull PointBean it) { | ||
mPointBean = it; | ||
} | ||
|
||
@Override | ||
public void handleHook(Context context, XC_LoadPackage.LoadPackageParam lpparam) { | ||
if (mPointBean == null) { | ||
return; | ||
} | ||
Method method = XposedHelpers2.findMethodExactIfExists(ClazzN.from(mPointBean.getClazz()), mPointBean.getMethod(), Integer.TYPE); | ||
if (method == null) { | ||
return; | ||
} | ||
XposedHelpers2.hookMethod(method, new XC_MethodHook2() { | ||
@Override | ||
protected void afterHookedMethod(MethodHookParam param) throws Throwable { | ||
WXMaskPlugin wxMaskPlugin = PluginProviders.from(WXMaskPlugin.class); | ||
HideSearchListUIPluginPart pluginPart = wxMaskPlugin.getHideSearchListPluginPart(); | ||
|
||
if (pluginPart.needHideUserName2(param, param.getResult())) { | ||
LogUtil.d("hide hahah", param.getResult()); | ||
param.setResult(null); | ||
} | ||
} | ||
|
||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.lu.wxmask.util; | ||
|
||
import android.content.Context; | ||
|
||
import com.lu.magic.util.ReflectUtil; | ||
import com.lu.magic.util.function.Consumer; | ||
import com.lu.magic.util.function.Predicate; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Enumeration; | ||
import java.util.HashSet; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import dalvik.system.DexFile; | ||
|
||
public class CodeUtil { | ||
/** | ||
* 获取应用程序下的所有Dex文件 | ||
* | ||
* @param packageCodePath 包路径 | ||
* @return Set<DexFile> | ||
*/ | ||
private static List<DexFile> getDexFileList(String packageCodePath) { | ||
List<DexFile> dexFiles = new ArrayList<>(); | ||
File dir = new File(packageCodePath).getParentFile(); | ||
File[] files = dir.listFiles(); | ||
for (File file : files) { | ||
try { | ||
String absolutePath = file.getAbsolutePath(); | ||
if (!absolutePath.contains(".")) continue; | ||
String suffix = absolutePath.substring(absolutePath.lastIndexOf(".")); | ||
if (!suffix.equals(".apk")) continue; | ||
DexFile dexFile = getDexFile(file.getAbsolutePath()); | ||
if (dexFile == null) continue; | ||
dexFiles.add(dexFile); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return dexFiles; | ||
} | ||
|
||
/** | ||
* 获取DexFile文件 | ||
* | ||
* @param path 路径 | ||
* @return DexFile | ||
*/ | ||
public static DexFile getDexFile(String path) { | ||
try { | ||
return new DexFile(path); | ||
} catch (IOException e) { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
public static List<String> filterClass(Context context, Predicate<String> func) { | ||
List<DexFile> dexFiles = getDexFileListNewApi(context.getClassLoader()); | ||
if (dexFiles.isEmpty()) { | ||
//老方法需要重新读取,耗时大 | ||
dexFiles = getDexFileList(context.getApplicationContext().getPackageCodePath()); | ||
} | ||
return filterClassInternal(dexFiles.iterator(), func); | ||
} | ||
|
||
public static void eachClass(Context context, Consumer<String> consumer) { | ||
List<DexFile> dexFiles = getDexFileListNewApi(context.getClassLoader()); | ||
if (dexFiles.isEmpty()) { | ||
//老方法需要重新读取,耗时大 | ||
dexFiles = getDexFileList(context.getApplicationContext().getPackageCodePath()); | ||
} | ||
eachClassInternal(dexFiles.iterator(), consumer); | ||
} | ||
|
||
/** | ||
* 读取类路径下的所有类 | ||
* | ||
* @param context 上下文 | ||
* @param pkgName 包名 | ||
* @return List<String> | ||
*/ | ||
public static List<String> filterClass(Context context, String pkgName, boolean includeChildDir) { | ||
List<DexFile> dexFiles = getDexFileListNewApi(context.getClassLoader()); | ||
if (dexFiles.isEmpty()) { | ||
//老方法需要重新读取,耗时大 | ||
dexFiles = getDexFileList(context.getApplicationContext().getPackageCodePath()); | ||
} | ||
|
||
return filterClassInternal(dexFiles.iterator(), currentClassPath -> { | ||
if (!currentClassPath.startsWith(pkgName)) { | ||
return false; | ||
} | ||
if (includeChildDir) { | ||
return true; | ||
} else { | ||
return '.' == currentClassPath.charAt(pkgName.length()); | ||
} | ||
}); | ||
} | ||
|
||
|
||
public static List<DexFile> getDexFileListNewApi(ClassLoader classLoader) { | ||
List<DexFile> result = new ArrayList<>(); | ||
try { | ||
Object pathList = ReflectUtil.getFieldValue(classLoader, classLoader.getClass().getSuperclass(), "pathList"); | ||
Object[] dexElements = (Object[]) ReflectUtil.getFieldValue(pathList, "dexElements"); | ||
for (Object dexElement : dexElements) { | ||
DexFile dexFile = (DexFile) ReflectUtil.getFieldValue(dexElement, "dexFile"); | ||
result.add(dexFile); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
return result; | ||
} | ||
|
||
|
||
private static void eachClassInternal(Iterator<DexFile> dexFiles, Consumer<String> func) { | ||
|
||
while (dexFiles.hasNext()) { | ||
DexFile dexFile = dexFiles.next(); | ||
if (dexFile == null) continue; | ||
|
||
Enumeration<String> entries = dexFile.entries(); | ||
while (entries.hasMoreElements()) { | ||
try { | ||
String currentClassPath = entries.nextElement(); | ||
if (currentClassPath == null || currentClassPath.isEmpty()) { | ||
continue; | ||
} | ||
func.accept(currentClassPath); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private static List<String> filterClassInternal(Iterator<DexFile> dexFiles, Predicate<String> predicateFunc) { | ||
HashSet<String> result = new HashSet<>(); | ||
eachClassInternal(dexFiles, s -> { | ||
if (predicateFunc.test(s)) { | ||
result.add(s); | ||
} | ||
}); | ||
return new ArrayList<>(result); | ||
} | ||
|
||
|
||
public static String getPackageName(String typeName) { | ||
int index = typeName.lastIndexOf("."); | ||
if (index == -1) { | ||
return null; | ||
} | ||
return typeName.substring(0, index); | ||
} | ||
} |
Oops, something went wrong.