Skip to content

Commit

Permalink
Small fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Emerson Lin authored and Emerson Lin committed Mar 27, 2018
1 parent 729957f commit 119436b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// 重复添加同样的依赖,以保证Spellbook能够独立编译
buildscript {
ext {
android_gradle_version = '3.2.0-alpha06'
android_gradle_version = '3.2.0-alpha07'
dokka_version = '0.9.14'
kotlin_version = '1.2.30'
kotlin_version = '1.2.31'
}
repositories {
jcenter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.gh0u1l5.wechatmagician.spellbook

import android.content.Context
import android.os.Build
import com.gh0u1l5.wechatmagician.spellbook.base.EventCenter
import com.gh0u1l5.wechatmagician.spellbook.base.HookerProvider
import com.gh0u1l5.wechatmagician.spellbook.base.Version
import com.gh0u1l5.wechatmagician.spellbook.hookers.*
import com.gh0u1l5.wechatmagician.spellbook.util.BasicUtil.tryAsynchronously
import com.gh0u1l5.wechatmagician.spellbook.util.BasicUtil.tryVerbosely
import com.gh0u1l5.wechatmagician.spellbook.util.XposedUtil
import de.robv.android.xposed.XposedBridge.log
import de.robv.android.xposed.XposedHelpers.*
Expand Down Expand Up @@ -104,19 +102,6 @@ object SpellBook {
?: throw Error("Failed to get the version of $packageName"))
}

/**
* Hooks functions in suitable strategy for corresponding API levels. NOTE: for Android 7.X or
* later, multi-thread causes unexpected crashes with WeXposed, so we drop this feature for now.
*
* @param hook the callback function that actually hook functions using Xposed.
*/
private inline fun tryHook(crossinline hook: () -> Unit) {
when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N -> tryVerbosely { hook() }
else -> tryAsynchronously { try { hook() } catch (t: Throwable) { /* Ignore */ } }
}
}

/**
* Initializes and starts up the SpellBook engine.
*
Expand Down Expand Up @@ -156,7 +141,7 @@ object SpellBook {
}

/**
* Registers all the custom hookers to the Xposed framework using [tryHook].
* Registers all the custom hookers to the Xposed framework using [XposedUtil.postHooker].
*/
private fun registerHookers(hookers: List<HookerProvider>?) {
if (hookers == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Activities : EventCenter() {
override fun afterHookedMethod(param: MethodHookParam) {
val activity = param.thisObject as? Activity ?: return
val menu = param.args[0] as? Menu ?: return
notifyParallel("onMMActivityOptionsMenuCreated") { plugin ->
notify("onMMActivityOptionsMenuCreated") { plugin ->
(plugin as IActivityHook).onMMActivityOptionsMenuCreated(activity, menu)
}
}
Expand All @@ -43,7 +43,7 @@ object Activities : EventCenter() {
override fun beforeHookedMethod(param: MethodHookParam) {
val activity = param.thisObject as? Activity ?: return
val savedInstanceState = param.args[0] as Bundle?
notifyParallel("onActivityCreating") { plugin ->
notify("onActivityCreating") { plugin ->
(plugin as IActivityHook).onActivityCreating(activity, savedInstanceState)
}
}
Expand All @@ -54,7 +54,7 @@ object Activities : EventCenter() {
findAndHookMethod(C.Activity, "onStart", object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
val activity = param.thisObject as? Activity ?: return
notifyParallel("onActivityStarting") { plugin ->
notify("onActivityStarting") { plugin ->
(plugin as IActivityHook).onActivityStarting(activity)
}
}
Expand All @@ -65,7 +65,7 @@ object Activities : EventCenter() {
findAndHookMethod(C.Activity, "onResume", object : XC_MethodHook() {
override fun beforeHookedMethod(param: MethodHookParam) {
val activity = param.thisObject as? Activity ?: return
notifyParallel("onActivityResuming") { plugin ->
notify("onActivityResuming") { plugin ->
(plugin as IActivityHook).onActivityResuming(activity)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ object Database : EventCenter() {
override fun beforeHookedMethod(param: MethodHookParam) {
val thisObject = param.thisObject
val table = param.args[0] as String
val nullColumnHack = param.args[1] as String
val nullColumnHack = param.args[1] as String?
val initialValues = param.args[2] as ContentValues?
val conflictAlgorithm = param.args[3] as Int
notifyWithOperation("onDatabaseInserting", param) { plugin ->
Expand All @@ -107,7 +107,7 @@ object Database : EventCenter() {
override fun afterHookedMethod(param: MethodHookParam) {
val thisObject = param.thisObject
val table = param.args[0] as String
val nullColumnHack = param.args[1] as String
val nullColumnHack = param.args[1] as String?
val initialValues = param.args[2] as ContentValues?
val conflictAlgorithm = param.args[3] as Int
val result = param.result as Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ interface IDatabaseHook {
* otherwise return [Operation.nop]. The Long number represents the row ID of the newly inserted
* row OR -1 if no row is inserted.
*/
fun onDatabaseInserting(thisObject: Any, table: String, nullColumnHack: String, initialValues: ContentValues?, conflictAlgorithm: Int): Operation<Long?> = nop()
fun onDatabaseInserting(thisObject: Any, table: String, nullColumnHack: String?, initialValues: ContentValues?, conflictAlgorithm: Int): Operation<Long?> = nop()

/**
* Called when a WCDB SQLiteDatabase object has returned from [SQLiteDatabase.insertWithOnConflict] method.
Expand All @@ -91,7 +91,7 @@ interface IDatabaseHook {
* @return to replace the original result, return a Long number wrapped by [Operation.replacement],
* otherwise return [Operation.nop].
*/
fun onDatabaseInserted(thisObject: Any, table: String, nullColumnHack: String, initialValues: ContentValues?, conflictAlgorithm: Int, result: Long): Operation<Long?> = nop()
fun onDatabaseInserted(thisObject: Any, table: String, nullColumnHack: String?, initialValues: ContentValues?, conflictAlgorithm: Int, result: Long): Operation<Long?> = nop()

/**
* Called when a WCDB SQLiteDatabase object is going to invoke [SQLiteDatabase.updateWithOnConflict] method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.gh0u1l5.wechatmagician.spellbook.WechatGlobal.wxPackageName
import com.gh0u1l5.wechatmagician.spellbook.util.ReflectionUtil.findClassIfExists

object Classes {
val WebWXLoginUI: Class<*> by wxLazy("WebWXLoginUI") {
val ExtDeviceWXLoginUI: Class<*> by wxLazy("ExtDeviceWXLoginUI") {
findClassIfExists("$wxPackageName.plugin.webwx.ui.ExtDeviceWXLoginUI", wxLoader)
}
}

0 comments on commit 119436b

Please sign in to comment.