0

Assuming a diskless situation, how can I (in Java) create a process from an in-memory unzipped exe (and respective support files)?

I've seen out to unzip to memory here and here but can't find a way to create a process from a byte[] or InputStream, ie without a (filesystem) command string.

The idea is to bundle a 3rd party component in a Java application/project without allowing it's standalone usage, thus bundling it in a password protected Zip. During my program's execution it would be unzipped to memory (exe + support files) and prepared for latter OutputStream writes, as in:

Process process = ?
OutputStream output = process.getOutputStream();
...
output.write("my commmand to 3rd party component");

Any hints?

Thanks in advance,

Community
  • 1
  • 1
  • There must be some sort of in-memory file system that you can write the executable to, no? – bmargulies May 16 '12 at 13:22
  • Are you asking how to execute an external program? If so, http://www.rgagnon.com/javadetails/java-0014.html – eboix May 16 '12 at 13:24

2 Answers2

0

I can see several possible approaches:

  1. Unzip into an in-memory filesystem.
  2. Write a custom class loader that would load the classes directly from the ZIP file.

Of the two, the first will probably require less work.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • 1
    I think approach #2 won't be possible as Peter is asking for executing "exe + support files" which hints into a non-Java executable on Windows. So this leaves only the Ramdisk-approach. – Kosi2801 May 16 '12 at 13:28
  • that's right, it's a non-java 3rd party component. I wasn't aware of ram filesystem, now checking Apache Commons VFS. Thanks! – Peter Fialho May 16 '12 at 14:02
0

Windows requires that the image of the process resides on the filesystem visible to the OS. This means that you need to have a "disk" (to be precise, a system-wide visible file system exposed by the kernel-mode driver) to which the EXE is unpacked.

We offer several products which can be used to create a virtual file system suitable for launching EXEs from it, but in all these products installation of the kernel-mode driver is required. This is just how Windows was designed to work.

So running the native EXE (in PE format) from just a stream unfortunately won't work. .NET assemblies can be loaded in/from memory, and Java classes can also be loaded from anywhere using Java runtime capabilities, but this is not so for native processes.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • Ok, thank you. But with a disk I would still need to use the contents of my password protected zip without exposing them on the filesystem (if I put them in a temp folder, someone might find it and use the 3rd party component as a standalone). Is there a "standard" procedure to do this (as it's done in most "professional" applications and games) ? – Peter Fialho May 16 '12 at 14:26
  • @PeterFialho With our products you expose your data via the virtual filesystem but you can restrict access to the filesystem to only system process, so that others can't get to it. As for your second question, I can't comment about generic applications and games, but I have yet to see a game that spawns a process without having anything on the disk – Eugene Mayevski 'Callback May 16 '12 at 14:54