Skip to content

Commit 577e9c7

Browse files
committed
refactor: Expose get_pkg_from_apk_path and integrate it into apk_sign.c's package extraction with system app fallback.
1 parent a69995b commit 577e9c7

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

kernel/apk_sign.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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
3131
static 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';

kernel/throne_tracker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct uid_data {
2121
char package[KSU_MAX_PACKAGE_NAME];
2222
};
2323

24-
static int get_pkg_from_apk_path(char *pkg, const char *path)
24+
int get_pkg_from_apk_path(char *pkg, const char *path)
2525
{
2626
int len = strlen(path);
2727
if (len >= KSU_MAX_PACKAGE_NAME || len < 1)

0 commit comments

Comments
 (0)