Skip to content

Commit

Permalink
Fix hookPackageManagerGetPackageInfo & update logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
gauravssnl committed Feb 7, 2024
1 parent 7406682 commit 18904bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/src/main/cpp/nativehooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ NativeOnModuleLoaded native_init(const NativeAPIEntries *entries) {
FILE *fake_fopen(const char *filename, const char *mode) {
LOGD("Inside fake_fopen. Filename :: %s", filename);
if (is_file_related_to_root(filename)) {
LOGD("App tried to check root related files, so bypass it");
LOGI("App tried to check root related files, so bypass it");
return nullptr;
}
return original_fopen(filename, mode);
Expand All @@ -60,7 +60,7 @@ FILE *fake_fopen(const char *filename, const char *mode) {
int fake_stat(const char *filename, struct stat *file_info) {
LOGD("Inside fake_stat. Filename :: %s ", filename);
if (is_file_related_to_root(filename)) {
LOGD("App tried to check root related files, so bypass it");
LOGI("App tried to check root related files, so bypass it");
return -1;
}
return original_stat(filename, file_info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ class MainModule(base: XposedInterface, param: ModuleLoadedParam) : XposedModule
@JvmStatic
@BeforeInvocation
fun beforeInvocation(callback: BeforeHookCallback): MyHooker {
// module.log("Inside beforeInvocation()")
when (callback.member.name) {
"setLogging" -> callback.args[0] = true // enable logging
"exists" -> {
val file = callback.thisObject as File
val fileName = file.absolutePath
// module.log("Filename being accessed :: $fileName")
// we immediately return false if root related files are checked
if (isFileRootAccessRelated(fileName)) {
module.log("App tried to access root related file :: $fileName , so bypass it")
Expand All @@ -77,11 +75,11 @@ class MainModule(base: XposedInterface, param: ModuleLoadedParam) : XposedModule
if(knownRootAppsPackages.contains(packageName)
|| knownDangerousAppsPackages.contains(packageName)
|| knownRootCloakingPackages.contains(packageName)) {
callback.returnAndSkip(PackageManager.NameNotFoundException(packageName))
module.log("App tried to read root related Android apps :: $packageName , so bypass it")
callback.throwAndSkip(PackageManager.NameNotFoundException(packageName))
}
}
"exec" -> {
// module.log("Inside exec hook. Callback args :: ${callback.args.contentToString()}")
// Args can be either String or Array; so we need to handle
val command: String = try {
callback.args[0] as String
Expand Down Expand Up @@ -110,7 +108,6 @@ class MainModule(base: XposedInterface, param: ModuleLoadedParam) : XposedModule
@JvmStatic
@AfterInvocation
fun afterInvocation(callback: AfterHookCallback, param: MyHooker) {
// module.log("Inside afterInvocation()")
when(callback.member.name) {
"get" -> {
val propName = callback.args[0] as String
Expand Down Expand Up @@ -139,7 +136,7 @@ class MainModule(base: XposedInterface, param: ModuleLoadedParam) : XposedModule

@SuppressLint("PrivateApi")
private fun hookPackageManagerGetPackageInfo(classLoader: ClassLoader) {
val clazz = classLoader.loadClass("android.content.pm.PackageManager")
val clazz = classLoader.loadClass("android.app.ApplicationPackageManager")
clazz.declaredMethods.filter { it.name == "getPackageInfo" }.forEach{
hook(it, MyHooker::class.java)
}
Expand Down

0 comments on commit 18904bc

Please sign in to comment.