No need to hack anything...

This commit is contained in:
topjohnwu 2017-01-31 04:20:36 +08:00
parent 1d728475e3
commit fe3c66a7c8
4 changed files with 2 additions and 58 deletions

View File

@ -5,6 +5,6 @@ LOCAL_MODULE := su
LOCAL_MODULE_TAGS := eng debug optional LOCAL_MODULE_TAGS := eng debug optional
LOCAL_STATIC_LIBRARIES := libselinux LOCAL_STATIC_LIBRARIES := libselinux
LOCAL_C_INCLUDES := jni/selinux/libselinux/include/ jni/selinux/libsepol/include/ jni/su/sqlite3/ LOCAL_C_INCLUDES := jni/selinux/libselinux/include/ jni/selinux/libsepol/include/ jni/su/sqlite3/
LOCAL_SRC_FILES := su.c daemon.c activity.c db.c utils.c pts.c hacks.c sqlite3/sqlite3.c LOCAL_SRC_FILES := su.c daemon.c activity.c db.c utils.c pts.c sqlite3/sqlite3.c
LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -std=gnu11 LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -std=gnu11
include $(BUILD_EXECUTABLE) include $(BUILD_EXECUTABLE)

49
hacks.c
View File

@ -1,49 +0,0 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "su.h"
#include "utils.h"
enum {
H_NO_CONTEXT = 0x0001,
};
static struct {
const char *package;
int flags;
int uid;
} apps_list[] = {
{ "com.keramidas.TitaniumBackup", H_NO_CONTEXT, },
};
void hacks_init() {
char oldCwd[512];
int i;
getcwd(oldCwd, sizeof(oldCwd));
chdir("/data/data");
for(i=0; i<(sizeof(apps_list)/sizeof(apps_list[0])); ++i) {
apps_list[i].uid = -1;
struct stat st_buf;
int ret = stat(apps_list[i].package, &st_buf);
LOGW("hacks: Testing (%s:%d:%d)", apps_list[i].package, ret, st_buf.st_uid);
if(ret)
continue;
apps_list[i].uid = st_buf.st_uid;
}
}
void hacks_update_context(struct su_context* ctxt) {
int i;
for(i=0; i<(sizeof(apps_list)/sizeof(apps_list[0])); ++i) {
LOGW("hacks: Testing (%s:%d), %d", apps_list[i].package, ctxt->from.uid);
if(apps_list[i].uid != ctxt->from.uid)
continue;
LOGW("hacks: Found app (%s:%d)", apps_list[i].package, ctxt->from.uid);
if(apps_list[i].flags & H_NO_CONTEXT) {
LOGW("hacks: Disabling context (%s:%d)", apps_list[i].package, ctxt->from.uid);
ctxt->to.context = NULL;
}
}
}

6
su.c
View File

@ -479,8 +479,6 @@ static __attribute__ ((noreturn)) void allow(struct su_context *ctx) {
char *arg0; char *arg0;
int argc, err; int argc, err;
hacks_update_context(ctx);
umask(ctx->umask); umask(ctx->umask);
int send_to_app = 1; int send_to_app = 1;
@ -541,7 +539,7 @@ static __attribute__ ((noreturn)) void allow(struct su_context *ctx) {
arg0, PARG(0), PARG(1), PARG(2), PARG(3), PARG(4), PARG(5), arg0, PARG(0), PARG(1), PARG(2), PARG(3), PARG(4), PARG(5),
(ctx->to.optind + 6 < ctx->to.argc) ? " ..." : ""); (ctx->to.optind + 6 < ctx->to.argc) ? " ..." : "");
if(ctx->to.context && strcmp(ctx->to.context, "u:r:su_light:s0") == 0) { if(ctx->to.context) {
setexeccon(ctx->to.context); setexeccon(ctx->to.context);
} else { } else {
setexeccon("u:r:su:s0"); setexeccon("u:r:su:s0");
@ -803,8 +801,6 @@ int su_main_nodaemon(int argc, char **argv) {
deny(&ctx); deny(&ctx);
} }
hacks_init();
read_options(&ctx); read_options(&ctx);
user_init(&ctx); user_init(&ctx);

3
su.h
View File

@ -179,9 +179,6 @@ int su_main_nodaemon(int argc, char *argv[]);
// deadbeat dad fork. // deadbeat dad fork.
int fork_zero_fucks(); int fork_zero_fucks();
void hacks_init();
void hacks_update_context(struct su_context* ctxt);
// fallback to using /system/bin/log. // fallback to using /system/bin/log.
// can't use liblog.so because this is a static binary. // can't use liblog.so because this is a static binary.
#ifndef LOGE #ifndef LOGE