Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
use Magisk installer & support Android Q beta 3
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed May 9, 2019
1 parent c42e737 commit 4db2a4c
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 203 deletions.
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ def moduleId = "location_report_enabler"
def moduleName = "Location Report Enabler"
def moduleAuthor = "Rikka"
def moduleDescription = "Enable Google location report by hook system_property_get (and android::base::GetProperty for API 28+)."
def versionName = "v8"
def versionCode = 8
def riruApi = 3
def versionName = "v9"
def versionCode = 6
def riruApi = 4

def moduleIdMagisk = "riru_location_report_enabler"
def moduleNameMagisk = "Riru - $moduleName"
def moduleDescriptionMagisk = "$moduleDescription Requires Riru - Core v18 or above installed."
def moduleDescriptionMagisk = "$moduleDescription Requires Riru - Core v19 or above installed."
def zipNameMagisk = "magisk-${project.name}-${versionName}.zip"

def isWindows = org.gradle.internal.os.OperatingSystem.current().isWindows()
Expand Down
95 changes: 48 additions & 47 deletions jni/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#include <unistd.h>
#include <fcntl.h>
#include <jni.h>
#include <cstring>
#include <cstdlib>
#include <sys/mman.h>
#include <array>
#include <thread>
#include <vector>
#include <utility>
#include <string>
#include <sys/system_properties.h>

Expand All @@ -21,85 +18,89 @@
static char package_name[256];
static int uid;
static int enable_hook;
static std::vector<std::string> packages = {
"com.google.android.gms",
"com.google.android.gsf",
"com.google.android.apps.maps"
};

int is_app_need_hook(JNIEnv *env, jstring appDataDir) {
if (!appDataDir)
return 0;


const char *app_data_dir = env->GetStringUTFChars(appDataDir, nullptr);

int user = 0;
if (sscanf(app_data_dir, "/data/%*[^/]/%d/%s", &user, package_name) != 2) {
if (sscanf(app_data_dir, "/data/%*[^/]/%s", package_name) != 1) {
package_name[0] = '\0';
LOGW("can't parse %s", app_data_dir);
return 0;
static bool is_app_need_hook(JNIEnv *env, jstring jAppDataDir, jstring jPackageName) {
if (jAppDataDir) {
const char *appDataDir = env->GetStringUTFChars(jAppDataDir, nullptr);
int user = 0;
if (sscanf(appDataDir, "/data/%*[^/]/%d/%s", &user, package_name) != 2) {
if (sscanf(appDataDir, "/data/%*[^/]/%s", package_name) != 1) {
package_name[0] = '\0';
LOGW("can't parse %s", appDataDir);
return false;
}
}
env->ReleaseStringUTFChars(jAppDataDir, appDataDir);
} else if (jPackageName) {
const char *packageName = env->GetStringUTFChars(jPackageName, nullptr);
sprintf(package_name, "%s", packageName);
env->ReleaseStringUTFChars(jPackageName, packageName);
} else {
return false;
}

env->ReleaseStringUTFChars(appDataDir, app_data_dir);

if (access(CONFIG_PATH "/packages", R_OK) != 0) {
for (auto &s : packages) {
if (strcmp(s.c_str(), package_name) == 0)
return 1;
}
} else {
char path[PATH_MAX];
snprintf(path, PATH_MAX, CONFIG_PATH "/packages/%s", package_name);
return access(path, F_OK) == 0;
}
return 0;
char path[PATH_MAX];
snprintf(path, PATH_MAX, CONFIG_PATH "/packages/%s", package_name);
return access(path, F_OK) == 0;
}

void load_config() {
static void load_config() {
char buf[PROP_VALUE_MAX + 1];
int fd;
fd = open(CONFIG_PATH "/gsm.sim.operator.numeric", O_RDONLY);
fd = open(CONFIG_PATH "/gsm.sim.operator.numeric", O_RDONLY | O_CLOEXEC);
if (fd > 0 && fdgets(buf, sizeof(buf), fd) > 0)
set_sim_operator_numeric(buf);

if (fd > 0)
close(fd);

fd = open(CONFIG_PATH "/gsm.sim.operator.iso-country", O_RDONLY);
fd = open(CONFIG_PATH "/gsm.sim.operator.iso-country", O_RDONLY | O_CLOEXEC);
if (fd > 0 && fdgets(buf, sizeof(buf), fd) > 0)
set_sim_operator_country(buf);

if (fd > 0)
close(fd);
}

void nativeForkAndSpecialize(int res, int enable_hook, const char *package_name, jint uid) {
if (res == 0 && enable_hook) {
install_hook(package_name, uid / 100000);
}
}

extern "C" {
__attribute__((visibility("default"))) void nativeForkAndSpecializePre(
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtime_flags,
jobjectArray *rlimits, jint *_mount_external, jstring *se_info, jstring *se_name,
jintArray *fdsToClose, jintArray *fdsToIgnore, jboolean *is_child_zygote,
jstring *instructionSet, jstring *appDataDir, jstring *packageName,
jobjectArray *packagesForUID, jobjectArray *visibleVolIDs) {
jobjectArray *packagesForUID, jstring *sandboxId) {

uid = *_uid;
enable_hook = is_app_need_hook(env, *appDataDir);
enable_hook = is_app_need_hook(env, *appDataDir, nullptr);

if (enable_hook)
load_config();
}

__attribute__((visibility("default"))) int nativeForkAndSpecializePost(JNIEnv *env, jclass clazz,
jint res) {
nativeForkAndSpecialize(res, enable_hook, package_name, uid);
__attribute__((visibility("default"))) int nativeForkAndSpecializePost(
JNIEnv *env, jclass clazz, jint res) {
if (res == 0 && enable_hook) install_hook(package_name, uid / 100000);
return !enable_hook;
}

__attribute__((visibility("default"))) void specializeAppProcessPre(
JNIEnv *env, jclass clazz, jint *_uid, jint *gid, jintArray *gids, jint *runtimeFlags,
jobjectArray *rlimits, jint *mountExternal, jstring *seInfo, jstring *niceName,
jboolean *startChildZygote, jstring *instructionSet, jstring *appDataDir,
jstring *packageName, jobjectArray *packagesForUID, jstring *sandboxId) {

uid = *_uid;
enable_hook = is_app_need_hook(env, nullptr, *packageName);

if (enable_hook)
load_config();
}

__attribute__((visibility("default"))) int specializeAppProcessPost(
JNIEnv *env, jclass clazz) {

if (enable_hook) install_hook(package_name, uid / 100000);
return !enable_hook;
}
}
150 changes: 0 additions & 150 deletions template_override/config.sh

This file was deleted.

Loading

0 comments on commit 4db2a4c

Please sign in to comment.