66#include <linux/version.h>
77#ifdef CONFIG_KSU_DEBUG
88#include <linux/moduleparam.h>
9+ #include "throne_tracker.h"
910#endif
1011#include <crypto/hash.h>
1112#if LINUX_VERSION_CODE >= KERNEL_VERSION (5 , 11 , 0 )
@@ -23,26 +24,29 @@ struct sdesc {
2324};
2425
2526#ifdef CONFIG_KSU_DEBUG
27+ extern int get_pkg_from_apk_path (char * pkg , const char * path );
28+
2629// Extract package name from APK path for debug logging
27- // Examples:
28- // "/data/app/~~xxx==/me.weishu.kernelsu-yyy==/base.apk" -> "me.weishu.kernelsu"
29- // "/data/app/MIUICalculator/base.apk" -> "MIUICalculator"
30- // "/system/app/Calculator/Calculator.apk" -> "Calculator"
30+ // Reuses get_pkg_from_apk_path() for third-party apps, with fallback for system apps
3131static const char * extract_package_name (const char * path )
3232{
3333 static char pkg_name [256 ];
34+
35+ // Try official function first (handles third-party apps)
36+ if (get_pkg_from_apk_path (pkg_name , path ) == 0 )
37+ return pkg_name ;
38+
39+ // Fallback for system apps: extract directory name
3440 const char * last_slash = NULL ;
3541 const char * second_last_slash = NULL ;
3642
37- // Find last two '/' in path
3843 for (const char * p = path ; * p ; p ++ ) {
3944 if (* p == '/' ) {
4045 second_last_slash = last_slash ;
4146 last_slash = p ;
4247 }
4348 }
4449
45- // Extract directory name between the two slashes
4650 if (!second_last_slash || !last_slash )
4751 return path ;
4852
@@ -53,7 +57,7 @@ static const char *extract_package_name(const char *path)
5357 memcpy (pkg_name , second_last_slash + 1 , len );
5458 pkg_name [len ] = '\0' ;
5559
56- // Remove " .apk" suffix if present (e.g., /system/app/Calc/Calc.apk)
60+ // Remove .apk suffix if present
5761 len = strlen (pkg_name );
5862 if (len > 4 && !strcmp (pkg_name + len - 4 , ".apk" ))
5963 pkg_name [len - 4 ] = '\0' ;
0 commit comments