Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

java - Load a Byte Array into a Memory Class Loader

I am wondering how I can load a byte array into a memory URLClassLoader? The byte array is the decrypted bytes of a jar file (as seen below)!

Most of the memory class loaders are using ClassLoader and not URLClassLoader! I need it to be using URLClassLoader.

    byte[] fileB = Util.crypt.getFileBytes(inputFile);
    byte[] dec;
    dec = Util.crypt.decrypt(fileB, "16LENGTHLONGKEYX".getBytes());
    //Load bytes into memory and load a class here?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have you looked at the NetworkClassLoader example in the ClassLoader javadocs:

http://docs.oracle.com/javase/6/docs/api/index.html?java/lang/ClassLoader.html

Using this as a base, you just need to implement the loadClassData method, which will pull the desired resource from decrypted jar bytes. You can wrap the decrypted bytes with a JarInputStream(new ByteArrayInputStream(dec)), then iterate through the jar entries until you find the resource / class you're interested in and then return the jar entry's byte array


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...