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

New Hook Entry Class #48

Open
fankes opened this issue Sep 20, 2023 · 0 comments
Open

New Hook Entry Class #48

fankes opened this issue Sep 20, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@fankes
Copy link
Collaborator

fankes commented Sep 20, 2023

New Hook Entry Class

The entry class currently used by the API is designed with reference to the working mode and principle of the native Xposed API.

The biggest problem encountered so far is the logical confusion of the entry class.

For example, we cannot clearly get a Host App's lifecycle from the beginning.

The current API solution is to use onAppLifecycle to monitor the Host App's lifecycle method.

So we may adopt a new entry class design pattern in later versions to bring better experience to Xposed Module developers.

The following example

@YukiXposedModule
class YourModule(hookContext: HookContext) : YukiBaseModule(hookContext: HookContext) {

    init {
        YukiHookAPI.configs {
            isDebug = false
        }
        // HookContext means the global system context
        hookContext.packageName // "android"
        // Listen to the loading events of the native Xposed API
        YukiXposedEvent.events {
            onInitZygote {
                // The it object is [StartupParam]
            }
            onHandleLoadPackage {
                // The it object is [LoadPackageParam]
            }
            onHandleInitPackageResources {
                // The it object is [InitPackageResourcesParam]
            }
        }
    }

    override fun onHook() {
        loadApp(name = "com.example.demo") {
            // Do something...
        }
    }
}

Below are the current entry class schemes.

The following example

@InjectYukiHookWithXposed
object HookEntry : IYukiHookXposedInit {

    override fun onInit() = configs {
        isDebug = false
    }

    override fun onHook() = encase {
        loadApp(name = "com.example.demo") {
            // Do something...
        }
    }

    override fun onXposedEvent() {
        // Listen to the loading events of the native Xposed API
        YukiXposedEvent.events {
            onInitZygote {
                // The it object is [StartupParam]
            }
            onHandleLoadPackage {
                // The it object is [LoadPackageParam]
            }
            onHandleInitPackageResources {
                // The it object is [InitPackageResourcesParam]
            }
        }
    }
}

新的入口类方案

API 目前采用的入口类参考了原生 Xposed API 的工作模式与原理而设计,目前遇到的最大的问题就是入口类逻辑上的混乱问题。

例如我们无法从开始就明确地得到一个宿主的生命周期,目前 API 给出的解决方案是使用 onAppLifecycle 来监听宿主的生命周期方法。

所以我们可能会在后期的版本采用一种新的入口类设计模式来给 Xposed 模块开发者带来更好的体验。

示例如下

@YukiXposedModule
class YourModule(hookContext: HookContext) : YukiBaseModule(hookContext: HookContext) {

    init {
        YukiHookAPI.configs {
            isDebug = false
        }
        // HookContext 即全局系统上下文
        hookContext.packageName // "android"
        // 监听原生 Xposed API 的装载事件
        YukiXposedEvent.events {
            onInitZygote {
                // it 对象即 [StartupParam]
            }
            onHandleLoadPackage {
                // it 对象即 [LoadPackageParam]
            }
            onHandleInitPackageResources {
                // it 对象即 [InitPackageResourcesParam]
            }
        }
    }

    override fun onHook() {
        loadApp(name = "com.example.demo") {
            // Do something...
        }
    }
}

以下是目前采取的入口类方案。

示例如下

@InjectYukiHookWithXposed
object HookEntry : IYukiHookXposedInit {

    override fun onInit() = configs {
        isDebug = false
    }

    override fun onHook() = encase {
        loadApp(name = "com.example.demo") {
            // Do something...
        }
    }

    override fun onXposedEvent() {
        // 监听原生 Xposed API 的装载事件
        YukiXposedEvent.events {
            onInitZygote {
                // it 对象即 [StartupParam]
            }
            onHandleLoadPackage {
                // it 对象即 [LoadPackageParam]
            }
            onHandleInitPackageResources {
                // it 对象即 [InitPackageResourcesParam]
            }
        }
    }
}
@fankes fankes self-assigned this Sep 20, 2023
@fankes fankes added the enhancement New feature or request label Sep 20, 2023
@fankes fankes added this to the 2.0.0 milestone Sep 20, 2023
@fankes fankes pinned this issue Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant