gpt4 book ai didi

java - 使用 Java 访问内存

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:13:45 25 4
gpt4 key购买 nike

我在内存中加载了一个程序。现在我想直接访问内存并为该程序更改内存中的 OPCODE 和 DATA。为此,我需要编写一个 Java 程序。

你能告诉我这是否可行吗?如果是,请告诉我如何编写这样的程序。

提前致谢!

最佳答案

Java 不是为此而设计的。
Java 的主要目的是让 JVM 为您管理内存。因此,您的程序是沙盒化的。

但是,HotSpot JVM 中似乎有一个后门:

Java was initially designed as a safe, managed environment. Nevertheless, Java HotSpot VM contains a “backdoor” that provides a number of low-level operations to manipulate memory and threads directly. This backdoor – sun.misc.Unsafe – is widely used by JDK itself in the packages like java.nio or java.util.concurrent. It is hard to imagine a Java developer who uses this backdoor in any regular development because this API is extremely dangerous, non portable, and volatile. Nevertheless, Unsafe provides an easy way to look into HotSpot JVM internals and do some tricks. Sometimes it is simply funny, sometimes it can be used to study VM internals without C++ code debugging, sometimes it can be leveraged for profiling and development tools.

来源:http://highlyscalable.wordpress.com/2012/02/02/direct-memory-access-in-java/

但是,Unsafe 类没有记录。您可能想查看此 SO 答案以获取更多详细信息:https://stackoverflow.com/questions/5574241/interesting-uses-of-sun-misc-unsafe

非官方文档:http://mishadoff.github.io/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/
绝对初学者指南 http://java-performance.info/string-packing-converting-characters-to-bytes/
http://javapapers.com/core-java/address-of-a-java-object/

附言我知道我必须在这里发布链接的一些内容,但是由于文章真的很详细,所以我跳过了那部分

关于java - 使用 Java 访问内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19418900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com