Search code examples
javabyte-buddyjavaagents

Can a java agent attached from a remote host be used to pass data?


I've seen examples like this where an agent can be attach to a running java process using Byte Buddy.

 public static void premain(String args, Instrumentation instrumentation) {

        File file ;
        try {
                file = (new File("BBAgent.jar"));
                ByteBuddyAgent.attach(file,"21345");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }

// Code to access objects in the original running process here.

    }
}

My question is, would it possible to access the the objects in the original process by adding additional code below the attachment? Or does any code that access the data in the original process have to already be packaged in the jar file attachment?


Solution

  • No, objects cannot be transfered from one Java process to another without serializing them. You would for example needs to open a socket to transfer bytes from one process to the other where you certainly could send serialized objects.