Skip to content

Commit c7bc4a2

Browse files
authored
Merge pull request #6 from vadage/develop
Merge develop into main
2 parents da3d4b9 + 43a2db0 commit c7bc4a2

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "jvm-hook"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Keep this in mind as you use this feature in your projects.
1313

1414
## Compatibility
1515
### ✅ Java
16-
All Java versions should be supported, as `jni` is only used for the structs and no method calls or such.<br>
16+
The export `JVM_DefineClassWithSource` was only added in JDK1.5, therefore all Java versions starting from `Java 6` are supported (there is no JNI version for `Java 5`).<br>
1717
Thus far only `Java 8`, `Java 20` and `Java 21` were explicitly tested.
1818

1919
### ✅ Operating system

src/class_loader.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::mem;
1+
use std::ops::Deref;
22
use std::os::raw::c_char;
33
use std::slice::from_raw_parts_mut;
44

@@ -26,9 +26,8 @@ impl ClassLoader {
2626
pub unsafe fn setup_hook() {
2727
let handle = Library::new("jvm").expect("Could not find jvm library.");
2828
let method = handle.get::<DefineClassCommon>(b"JVM_DefineClassWithSource").expect("Could not find exported function.");
29-
let target: DefineClassCommon = mem::transmute(method);
3029

31-
let hook = DefineClassCommonHook.initialize(target, ClassLoader::hooked_define_class_common).expect("Could not initialize hook for class loading.");
30+
let hook = DefineClassCommonHook.initialize(*method.deref(), ClassLoader::hooked_define_class_common).expect("Could not initialize hook for class loading.");
3231
hook.enable().expect("Could not to hook into class loading.");
3332
}
3433

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ mod jvm;
33

44
use std::os::raw::c_void;
55
use jni::JavaVM;
6-
use jni::sys::{jint, JNI_VERSION_1_1};
6+
use jni::sys::{jint, JNI_VERSION_1_6};
77
use class_loader::ClassLoader;
88

99
#[no_mangle]
1010
pub unsafe extern "system" fn JNI_OnLoad(_: JavaVM, _: *mut c_void) -> jint {
1111
ClassLoader::setup_hook();
12-
return JNI_VERSION_1_1;
12+
return JNI_VERSION_1_6;
1313
}

0 commit comments

Comments
 (0)