views:

60

answers:

1

Say I have a couple of java runtime environments running on my system which are used by several applications. I would like to programmatically interact with these applications by reading their memory.

A typical approach would be to directly look into this application's memory, however for java applications this seems to be practically impossible because of the java runtime environment. Instead, one has to look into the memory of the java runtime environment, or debug it.

[ the above is what I think I have learned from several searches on the web, if anything is false, please correct me ]

Note: keep in mind that the application I want to monitor is not owned by me and thus I do not have the source code nor the ability to launch the application in "debug mode" or something.

Now, as this is a non-production project, I would prefer an easy way out: using an existing windows GUI application which can already monitor variables of a java runtime environment and it's applications to programmatically crawl these from this GUI application for usage in my own project. If any such program exists, I would really appreciate the help.

If the above is not possible, how would I (programmatically) retreive these variables otherwise?

+1  A: 

It's difficult to answer this precisely without knowing much more about the application involved, its structure etc. Note that objects move around in the JVM's memory, and so you can't monitor the actual application memory directly.

So the first question is, how do you know what you want to monitor without the source code ? e.g. which variables/objects etc.?

Given that you've worked this out, it strikes me that you have two options.

  1. decompile and instrument the application (perhaps statically, perhaps using AOP), and recompile it. This assumes that the application is not obfuscated, and you're not in breach of licensing etc.
  2. wrap the application in a thin layer that uses reflection to identify the variables you're interested in, and tracks the values of those variables as the process executes. I suspect you'll still have to decompile to identify these variables.

You can monitor these values remotely by creating an MBean and exposing via JMX, and monitoring via JConsole. That's pretty trivial compared to the initial step of finding those variables you're interested in.

Brian Agnew
I'm afraid decompiling is not really an option. There aren't even direct java files in the application folder. The application has been compiled to a windows executable and is highly obfuscated. I was hoping to find these variables using an existing GUI application, using simple comparison commands and searches when I change certain things within the application (and then look which variables have changed in a logical way to find the corresponding ones). Doesn't something like this exist?
Tom
Update: tried using JConsole. It finds the JRE of the application, but when connecting gives an error that connecting has failed without any further information, it can however connect to other JREs.
Tom