public
class MainModule implements IXposedHookLoadPackage {
// 目标应用的包名
private
static final String TARGET_PACKAGE =
"com.justsoso.faster"
;
@Override
public
void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
// 检查当前加载的应用是否是目标应用
if
(!lpparam.packageName.equals(TARGET_PACKAGE)) {
return; // 如果不是目标应用,直接返回
}
// 获取模块的资源路径
final String modulePath = lpparam.appInfo.sourceDir;
// 挂钩到 Application.attach 方法,加载模块资源
XposedHelpers.findAndHookMethod(Application.class,
"attach"
, Context.class, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Context context = (Context) param.args[0];
// 将模块的资源路径添加到目标应用的 AssetManager
XposedHelpers.callMethod(context.getResources().getAssets(),
"addAssetPath"
, modulePath);
}
});
XposedHelpers.findAndHookMethod(
"com.faster.cheetah.MainActivity"
,
lpparam.classLoader,
"onCreate"
, // 在 onResume 中操作视图
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Activity activity = (Activity) param.thisObject;
// 确保 DecorView 已初始化
View decorView = activity.getWindow().getDecorView();
if
(decorView != null) {
// 显示自定义弹窗
showCustomDialog(activity);
}
else
{
XposedBridge.log(
"DecorView 未初始化,无法显示弹窗"
);
}
}
}
);
}
/**
* 显示自定义弹窗
*
* [url=home.php
?
mod
=space&uid=952169]@Param[/url] activity 当前的 Activity 对象
*/
private
void showCustomDialog(Activity activity) {
try {
// 使用 LayoutInflater 加载自定义布局
LayoutInflater inflater = LayoutInflater.from(activity);
View dialogView = inflater.inflate(R.layout.dialog_custom, null);
// 获取布局中的控件
ImageView imageView = dialogView.findViewById(R.id.imageView);
TextView messageTextView = dialogView.findViewById(R.id.messageTextView);
// 设置图片和文字
imageView.setImageResource(R.drawable.custom_image); // 替换为你的图片资源
messageTextView.setText(
"这是一个自定义弹窗!"
); // 替换为你的文字内容
// 创建弹窗
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setView(dialogView);
builder.setPositiveButton(
"确定"
, new DialogInterface.OnClickListener() {
@Override
public
void onClick(DialogInterface dialog,
int
which) {
dialog.dismiss(); // 点击确定按钮后关闭弹窗
}
});
// 显示弹窗
AlertDialog dialog = builder.create();
dialog.show();
} catch (Exception e) {
// 输出日志
XposedBridge.log(
"弹窗加载失败: "
+ e.getMessage());
}
}
}