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 )
@@ -24,26 +25,29 @@ struct sdesc {
2425};
2526
2627#ifdef CONFIG_KSU_DEBUG
28+ extern int get_pkg_from_apk_path (char * pkg , const char * path );
29+
2730// Extract package name from APK path for debug logging
28- // Examples:
29- // "/data/app/~~xxx==/me.weishu.kernelsu-yyy==/base.apk" -> "me.weishu.kernelsu"
30- // "/data/app/MIUICalculator/base.apk" -> "MIUICalculator"
31- // "/system/app/Calculator/Calculator.apk" -> "Calculator"
31+ // Reuses get_pkg_from_apk_path() for third-party apps, with fallback for system apps
3232static const char * extract_package_name (const char * path )
3333{
3434 static char pkg_name [256 ];
35+
36+ // Try official function first (handles third-party apps)
37+ if (get_pkg_from_apk_path (pkg_name , path ) == 0 )
38+ return pkg_name ;
39+
40+ // Fallback for system apps: extract directory name
3541 const char * last_slash = NULL ;
3642 const char * second_last_slash = NULL ;
3743
38- // Find last two '/' in path
3944 for (const char * p = path ; * p ; p ++ ) {
4045 if (* p == '/' ) {
4146 second_last_slash = last_slash ;
4247 last_slash = p ;
4348 }
4449 }
4550
46- // Extract directory name between the two slashes
4751 if (!second_last_slash || !last_slash )
4852 return path ;
4953
@@ -54,7 +58,7 @@ static const char *extract_package_name(const char *path)
5458 memcpy (pkg_name , second_last_slash + 1 , len );
5559 pkg_name [len ] = '\0' ;
5660
57- // Remove " .apk" suffix if present (e.g., /system/app/Calc/Calc.apk)
61+ // Remove .apk suffix if present
5862 len = strlen (pkg_name );
5963 if (len > 4 && !strcmp (pkg_name + len - 4 , ".apk" ))
6064 pkg_name [len - 4 ] = '\0' ;
0 commit comments