Skip to content

Commit

Permalink
Fix some bootloop
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveSy committed Dec 7, 2020
1 parent 6495322 commit 3036a81
Show file tree
Hide file tree
Showing 14 changed files with 41 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "edxp-core/src/main/cpp/external/Dobby"]
path = edxp-core/src/main/cpp/external/Dobby
url = https://github.com/jmpews/Dobby.git
[submodule "apk-parser"]
path = apk-parser
url = https://github.com/jaredrummler/APKParser.git
1 change: 1 addition & 0 deletions apk-parser
Submodule apk-parser added at 4b2590
1 change: 1 addition & 0 deletions edxp-common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
api project(':xposed-bridge')
compileOnly project(':dexmaker')
compileOnly 'com.android.support:support-annotations:28.0.0'
implementation project(':apk-parser:library')
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import com.elderdrivers.riru.edxp.config.ConfigManager;
import com.elderdrivers.riru.edxp.util.Hookers;
import com.elderdrivers.riru.edxp.util.Utils;
import com.jaredrummler.apkparser.ApkParser;

import java.io.File;
import java.io.IOException;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
Expand Down Expand Up @@ -55,15 +57,24 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String processName = (String) XposedHelpers.getObjectField(bindData, "processName");


final ApplicationInfo ai = ActivityThread.currentActivityThread().getSystemContext().getPackageManager().getApplicationInfo(appInfo.packageName, PackageManager.GET_META_DATA);
boolean isModule = false;
int xposedminversion = -1;
try {
ApkParser ap = ApkParser.create(new File(appInfo.sourceDir));
isModule = ap.getApkMeta().metaData.containsKey("xposedmodule");
if(isModule)
xposedminversion = Integer.parseInt(ap.getApkMeta().metaData.get("xposedminversion"));
} catch (NumberFormatException | IOException e) {
Hookers.logE("ApkParser fails", e);
}

if(ai.metaData.getBoolean("xposedmodule") && ai.metaData.getInt("xposedminversion", -1) > 92) {
if (isModule && xposedminversion > 92) {
Utils.logW("New modules detected, hook preferences");
XposedHelpers.findAndHookMethod(ContextImpl.class, "getSharedPreferences", File.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String fileName = ((File)param.args[0]).getName();
File file = new File(ConfigManager.getPrefsPath(ai.packageName), fileName);
String fileName = ((File) param.args[0]).getName();
File file = new File(ConfigManager.getPrefsPath(appInfo.packageName), fileName);
file.createNewFile();
file.setReadable(true, false);
param.args[0] = file;
Expand Down
3 changes: 0 additions & 3 deletions edxp-core/src/main/cpp/main/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ inline constexpr bool is64 = Is64();
static const auto kLibArtName = "libart.so"s;
static const auto kLibFwName = "libandroidfw.so"s;
static const auto kLibSandHookName = "libsandhook.edxp.so"s;
static const auto kLibDlName = "libdl.so"s;
static const auto kLibSandHookNativeName = "libsandhook-native.so"s;

static const auto kLibBasePath =
LP_SELECT("/system/lib/"s,
"/system/lib64/"s);
static const auto kLibArtLegacyPath = kLibBasePath + kLibArtName;
static const auto kLibSandHookPath = kLibBasePath + kLibSandHookName;
static const auto kLibSandHookNativePath = kLibBasePath + kLibSandHookNativeName;
static const auto kLibFwPath = kLibBasePath + kLibFwName;

inline constexpr const char *const BoolToString(bool b) {
Expand Down
3 changes: 2 additions & 1 deletion edxp-core/src/main/cpp/main/src/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ namespace edxp {
if (!app_pkg_name.empty())
scope.emplace(std::move(app_pkg_name));
}
scope.insert(module_pkg_name); // Always add module itself
if(!scope.empty())
scope.insert(module_pkg_name); // Always add module itself
if (IsInstaller(module_pkg_name)) scope.erase("android");
LOGI("scope of %s is:\n%s", module_pkg_name.c_str(), ([&scope = scope]() {
std::ostringstream join;
Expand Down
2 changes: 0 additions & 2 deletions edxp-core/template_override/customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,13 @@ else
ui_print "- Extracting arm libraries"
extract "$ZIPFILE" 'system/lib/libriru_edxp.so' "$MODPATH"
if [[ "${VARIANTS}" == "SandHook" ]]; then
extract "$ZIPFILE" 'system/lib/libsandhook-native.so' "$MODPATH"
extract "$ZIPFILE" 'system/lib/libsandhook.edxp.so' "$MODPATH"
fi

if [ "$IS64BIT" = true ]; then
ui_print "- Extracting arm64 libraries"
extract "$ZIPFILE" 'system/lib64/libriru_edxp.so' "$MODPATH"
if [[ "${VARIANTS}" == "SandHook" ]]; then
extract "$ZIPFILE" 'system/lib64/libsandhook-native.so' "$MODPATH"
extract "$ZIPFILE" 'system/lib64/libsandhook.edxp.so' "$MODPATH"
fi
fi
Expand Down
5 changes: 3 additions & 2 deletions edxp-core/template_override/post-fs-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ sepolicy() {
#fi

DEFAULT_BASE_PATH="${PATH_PREFIX}${EDXP_MANAGER}"
BASE_PATH="/data/misc/$(cat /data/adb/edxp/misc_path)"
MISC_PATH=$(cat /data/adb/edxp/misc_path)
BASE_PATH="/data/misc/$MISC_PATH"

LOG_PATH="${BASE_PATH}/0/log"
CONF_PATH="${BASE_PATH}/0/conf"
Expand Down Expand Up @@ -166,6 +167,6 @@ fi

chcon -R u:object_r:system_file:s0 "${MODDIR}"
chcon -R ${PATH_CONTEXT} "${LOG_PATH}"
chcon -R u:object_r:magisk_file:s0 $BASE_PATH
chown -R ${PATH_OWNER} "${LOG_PATH}"
chmod -R 666 "${LOG_PATH}"
[[ -z "$MISC_PATH" ]] && chcon -R u:object_r:magisk_file:s0 "$BASE_PATH"
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ private Map<String, String> loadEnabledModules(int uid) {
return result;
}

private void updateModuleList(int uid, String packageName) {
private void updateModuleList(int uid) {
Map<String, String> enabledModules = loadEnabledModules(uid);

if (!enabledModules.containsKey(packageName)) return;

try {
File moduleListFile = new File(CONFIG_PATH, uid + "/" + MODULES_LIST_FILENAME);
moduleListFile.createNewFile();
Expand Down Expand Up @@ -157,7 +155,7 @@ public void onReceive(Context context, Intent intent) {
for (Object uh : (List<Object>) m.invoke(um)) {
int uid = (int) uh.getClass().getDeclaredField("id").get(uh);
Utils.logI("updating uid: " + uid);
updateModuleList(uid, packageName);
updateModuleList(uid);
}
Toast.makeText(context, "EdXposed: Updated " + packageName, Toast.LENGTH_SHORT).show();
} catch (Throwable e) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include ':edxp-core', ':xposed-bridge', ':hiddenapi-stubs', ':dexmaker', ':dalvikdx', ':edxp-common', ':edxp-yahfa', ':edxp-sandhook', ':edxp-service'
include ':edxp-core', ':xposed-bridge', ':hiddenapi-stubs', ':dexmaker', ':dalvikdx', ':edxp-common', ':edxp-yahfa', ':edxp-sandhook', ':edxp-service', ':apk-parser:library'
1 change: 1 addition & 0 deletions xposed-bridge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ preBuild.doLast {
}

dependencies {
compileOnly project(':apk-parser:library')
compileOnly files(project(":dexmaker").tasks.getByName("makeJarRelease").outputs)
compileOnly files(project(":hiddenapi-stubs").tasks.getByName("makeStubJar").outputs)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.util.Log;

import com.android.internal.util.XmlUtils;
import com.jaredrummler.apkparser.ApkParser;

import org.xmlpull.v1.XmlPullParserException;

Expand Down Expand Up @@ -72,8 +73,17 @@ public XSharedPreferences(String packageName, String prefFileName) {
Set<String> modules = XposedInit.getLoadedModules();
for (String m : modules) {
if (m.contains("/" + packageName + "-")) {
PackageInfo packageInfo = ((Context) ActivityThread.currentActivityThread().getSystemContext()).getPackageManager().getPackageArchiveInfo(m, PackageManager.GET_META_DATA);
newModule = packageInfo != null && packageInfo.applicationInfo != null && packageInfo.applicationInfo.metaData.getBoolean("xposedmodule") && packageInfo.applicationInfo.metaData.getInt("xposedminversion", -1) > 92;
boolean isModule = false;
int xposedminversion = -1;
try {
ApkParser ap = ApkParser.create(new File(m));
isModule = ap.getApkMeta().metaData.containsKey("xposedmodule");
if(isModule)
xposedminversion = Integer.parseInt(ap.getApkMeta().metaData.get("xposedminversion"));
} catch (NumberFormatException | IOException e) {
Log.w(TAG, "Apk parser fails: " + e);
}
newModule = isModule && xposedminversion > 92;
}
}
if (newModule && XposedInit.prefsBasePath != null) {
Expand Down

0 comments on commit 3036a81

Please sign in to comment.