This repository was archived by the owner on Jun 30, 2026. It is now read-only.
File tree
Expand file treeCollapse file tree
Open diff view settings
unsafe-core/src/main/java/top/dreamlike/unsafe/jni
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: readme.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -27,7 +27,7 @@ IMPL_LOOKUP这个是无视各种权限的lookup,从它这里获取到的Method |
27 | 27 | 为了应对未来的Unsafe中的某些内存操作被移除的问题,在[寒老板](https://github.com/IceSoulHanxi)的一次群聊中提到了几个java动态库导出的符号,我们逆向了这些符号以及正向参考了openjdk源码,[使用Panama API封装了大部分的JNI操作](https://github.com/dreamlike-ocean/backend_qingyou/blob/main/dreamlike%E7%9A%84%E7%A7%81%E8%B4%A7/afterUnsafe.md),使得可以绕开模块化之类的限制让我们继续可以hack标准库,继续能拿到IMPL_LOOKUP字段 |
28 | 28 |
|
29 | 29 | > [!WARNING] |
30 | | -> 目前只在Linux x86_64上测试过,其他平台可能需要评估兼容性问题 |
| 30 | +> 目前只在Linux以及Windows x86_64上测试过,其他平台可能需要评估兼容性问题 |
31 | 31 |
|
32 | 32 |
|
33 | 33 | 当然你也会发现项目里面有另外一种写法,即获取到MethodHandle之后转换为`java.util.function.Function`,这两种形式核心原理是一样的 |
|
Collapse file
Copy file name to clipboardExpand all lines: unsafe-core/src/main/java/top/dreamlike/unsafe/jni/JNIEnv.java +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
4 | 4 | import top.dreamlike.unsafe.helper.JValue; |
5 | 5 | import top.dreamlike.unsafe.helper.NativeHelper; |
6 | 6 |
|
| 7 | +import java.io.File; |
7 | 8 | import java.lang.foreign.*; |
8 | 9 | import java.lang.invoke.MethodHandle; |
9 | 10 | import java.lang.reflect.*; |
| 11 | +import java.nio.file.Files; |
| 12 | +import java.nio.file.Path; |
10 | 13 | import java.util.Arrays; |
| 14 | +import java.util.logging.Filter; |
11 | 15 | import java.util.stream.Collectors; |
12 | 16 |
|
13 | 17 | import static java.lang.StringTemplate.STR; |
@@ -548,7 +552,11 @@ private static MemorySegment initMainVM() throws Throwable { |
548 | 552 | } |
549 | 553 | //根据当前系统判断使用哪个后缀名 |
550 | 554 | String libName = System.mapLibraryName("jvm"); |
| 555 | + |
551 | 556 | String jvmPath = STR."\{javaHomePath}/lib/server/\{libName}"; |
| 557 | + if (!Files.exists(Path.of(STR."\{javaHomePath}/lib/server/\{libName}"))) { |
| 558 | + jvmPath = STR."\{javaHomePath}/bin/server/\{libName}"; |
| 559 | + } |
552 | 560 | Runtime.getRuntime().load(jvmPath); |
553 | 561 | MemorySegment jniGetCreatedJavaVM_FP = SymbolLookup.loaderLookup() |
554 | 562 | .find("JNI_GetCreatedJavaVMs") |
|