1

I have java program (with a gui) which is running on a host. On runtime a user can add some data records. The program just works with them.

Later the system maybe shuts down or the program is just closed by SIGTERM.

Unfortunately the porgram only seems to store the data records if it is closed manually by the user with the "X".

Now i have the problem that i maybe lose some data if the program is closed by SIGTERM. Unfortunately there is no contact email address to ask the author for the change.

I tried to decompile it with "jd gui" which seemed to work more or less. I thought then i just could add the signal handler and invoke the "window close" method.

But "jd gui" created code like this:

/* 110:269 */       if ((??? = Thread.currentThread().getContextClassLoader()) != null) {
/* 111:270 */         return ???;

And i also get many other errors if i try to compile the source.

I think this is because the jar file is obfuscated by some tool. Unfortunately the decompiled code doesn't work and i am not able to recompile the file with the JFrame.

Long story short: Is it possible to write a "wrapper program" which just handles SIGTERM and then invokes the JFrame "close method" (or how it is called) of the main frame (which is the only JFrame)?

I just do not know how to invoke such a method of an external running java program.

Thank you very much.

Best regards Kevin

Kevin Meier
  • 2,339
  • 3
  • 25
  • 52

2 Answers2

1

Try to deobfuscate the application. Have a look here (2009) - Tool to deobfuscate Java codes.

Maybe it is possible to resolve the source so that you are able to diggin deeper into the source and compile it.

Otherwise it is quite complicated to hook into a Swing based ui event queue from outside a wrapper application.

Maybe you can decompile the main class and replace its main method with your own and add a shutdownhook see: Useful example of a shutdown hook in Java? which calls the onClose (deobfuscated) method.

Any way, an interesting and challening question!

Community
  • 1
  • 1
Diversity
  • 1,890
  • 13
  • 20
  • Thanks for the tool to deobfuscate java code. It really helped me to understand how the code works (and how to write the hook). Thank you:) – Kevin Meier Aug 17 '14 at 00:07
1

Create your own class with a main method which installs a shutdown hook to save before closing. then invoke the original programs main method. add this to the jar and use this class to launch the program.

jtahlborn
  • 52,909
  • 5
  • 76
  • 118