Skip to content
New issue

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

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

Already on GitHub? # to your account

New Hook Code Style #33

Open
fankes opened this issue Apr 15, 2023 · 1 comment
Open

New Hook Code Style #33

fankes opened this issue Apr 15, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@fankes
Copy link
Collaborator

fankes commented Apr 15, 2023

New Hook Code Style

This is a proposal.

Since the API's original design mode of constructing a Hook only for a Class does not meet some exceptions, and there are some adaptability problems, so we make a new Hook code style is given below.

The following example

// Single Method Hook
"com.demo.Test".toClass().method {
    name = "test"
    param(StringClass)
}.hook {
    before {
        // Do something...
    }
    after {
        // Do something...
    }
}
// Multiple Methods Hook
"com.demo.Test".toClass().method {
    name = "test"
}.all().hook {
    before {
        // Do something...
    }
    after {
        // Do something...
    }
}
// A Class with multiple Methods Hook
"com.demo.Test".toClass().apply {
    method {
        name = "test"
        param(StringClass)
    }.hook {
        before {
            // Do something...
        }
        after {
            // Do something...
        }
    }
    method {
        name = "another"
        param(IntType)
    }.hook {
        before {
            // Do something...
        }
        after {
            // Do something...
        }
    }
}

Below is the current Hook code style.

The following example

// Single Method Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
            param(StringClass)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}
// Multiple Methods Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
        }.all()
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}
// A Class with multiple Methods Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
            param(StringClass)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
    injectMember {
        method {
            name = "another"
            param(IntType)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}

新的 Hook 代码样式

这是一个提案。

由于 API 最初设计的仅针对一个 Class 构造一个 Hook 的模式不符合一些例外情况,也存在一些适配性问题,所以我们在下方给出了一种新的 Hook 代码样式。

示例如下

// 单一方法 Hook
"com.demo.Test".toClass().method {
    name = "test"
    param(StringClass)
}.hook {
    before {
        // Do something...
    }
    after {
        // Do something...
    }
}
// 多重方法 Hook
"com.demo.Test".toClass().method {
    name = "test"
}.all().hook {
    before {
        // Do something...
    }
    after {
        // Do something...
    }
}
// 一个 Class 多个方法 Hook
"com.demo.Test".toClass().apply {
    method {
        name = "test"
        param(StringClass)
    }.hook {
        before {
            // Do something...
        }
        after {
            // Do something...
        }
    }
    method {
        name = "another"
        param(IntType)
    }.hook {
        before {
            // Do something...
        }
        after {
            // Do something...
        }
    }
}

下方是现在采用的 Hook 代码样式。

示例如下

// 单一方法 Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
            param(StringClass)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}
// 多重方法 Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
        }.all()
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}
// 一个 Class 多个方法 Hook
"com.demo.Test".toClass().hook {
    injectMember {
        method {
            name = "test"
            param(StringClass)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
    injectMember {
        method {
            name = "another"
            param(IntType)
        }
        beforeHook {
            // Do something...
        }
        afterHook {
            // Do something...
        }
    }
}
@fankes fankes self-assigned this Apr 15, 2023
@fankes fankes converted this from a draft issue Apr 15, 2023
@fankes fankes moved this from Todo to In Progress in YukiHookAPI Features Plan Apr 15, 2023
@fankes fankes added the enhancement New feature or request label Apr 15, 2023
@fankes
Copy link
Collaborator Author

fankes commented Apr 15, 2023

This feature will completed on 2.0.0 version, and will make a preview on 1.2.0 version.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant