Skip to content

Commit

Permalink
remove Resources hook
Browse files Browse the repository at this point in the history
  • Loading branch information
imlk0 committed Mar 21, 2018
1 parent 3f88870 commit a628d9f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android {
applicationId "top.imlk.undo"
minSdkVersion 14
targetSdkVersion 26
versionCode 20
versionCode 21
versionName "1.0.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
Binary file added app/release/app-release_v1.0.2.apk
Binary file not shown.
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3},"path":"app-release.apk","properties":{"packageId":"top.imlk.undo","split":"","minSdkVersion":"14"}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":20},"path":"app-release.apk","properties":{"packageId":"top.imlk.undo","split":"","minSdkVersion":"14"}}]
18 changes: 18 additions & 0 deletions app/src/main/java/top/imlk/undo/holder/IResources.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
package top.imlk.undo.holder;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;

import java.lang.reflect.Method;

/**
* Created by imlk on 2018/3/18.
*/

public class IResources {
public static Resources resources;
public static String MODULE_PATH;

public static void initResources(Context context) {

try {
MODULE_PATH = context.getPackageManager().getApplicationInfo("top.imlk.undo", 0).sourceDir;
AssetManager assetManager = AssetManager.class.newInstance();
Method addAssetPath = AssetManager.class.getMethod("addAssetPath", String.class);
addAssetPath.invoke(assetManager, MODULE_PATH);
resources = new Resources(assetManager, context.getResources().getDisplayMetrics(), context.getResources().getConfiguration());
} catch (Exception e) {

}
}
}
28 changes: 7 additions & 21 deletions app/src/main/java/top/imlk/undo/hooker/Injecter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@


import android.content.Context;
import android.content.res.XModuleResources;
import android.os.Build;
import android.os.Debug;
import android.util.AttributeSet;
import android.util.Log;
import android.view.ActionMode;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import de.robv.android.xposed.IXposedHookInitPackageResources;
import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_InitPackageResources;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import top.imlk.undo.holder.ITag;
import top.imlk.undo.proxy.IActionModeCallbackProxy;
Expand All @@ -29,25 +22,13 @@
import top.imlk.undo.proxy.IActionPopupWindowProxy;


public class Injecter implements IXposedHookLoadPackage, IXposedHookZygoteInit, IXposedHookInitPackageResources {
public class Injecter implements IXposedHookLoadPackage {

public static String MODULE_PATH = null;


@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) throws Throwable {
MODULE_PATH = startupParam.modulePath;
}

@Override
public void handleInitPackageResources(XC_InitPackageResources.InitPackageResourcesParam resparam) throws Throwable {
IResources.resources = XModuleResources.createInstance(MODULE_PATH, resparam.res);

}

@Override
public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {


// for(Method method : View.class.getDeclaredMethods()){
// XposedBridge.log(method.getReturnType().getName() + " " + method.getName() + "(");
// for(Class clazz : method.getParameterTypes()){
Expand All @@ -62,6 +43,11 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Th
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);

//初始化resources
if (IResources.resources == null) {
IResources.initResources(((Context) param.args[0]));
}

//TODO change ID from 7f to 77
if ((((EditText) param.thisObject).getTag(ITag.TOP_IMLK_UNDO_INJECTED_TAG) == null)
|| (!(((EditText) param.thisObject).getTag(ITag.TOP_IMLK_UNDO_INJECTED_TAG) instanceof Boolean))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (shouldDo()) {
newIUndoOperation = new IUndoOperation();

Log.e("Changed", "" + newIUndoOperation.time);
// Log.e("Changed", "" + newIUndoOperation.time);


newIUndoOperation.start = start;
Expand Down

0 comments on commit a628d9f

Please sign in to comment.