Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过修改AndroidManifest注册provider,注册application,进行低侵入式注册 #42

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ buildscript {
repositories {
maven { url 'https://maven.google.com' }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.novoda:bintray-release:0.3.4'

// NOTE: Do not place your application dependencies here; they belong
Expand Down
11 changes: 0 additions & 11 deletions exposed-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,3 @@ dependencies {

group = 'me.weishu.exposed'
version = '0.8.0'

apply plugin: 'com.novoda.bintray-release'

publish {
userOrg = 'twsxtd'
groupId = "${project.group}"
artifactId = "${project.name}"
publishVersion = "${project.version}"
desc = 'Xposed Wrapper in non-root environment'
website = 'https://github.com/android-hacker/exposed'
}
32 changes: 32 additions & 0 deletions exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Set;

import dalvik.system.DexClassLoader;
import dalvik.system.PathClassLoader;
import de.robv.android.xposed.DexposedBridge;
import de.robv.android.xposed.ExposedHelper;
import de.robv.android.xposed.IXposedHookInitPackageResources;
Expand Down Expand Up @@ -284,6 +285,37 @@ public static ModuleLoadResult loadModule(final String moduleApkPath, String mod
return ModuleLoadResult.FAILED;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}
```exposed-core/src/main/java/me/weishu/exposed/ExposedBridge.java


public static void loadModule(Context context) {
String dexPacName = "com.debby.xposetest";
try {
ClassLoader originClassLoader = context.getClassLoader();
ApplicationInfo info = context.getPackageManager().getApplicationInfo(dexPacName, 0);
ClassLoader appClassLoaderWithXposed = getAppClassLoaderWithXposed(originClassLoader);
ClassLoader mcl = new PathClassLoader(info.sourceDir, getXposedClassLoader(ExposedBridge.class.getClassLoader()));
Class<?> moduleClass = mcl.loadClass("com.debby.xposetest.HookLogic");
final Object moduleInstance = moduleClass.newInstance();

if (moduleInstance instanceof IXposedHookLoadPackage) {
IXposedHookLoadPackage.Wrapper wrapper = new IXposedHookLoadPackage.Wrapper((IXposedHookLoadPackage) moduleInstance);
XposedBridge.CopyOnWriteSortedSet<XC_LoadPackage> xc_loadPackageCopyOnWriteSortedSet = new XposedBridge.CopyOnWriteSortedSet<>();
xc_loadPackageCopyOnWriteSortedSet.add(wrapper);
XC_LoadPackage.LoadPackageParam lpparam = new XC_LoadPackage.LoadPackageParam(xc_loadPackageCopyOnWriteSortedSet);
ApplicationInfo currentApplicationInfo = context.getApplicationInfo();

lpparam.packageName = currentApplicationInfo.packageName;
lpparam.processName = currentApplicationInfo.processName;
lpparam.classLoader = appClassLoaderWithXposed;
lpparam.appInfo = currentApplicationInfo;
lpparam.isFirstApplication = true;
XC_LoadPackage.callAll(lpparam);
}
} catch (Throwable t) {
Log.e("InitProvider", t.getMessage());
log(t);
}
}


private static boolean ignoreHooks(Member member) {
if (member == null) {
return false;
Expand Down
52 changes: 52 additions & 0 deletions exposed-core/src/main/java/me/weishu/exposed/InitProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package me.weishu.exposed;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

/**
* Create by wakfu on 2020/7/14
*/
public class InitProvider extends ContentProvider {

@Override
public boolean onCreate() {
Log.e("InitProvider", "onCreate");
Context context = getContext();
if (context != null) {
ExposedBridge.initOnce(context, context.getApplicationInfo(), context.getClassLoader());
ExposedBridge.loadModule(context);
} else {
Log.e("InitProvider", "onCreateFail");
}
return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
return null;
}

@Override
public String getType(Uri uri) {
return null;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
return 0;
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Nov 30 19:01:20 CST 2017
#Sat Jul 25 09:21:35 CST 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip