如何使用 Java 从地址获取值?
对于我用 Java 编写的混淆程序,我需要找到一种方法来获取特定地址处的值。例如,在我在十六进制编辑器中打开的程序中,地址 0000001F 处是十六进制值“00”。此外,是否可以写入特定的内存地址?例如写入 0000001F 并将其从“00”更改为“FF”
For an obfuscation program I am writing in Java, I need to find a way to get a value at a specific address. For example, in a program I opened in a hex editor, at the address 0000001F is the hex value "00". Furthermore, is it possible to write to a specific memory address? For example writing to 0000001F and changing it from "00" to for example, "FF"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答您的第一个问题,您可以将文件作为二进制流打开并从中读取您想要的任何内容。这不会对类加载器产生太大影响,但如果您有一个自定义类加载器来操作该文件并在运行时将其转换为有效并由 JVM 加载的类,那么理论上这当然是可能的。不过,我想知道重点是什么,因为类加载器本身不会以这种方式被混淆。
要回答你的第二个问题,不,你不能用 Java 直接写入内存地址。您可以通过 JNI 调用一个可以执行此操作的函数(在 JVM 内存分配之外)。
在我看来,您使用了错误的语言来完成您想做的事情。
To answer your first question, you can open a file as a binary stream and read whatever you want from it. That won't do much in the way of the classloader, but if you have a custom classloader that manipulates the file and converts it at runtime into a class that is valid and loaded by the JVM, that is certainly theoretically possible. I would wonder what the point is, though, as the classloader itself would not be obfuscated in this manner.
To answer your second question, no you cannot write directly to a memory address with Java. You could call a function via JNI which could do so (outside of the JVM memory allocation).
It sounds to me like you are using the wrong language for what you want to do.
您使用了错误的语言。 C 或 C++ 是更好的选择,因为您可以轻松调用操作系统库(在大多数系统上)并尝试访问特定位置的内存。
大多数兼容 POSIX 的操作系统都实现 mmap,它允许您将内存映射到当前进程地址空间中的特定位置。
You are using the wrong language. C or C++ would be better choices because you can easily call operating system libraries (on most systems) and attempt to access the memory at a particular location.
Most POSIX-compliant operating systems implement mmap which allows you to map memory at a particular location in the current processes address space.