Skip to content

Commit

Permalink
移动Native到NativeOld|神金Karlatemp,太极霸耦合了😅
Browse files Browse the repository at this point in the history
  • Loading branch information
EarzuChan committed Aug 15, 2024
1 parent d3171b8 commit 56ae519
Show file tree
Hide file tree
Showing 38 changed files with 423 additions and 340 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
chmod +x .scripts/setup_docker.sh
- name: 为 ${{ matrix.cross }} 注册米哈游通行证
run: ./gradlew build
- name: Build native (${{ matrix.cross }})
- name: (${{ matrix.cross }}) 成为米孝子的第一天捏
run: .scripts/setup_docker.sh
env:
CROSS: ${{ matrix.cross }}
Expand All @@ -41,7 +41,7 @@ jobs:
with:
name: ${{ matrix.cross }}
path: |
native/cmake-build-release/bin
native-old/build/bin
build-jars:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.gradle
.idea
*.log
/native/cmake*
/native-old/cmake*
build/
*.class

native-build/

temp/
.vscode
/native/build
/native-old/build
10 changes: 5 additions & 5 deletions .scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cd native
cd native-old

rm -rf cmake-build-release
mkdir cmake-build-release
cd cmake-build-release
rm -rf build
mkdir build
cd build

echo "开始配置构建"
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CACHEFILE_DIR=$PWD -Dcross_triple=$CROSS ..
echo "开始构建本机库"
cmake --build . --target native -- -j 3
cmake --build . --target sakiko -- -j 3

ecode=$?

Expand Down
10 changes: 5 additions & 5 deletions .scripts/build_on_win.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
cd native
cd native-old

rm -rf cmake-build-release
mkdir cmake-build-release
cd cmake-build-release
rm -rf build
mkdir build
cd build

echo "开始配置构建"
cmake -DCMAKE_BUILD_TYPE=Release .. -G "MinGW Makefiles"
echo "开始构建本机库"
cmake --build . --target native -- -j 3
cmake --build . --target sakiko -- -j 3

ecode=$?

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ Sakiko是一款跨平台的JavaHook方案,旨在提供更灵活的JVM内部Hoo
- `sakiko-old-0.11.4.514-core.jar` - **旧版**运行时Java库
- `sakiko-old-0.11.4.514-launcher.jar` - **旧版**启动器包(Java Agent)
- **平台-架构.zip**
- `libnative.dll` / `libnative.so` - 本机库
- `libsakiko.dll` / `libsakiko.so` - 本机库

使用Sakiko,您需要修改Java命令行,格式如下:

```shell
java -agentpath:/path/to/libnative.so -javaagent:/path/to/sakiko-old-0.11.4.514-launcher.jar ...
java -agentpath:/path/to/libsakiko.so -javaagent:/path/to/sakiko-old-0.11.4.514-launcher.jar ...
```

## 克隆与构建
Expand Down
16 changes: 10 additions & 6 deletions api/src/main/kotlin/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ class UnhookConfig(private val method: Method) {
}

class HookConfig {
var before: (() -> Unit)? = null
var after: (() -> Unit)? = null
var beforeLambda: (HookContext.() -> Unit)? = null
var afterLambda: (HookContext.() -> Unit)? = null

fun before(action: () -> Unit) {
before = action
fun before(action: HookContext.() -> Unit) {
beforeLambda = action
}

fun after(action: () -> Unit) {
after = action
fun after(action: HookContext.() -> Unit) {
afterLambda = action
}
}

class HookContext(val args: Array<Any?>) {

}
14 changes: 9 additions & 5 deletions core/src/main/kotlin/Core.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package me.earzuchan.sakiko.core

import me.earzuchan.sakiko.api.HookConfig
import me.earzuchan.sakiko.api.HookContext
import me.earzuchan.sakiko.api.SakikoBaseModule
import me.earzuchan.sakiko.api.SakikoBridge
import me.earzuchan.sakiko.core.util.Log
import java.lang.reflect.Method

const val TAG = "SakikoCore"

// Karlatemp圣千古
object KarlatempNativeCompat {
external fun initNative(): Boolean
}

object Runner {
fun runModule(module: SakikoBaseModule) {
module.onHook()
Expand All @@ -20,23 +26,21 @@ object Runner {
ensureBridge()
}

private external fun helloMamba(): Boolean

private fun ensureNative() {
if (!helloMamba()) {
if (!KarlatempNativeCompat.initNative()) {
throw UnsatisfiedLinkError("Native library status is not OK")
}

Log.debug(TAG, "Native library loaded")
}

private fun ensureBridge() {
SakikoBridge.INSTANCE = SakikoBridgeImpl()
SakikoBridge.INSTANCE = SakikoKarlatempBridge()
Log.debug(TAG, "Bridge initialized")
}
}

public class SakikoBridgeImpl : SakikoBridge() {
public class SakikoKarlatempBridge : SakikoBridge() {
override fun hook(method: Method, config: HookConfig) {
Log.debug(TAG, "Hook ${method.name}")
}
Expand Down
2 changes: 1 addition & 1 deletion loader/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tasks.register<JavaExec>("testLoader") {
mainClass.set("me.earzuchan.sakiko.loader.LoaderEntry")

doFirst {
val nativeLibDir = file("${project.rootDir}/native/cmake-build-release")
val nativeLibDir = file("${project.rootDir}/native-old/build")
val nativeLib = nativeLibDir.listFiles()?.firstOrNull { it.extension == "dll" || it.extension == "so" }
val agentJar = tasks.named<Jar>("agentJar").get().archiveFile.get().asFile

Expand Down
2 changes: 1 addition & 1 deletion native/CMakeLists.txt → native-old/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ set(CMAKE_ANDROID_ARM_NEON ON)
set(CMAKE_ANDROID_STL_TYPE system)
add_compile_definitions(DEBUG)

add_library(native SHARED ${SRC_DIR} src/lib.cpp)
add_library(sakiko SHARED ${SRC_DIR} src/lib.cpp)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 56ae519

Please sign in to comment.