Adjustments for unified binary

This commit is contained in:
topjohnwu 2017-04-05 06:00:42 +08:00
parent dc9670c439
commit cd498711bc
4 changed files with 19 additions and 39 deletions

View File

@ -3,9 +3,9 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := magiskpolicy
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_SRC_FILES := main.c sepolicy.c rules.c utils.c
LOCAL_C_INCLUDES := jni/selinux/libsepol/include/
LOCAL_CFLAGS += -std=gnu11
LOCAL_SRC_FILES := magiskpolicy.c sepolicy.c rules.c utils.c ../utils/vector.c
LOCAL_C_INCLUDES := jni/selinux/libsepol/include jni/utils
LOCAL_CFLAGS := -DINDEP_BINARY
include $(BUILD_EXECUTABLE)
include jni/selinux/libsepol/Android.mk

View File

@ -1,5 +1,15 @@
#include "vector.h"
#include "magiskpolicy.h"
#ifdef INDEP_BINARY
int magiskpolicy_main(int argc, char *argv[]);
int main(int argc, char *argv[]) {
return magiskpolicy_main(argc, argv);
}
#else
#include "magisk.h"
#endif
static int syntax_err = 0;
static char err_msg[ARG_MAX];
@ -52,7 +62,7 @@ static void usage(char *arg0) {
static int parse_pattern_1(int action, char* statement) {
int state = 0, in_bracket = 0;
char *tok, *class, *saveptr;
vector source, target, permission, *temp;
struct vector source, target, permission, *temp;
vec_init(&source);
vec_init(&target);
vec_init(&permission);
@ -130,7 +140,7 @@ static int parse_pattern_1(int action, char* statement) {
static int parse_pattern_2(int action, char* statement) {
int state = 0, in_bracket = 0;
char *tok, *saveptr;
vector class, attribute, *temp;
struct vector class, attribute, *temp;
vec_init(&class);
vec_init(&attribute);
tok = strtok_r(statement, " ", &saveptr);
@ -185,7 +195,7 @@ static int parse_pattern_2(int action, char* statement) {
// Pattern 3: action { type }
static int parse_pattern_3(int action, char* statement) {
char *tok, *saveptr;
vector classes;
struct vector classes;
vec_init(&classes);
tok = strtok_r(statement, " {}", &saveptr);
while (tok != NULL) {
@ -253,7 +263,7 @@ static void syntax_error_msg() {
syntax_err = 1;
}
int main(int argc, char *argv[]) {
int magiskpolicy_main(int argc, char *argv[]) {
char *infile = NULL, *outfile = NULL, *tok, *saveptr;
int live = 0, minimal = 0, full = 0;
struct vector rules;

View File

@ -22,6 +22,8 @@
#include <sepol/policydb/conditional.h>
#include <sepol/policydb/constraint.h>
#include "vector.h"
// hashtab traversal macro
#define hashtab_for_each(table, ptr) \
for (int _i = 0; _i < table->size; ++_i) \
@ -52,16 +54,6 @@ int enforce(char *s);
int attradd(char *s, char *a);
int exists(char *source);
// Vector of char*
typedef struct vector {
size_t size;
size_t cap;
char **data;
} vector;
void vec_init(vector *v);
void vec_push_back(vector *v, char* s);
void vec_destroy(vector *v);
// Built in rules
void full_rules();
void min_rules();

22
utils.c
View File

@ -1,27 +1,5 @@
#include "magiskpolicy.h"
void vec_init(vector *v) {
v->size = 0;
v->cap = 1;
v->data = (char**) malloc(sizeof(char*));
}
void vec_push_back(vector *v, char* s) {
if (v == NULL) return;
if (v->size == v->cap) {
v->cap *= 2;
v->data = (char**) realloc(v->data, sizeof(char*) * v->cap);
}
v->data[v->size] = s;
++v->size;
}
void vec_destroy(vector *v) {
v->size = 0;
v->cap = 0;
free(v->data);
}
int allow(char *s, char *t, char *c, char *p) {
return add_rule(s, t, c, p, AVTAB_ALLOWED, 0);
}