GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 1,适配win · dreamlike-ocean/UnsafeJava@88d73e6

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
Filter options
  • readme.md
  • unsafe-core/src/main/java/top/dreamlike/unsafe/jni
    • JNIEnv.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎readme.md‎

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 numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ IMPL_LOOKUP这个是无视各种权限的lookup,从它这里获取到的Method
2727
为了应对未来的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字段
2828

2929
> [!WARNING]
30-
> 目前只在Linux x86_64上测试过,其他平台可能需要评估兼容性问题
30+
> 目前只在Linux以及Windows x86_64上测试过,其他平台可能需要评估兼容性问题
3131
3232

3333
当然你也会发现项目里面有另外一种写法,即获取到MethodHandle之后转换为`java.util.function.Function`,这两种形式核心原理是一样的
Collapse file

‎unsafe-core/src/main/java/top/dreamlike/unsafe/jni/JNIEnv.java‎

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 numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
import top.dreamlike.unsafe.helper.JValue;
55
import top.dreamlike.unsafe.helper.NativeHelper;
66

7+
import java.io.File;
78
import java.lang.foreign.*;
89
import java.lang.invoke.MethodHandle;
910
import java.lang.reflect.*;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
1013
import java.util.Arrays;
14+
import java.util.logging.Filter;
1115
import java.util.stream.Collectors;
1216

1317
import static java.lang.StringTemplate.STR;
@@ -548,7 +552,11 @@ private static MemorySegment initMainVM() throws Throwable {
548552
}
549553
//根据当前系统判断使用哪个后缀名
550554
String libName = System.mapLibraryName("jvm");
555+
551556
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+
}
552560
Runtime.getRuntime().load(jvmPath);
553561
MemorySegment jniGetCreatedJavaVM_FP = SymbolLookup.loaderLookup()
554562
.find("JNI_GetCreatedJavaVMs")

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.