用Java访问内存 [英] Accessing memory with Java

查看:158
本文介绍了用Java访问内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在内存中加载了一个程序.现在,我想直接访问内存,并为该程序更改内存中的操作码和数据.为此,我需要编写一个Java程序.

I have a program loaded in the memory. Now I want to access the memory directly and change the OPCODE and DATA in the memory for that program. For this I need to write a Java program.

您能告诉我这是否可行吗?如果是,请让我知道如何编写这样的程序.

Can you please tell me if this is feasible? If yes, please let me know how to write such a program.

提前谢谢!

推荐答案

Java并非为此设计的.
Java的主要目的是让JVM为您管理内存.因此,您的程序被沙箱化了.

Java is not designed for this.
The main aim of Java is to let the JVM manage the memory for you. Thus, your programs are sandboxed.

但是,HotSpot JVM中似乎存在后门:

However, there seems to be a backdoor in HotSpot JVM:

Java最初被设计为安全的托管环境. 尽管如此,Java HotSpot VM包含一个后门",该后门提供了 操纵内存和线程的低级操作数 直接地.这个后门– sun.misc.Unsafe –被JDK广泛使用 本身在java.nio或java.util.concurrent之类的软件包中.它是 很难想象一个Java开发人员会在任何常规情况下使用此后门程序 开发,因为此API极其危险,不可移植且 易挥发的.然而,不安全提供了一种简单的方法来研究 HotSpot JVM内部原理和一些技巧.有时只是 有趣的是,有时它可以用于研究没有C ++代码的VM内部 调试,有时可以利用它进行概要分析和开发 工具.

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

The Unsafe class is, however, undocumented. You may want to have a look at this SO answer for more details: 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/

Unoffical Docs: http://mishadoff.github.io/blog/java-magic-part-4-sun-dot-misc-dot-unsafe/
Absolute Beginners' Guide http://java-performance.info/string-packing-converting-characters-to-bytes/
http://javapapers.com/core-java/address-of-a-java-object/

P.S.我知道我必须在此处发布链接的某些内容,但是由于文章确实非常详细,因此我跳过了该部分

这篇关于用Java访问内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆