forked from Karlatemp/JvmHookFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,189 @@ | ||
# 祥子 Sakiko - 一款适用于JVM的Hook框架 | ||
# 祥子 Sakiko - 次世代的Java Hook解决方案 | ||
|
||
> 注意 | ||
> **注意** | ||
> | ||
> 本项目Fork自`Karlatemp`的`JvmHookFramework` | ||
> 本项目**Fork**自**Karlatemp**的**JvmHookFramework** | ||
> | ||
> 原开发者说不适合在正式环境使用, 很慢(悲 | ||
> | ||
> 另外由于麻烦,暂时不提供macOS平台的本机库CI构建 | ||
> **原开发者**表示**不适合**在**正式环境**使用,速度**较慢** | ||
> | ||
> 本库的名字来自于`BanG Dream! It's MyGO!!!!!`中的丰川祥子 | ||
> 由于**开发不便**,暂不提供**macOS平台**的**本机库CI构建** | ||
> | ||
> 项目名称源自于 **BanG Dream! It's MyGO!!!!!** 中的角色**丰川祥子** | ||
## 下载 | ||
## 概述 | ||
|
||
点击 [Actions](https://github.com/EarzuChan/Sakiko/actions) | ||
点击最后一个成功运行的`Action` | ||
Sakiko是一款跨平台的JavaHook方案,旨在提供更灵活的JVM内部Hook机制。目前已支持在桌面端JVM中通过JvmTI进行Hook。 | ||
|
||
拖到最下面, 在`Artifacts`中点击`Jars`和为相应平台构建的本机库(如 `windows-shared-x64`) | ||
## 特性 | ||
|
||
- **跨平台支持**:适用于多种操作系统,方便不同平台的开发者使用。 | ||
- **提供API与本机库**:开发者可以通过提供的API和本机库进行Hook操作。 | ||
|
||
## 下载 | ||
|
||
1. 前往 [Actions](https://github.com/EarzuChan/Sakiko/actions) | ||
2. 找到最后一个成功运行的Action | ||
3. 向下滚动,在Artifacts部分下载Jars和相应平台的本机库(例如windows-shared-x64)。 | ||
|
||
## 运行 | ||
|
||
下载之后, 应该有如下文件 | ||
|
||
```text | ||
Jars.zip | ||
`- api-1.0.0.jar - The api for developers | ||
`- jvm-hook-framework-core.jar - Runtime java library (shadowed) | ||
`- jvm-hook-framework-launcher.jar - JHF Launcher (Javaagent) | ||
`- jvm-hook-framework-launcher-obf.jar - JHF Launcher (Javaagent) (Relocated) | ||
`- jvm-hook-framework-obf.jar - JHF Launcher (Javaagent) (Relocated) (Not runnable) | ||
NativeLib.zip | ||
`- libnative.dll / libnative.so - native lib (native agent) | ||
``` | ||
下载后,您应该看到以下文件: | ||
|
||
你需要按照如下的格式修改你的Java命令行来使用Sakiko | ||
- **Jars.zip**: | ||
- `api-old-0.11.4.514.jar` - **旧版**开发者API包 | ||
- `sakiko-old-0.11.4.514-core.jar` - **旧版**运行时Java库 | ||
- `sakiko-old-0.11.4.514-launcher.jar` - **旧版**启动器包(Java Agent) | ||
- **平台-架构.zip**: | ||
- `libnative.dll` / `libnative.so` - 本机库 | ||
|
||
使用Sakiko,您需要修改Java命令行,格式如下: | ||
|
||
```shell | ||
java -agentpath:/path/to/libnative.so -javaagent:/path/to/jvm-hook-framework-launcher.jar ... | ||
# Or | ||
java -agentpath:/path/to/libnative.so -javaagent:/path/to/jvm-hook-framework-launcher-obf.jar ... | ||
java -agentpath:/path/to/libnative.so -javaagent:/path/to/sakiko-old-0.11.4.514-launcher.jar ... | ||
``` | ||
|
||
## 克隆与构建 | ||
|
||
注意克隆后如果再推送到你自己的新远程仓库,注意提交里要包含CMakelists.txt,不然CI构建会失败(悲 | ||
请注意,在克隆并推送到您自己的远程仓库时,务必确保提交中包含`CMakeLists.txt`,否则CI构建将失败。 | ||
|
||
## 旧模块范式【已过时】 | ||
|
||
### 开发模块 | ||
|
||
新建一个**生成Jar**的**Java Library**项目,并将`api-old`包添加为**项目依赖**。 | ||
|
||
将一个名为`module_entries`的文件放在**Jar的根目录**下,文件的**每一行**代表**一个入口点类名**。 | ||
|
||
在您的**入口类**中创建一个**静态方法**`load`,通过`io.github.karlatemp.jvmhook.JvmHookFramework`类的**静态字段**`INSTANCE`获取**预先提供的**`JvmHookFramework`实例,进行**Hook操作**。 | ||
|
||
## 安装扩展【旧扩展范式】 | ||
示例: | ||
|
||
第一次正确运行Java命令后, 会在运行目录创建一个名为`jvm-hook-framework-extensions`的文件夹 | ||
```java | ||
public class MyModule | ||
{ | ||
public static void load() | ||
{ | ||
// 度尽劫波兄弟在,相逢一笑泯恩仇 | ||
} | ||
} | ||
``` | ||
|
||
### 安装模块 | ||
|
||
把扩展放进这个文件夹里 | ||
首次正确运行Java命令后,将在运行目录创建一个名为`sakiko-modules`的文件夹。将模块放入该文件夹。 | ||
|
||
想要把扩展放到其它的目录下?只需要把自定义文件夹路径设置为系统环境变量`JVM_HOOK_FRAMEWORK_EXTENSIONS` | ||
如果希望将模块放在其他目录下,只需设置环境变量`SAKIKO_MODULES`为您放置模块的目录即可。 | ||
|
||
Shell脚本示例: | ||
|
||
```shell | ||
#!/usr/bin/env bash | ||
|
||
JVM_HOOK_FRAMEWORK_EXTENSIONS=/path/to/other/dir | ||
java .... | ||
SAKIKO_MODULES=/path/to/other/dir | ||
java ... | ||
``` | ||
|
||
## 开发扩展【旧扩展范式】 | ||
## 新模块范式【待开发】 | ||
|
||
### 开发模块 | ||
|
||
您需要新建一个**打包成Jar**的**JavaLibrary**项目,并根据以下格式填写配置项文件。 | ||
|
||
```yaml | ||
generator: | ||
target-type: COMPAT | ||
use-xxx: true # 指定使用一些特定的功能(参见文档) | ||
|
||
hook-module: | ||
package-name: com.mamba # 您的模块包名 | ||
java-entry: com.mamba.MambaModule # 您的Java库入口点 | ||
native-entry: mamba # 您的本机库入口点 | ||
description: My new Hook Module. # 模块描述 | ||
api-level: 1919810 # API等级 | ||
host-scopes: # 主机作用域 | ||
- com.xxx.universe.system # 一条主机作用域 | ||
``` | ||
将配置项文件命名为**module_profile**,并放在**Jar的根目录**下。 | ||
开发新版本模块需要使用Kotlin语言,以下是一个示例代码片段: | ||
```kotlin | ||
@SakikoHookModule | ||
class MambaModule(hookContext: HookContext) : SakikoBaseModule(hookContext) { | ||
init { // 初始化 | ||
SakikoHookAPI.configs { // 配置 | ||
isDebug = false // 是否开启调试 | ||
} | ||
} | ||
|
||
override fun onHook() { | ||
// 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... | ||
} | ||
} | ||
|
||
// 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... | ||
} | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### 安装模块 | ||
|
||
【待计划】 | ||
|
||
### 说明 | ||
|
||
新建一个生成Jar的Java库项目,并将Api包添加为项目依赖 | ||
这种范式受到未发布的新版YukiHook的启发,而且还没开始实现。 | ||
|
||
将一个名为`jvm-hook-ext.txt`的文件放在Jar的根目录下,文件内容是您的扩展类的完整类名 | ||
该新Hook模块范式旨在提供一个灵活且易于配置的方式来创建和使用Hook模块。通过设置jar元数据和实现主类中的Hook逻辑,用户可以轻松地对指定的类和方法进行Hook。 | ||
|
||
在您的类中创建一个静态方法`load`,通过`io.github.karlatemp.jvmhook.JvmHookFramework`类的静态字段`INSTANCE`获取事先提供的的`JvmHookFramework实例`,这样就可以爽Hook了(喜 | ||
## 展望 | ||
|
||
示例:[TestExtension](testunit/src/main/java/teunit/ext/Ext.java) | ||
- **KotlinHookAPI**:未来计划开发一套新的KotlinHookAPI,提供更便捷的Hook方式。 | ||
- **安卓端Hook支持**:通过LSPosed的LSPlant,实现对安卓平台的Hook。 | ||
- **桌面端内存修改Hook**:计划为桌面端JVM平台开发类似LSPlant的内存修改Hook方案,尽管可能对特定的JVM版本和型号有要求,适用性可能较差。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ plugins { | |
} | ||
dependencies { | ||
implementation(kotlin("stdlib-jdk8")) | ||
|
||
} | ||
repositories { | ||
mavenCentral() | ||
|