Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing data stored in a memory location in java

I'm looking for a way to read data from a pre-written memory location. Is there a way to do this in java, on a computer that runs on windows?

like image 743
Echocage Avatar asked Jul 05 '26 18:07

Echocage


1 Answers

Java provides an "abstraction" of a computer, hence "Java virtual machine" (JVM). This JVM is (theoretically) the same regardless of the underlying hardware or operating system. So (AFAIK) no direct access to low-level memory is possible from program space.

My suggestion would be to write something in a lower-level language (C for instance makes mem access fairly easy), then use the Java Native Interface (JNI) to call it and get the data into your Java program. Google on "Java Native Interface" and/or "Calling C From Java" for tutorial on how to. Obviously this native component would be compiled differently for each platform you want to run it on, providing a separate executable binary "native" file. ANSI C used to be a good standard to code to, since compilers complying with this standard are available on all(??) platforms, if you want to go multi-platform.

Using a JNI call will break the "compile once, run anywhere"-feature of your Java, as it depends on a component that still needs to be recompiled for each platform you want to run it on. And, of course, in practice the native code will probably also differ from platform to platform, as memory organisation might differ between platforms.

like image 130
frIT Avatar answered Jul 07 '26 06:07

frIT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!