1,问题提出,日出开发xposed 模块,遇到各种壳,hook 都是有点困难,比如乐加固,360加固等。
2,解决: 使用hook ClassLoader.class, 这样就可以找到需要的类, 但是要注意,找到之后就不要继续往下找,return 即可,不然就是递归调用。
public class Main implements IXposedHookLoadPackage {
插入代码
public static String xxx_PACKAGE
=
"com.xxx"
;
public static boolean xxx_PACKAGE_ISHOOK
=
false;
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
final String packageName
=
lpparam.packageName;
XposedBridge.log(
"pkgname:"
+
packageName);
final String processName
=
lpparam.processName;
try
{
final
Set
<XC_MethodHook.Unhook> unhooks
=
XposedBridge.hookAllMethods(ClassLoader.
class
,
"loadClass"
, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
if
(NXES_PACKAGE_ISHOOK){
throw new Throwable(
"exp"
);
}
}
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super
.afterHookedMethod(param);
try
{
if
(param.hasThrowable()) {
return
;
}
if
(param.args.length !
=
1
) {
return
;
}
if
(NXES_PACKAGE_ISHOOK){
return
;
}
Class<?>
cls
=
(Class<?>) param.getResult();
String name
=
cls
.getName();
XposedBridge.log(
"className1:"
+
name);
if
(
"me.weishu.epic.art.entry.Entry"
.equals(name)) {
return
;
}
if
(
"me.weishu.epic.art.method.ArtMethod"
.equals(name)){
return
;
}
if
(
"s.h.e.l.l.S"
.equals(name)) {
LogUtil.printLog(
"s.h.e.l.l.S-------hooked"
);
XposedHelpers.findAndHookMethod(
"s.h.e.l.l.S"
, (ClassLoader) param.thisObject,
"attachBaseContext"
,
Context.
class
,
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super
.afterHookedMethod(param);
LogUtil.printLog(
"afterHookedMethod s.h.l.l.S.attachBaseContext ..."
);
Context context
=
(Context) param.args[
0
];
ClassLoader appClassLoader
=
context.getClassLoader();
LogUtil.printLog(
"--->processName:"
+
processName
+
" isHooked :"
+
CITTC_PACKAGE_ISHOOK);
if
(xxx_PACKAGE.equals(processName) && !NXES_PACKAGE_ISHOOK) {
NXES_PACKAGE_ISHOOK
=
true;
PayHelperUtils.sendmsg(context,
"xxx hook成功,当前xxx 版本:"
+
PayHelperUtils.getVerName(context));
new NXESHook().hook(appClassLoader, context);
}
}
}
);
}
}catch (Exception exp) {
LogUtil.printLog(exp.toString());
}
}
});
} catch (Throwable e) {
XposedBridge.log(e);
}
}
public static String xxx_PACKAGE
=
"com.xxx"
;
public static boolean xxx_PACKAGE_ISHOOK
=
false;
@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam)
throws Throwable {
final String packageName
=
lpparam.packageName;
XposedBridge.log(
"pkgname:"
+
packageName);
final String processName
=
lpparam.processName;
try
{
final
Set
<XC_MethodHook.Unhook> unhooks
=
XposedBridge.hookAllMethods(ClassLoader.
class
,
"loadClass"
, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
if
(NXES_PACKAGE_ISHOOK){
throw new Throwable(
"exp"
);
}
}
@Override
protected void afterHookedMethod(XC_MethodHook.MethodHookParam param) throws Throwable {
super
.afterHookedMethod(param);
try
{
if
(param.hasThrowable()) {
return
;
}
if
(param.args.length !
=
1
) {
return
;
}
if
(NXES_PACKAGE_ISHOOK){
return
;
}
Class<?>
cls
=
(Class<?>) param.getResult();
String name
=
cls
.getName();
XposedBridge.log(
"className1:"
+
name);
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!