java - 使用 Java 访问内存

标签 java memory opcode

我在内存中加载了一个程序。现在我想直接访问内存并为该程序更改内存中的 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/

相关文章:

java - 显示斯坦福 NER 置信度分数

c++ - 编程语言函数在内存中位于哪里?

c - 我在 C++ 中使用 widestring 时程序崩溃

assembly - 汇编指令数据库?

assembly - 为什么在 x86 程序集中将 NOP 分配给 0x90?

java - 如何从另一个类获取调用者方法的注释

java - 可能会损失精度吗?

java - 访问 JSF 中的 protected 页面

google-chrome - Chrome 开发工具第一个内存堆快照异常大

assembly - LLVM 中的 getOpcode 是什么?