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

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...