Load a process as a stream?

So, I saw some code in the transfer that com.sun.tools.javac.Main

I was referring to and I got curious if I can start the AS A THREAD java process inside my process? Other executables? I have downloaded other java programs from ClassLoaders and injected with Java agents, but now I am curious if it is possible to load EXE inside java?

I guess this is possible with memory read / write, but there should be a safer way. (If not, where can you find some spec?)


source to share

3 answers

Extensions Banthar's answer:
Each process on the system has its own address space:
Themes are so called light weighted processes that are linked to the parent process they started with:
Inside assembly code or C / C ++ where you can access directly hardware addresses:
you could break into the address space of another process, perhaps, though:
usually the system that is responsible for creating them will try to avoid such things.

AFAIK there is no direct access to a specific area of ​​memory not allocated: the
process is trying to access it. IPC (Inter-Process Communication) is a good starting point to learn more about how to connect processes

This way there is no access to other processes not started by your process .:

However, you can start other java processes (threads are also processes):
 or execute command lines such as "java -jar xx.jar" .

And of course, there is nothing stopping you from doing things like calling a method on an object that is declared pulsating, like static static void main on your classpath.



Can you compile the classes in your code if that's what you ask? See getClass method at https://github.com/tgkprog/jCompile/blob/master/JCompService/src/main/java/s2n/jComp/services/impl/DefaultClazzCompilerService.java

You can see other examples on the Internet. The Javac compiler is another tool written in Java for a long time. I am assuming the next Java version is compiled by javac written in the previous version. Sounds strange, but great if you think about the java compiler.

So you could call it API like above, or make a process and call it (so its JVM part is not part of your JVM). Not sure if you are calling the main method on a thread, I don't understand why they would stop you. But it wouldn't be a heavy process, but just an API call to the main mehtod if the class looks like this:

public static void main(String[] args) throws Exception {


Similar: No com.sun.tools.javac in JDK7 , how to set classpath for com.sun.tools.javac.Main.compile ()?



It's impossible at all. The executable files must be downloaded to a specific address. This address is already taken by the java executable. Usually one process can only execute one executable file.

You can call other Java programs. Just add jar to the classpath and call the method main()

. You've probably seen com.sun.tools.javac.Main


If you have your own shared library, you can load it into the java process with System.loadLibrary


If you want to run a non-shared, native executable, the only way is to create a new process.



All Articles