怎样加载一个加密过的class

cooc123 2008-10-25 01:30:11


假如这个CLASS 被我用des加密了,当然我能解密,但解密后的数据怎样加载呢?
...全文
82 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
cooc123 2008-10-25
  • 打赏
  • 举报
回复
呵,以后不怕源代码被反编译了,,
cooc123 2008-10-25
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 huoyin 的回复:]
当调用loadClass时,loadClass方法内部会调用findClass
[/Quote]

喔,原来这样丫
cooc123 2008-10-25
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 huoyin 的回复:]
你怎么不查查JDK的文档呢?我给你贴出来算了:
loadClass
public Class loadClass(String name)
                throws ClassNotFoundException
Loads the class with the specified name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadC…
[/Quote]


我是说 findClass 不是 loadClass
huoyin 2008-10-25
  • 打赏
  • 举报
回复
你怎么不查查JDK的文档呢?我给你贴出来算了:
loadClass
public Class loadClass(String name)
throws ClassNotFoundException
Loads the class with the specified name. This method searches for classes in the same manner as the loadClass(String, boolean) method. It is invoked by the Java virtual machine to resolve class references. Invoking this method is equivalent to invoking loadClass(name, false).


Parameters:
name - The name of the class
Returns:
The resulting Class object
Throws:
ClassNotFoundException - If the class was not found

--------------------------------------------------------------------------------

loadClass
protected Class loadClass(String name,
boolean resolve)
throws ClassNotFoundException
Loads the class with the specified name. The default implementation of this method searches for classes in the following order:

Invoke findLoadedClass(String) to check if the class has already been loaded.

Invoke the loadClass method on the parent class loader. If the parent is null the class loader built-in to the virtual machine is used, instead.

Invoke the findClass(String) method to find the class.

If the class was found using the above steps, and the resolve flag is true, this method will then invoke the resolveClass(Class) method on the resulting Class object.

Subclasses of ClassLoader are encouraged to override findClass(String), rather than this method.


Parameters:
name - The name of the class
resolve - If true then resolve the class
Returns:
The resulting Class object
Throws:
ClassNotFoundException - If the class could not be found
cooc123 2008-10-25
  • 打赏
  • 举报
回复
说实话

public Class findClass(String name)
{}

这个方法在哪调用的还是没看到
huoyin 2008-10-25
  • 打赏
  • 举报
回复
当调用loadClass时,loadClass方法内部会调用findClass
cooc123 2008-10-25
  • 打赏
  • 举报
回复
呵,看明白了

String name 原来是类名丫

URL url=new URL("jar:file:/"+drive+"!/"+name+".class");
这样写的还是第一次看到

中间的 !号啥意思

是固定写法?
huoyin 2008-10-25
  • 打赏
  • 举报
回复
怎么调用的方法不是在main方法中写了:
public static void main(String[] args) throws Exception

{

FileClassLoader loader = new FileClassLoader("D:/TestDir/t.jar");

Class objClass = loader.loadClass("com.TestClassLoader");

Class objClass2 = loader.loadClass("com.TestClassLoaderUse");

Object obj = objClass.newInstance();

//通过reflect执行函数..doit(String a);

Method method=objClass.getMethod("doit",new Class[]{String.class});

System.out.println("method doit() return:"+method.invoke(obj,new Object[]{"J"}));

System.out.println(objClass.getName());

System.out.println(objClass.getClassLoader());

}

name就是你的class名称,如com.TestClassLoaderUse,com.x...
cooc123 2008-10-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 huoyin 的回复:]
引用 2 楼 cooc123 的回复:

那我解密后,要将解密的数据写入到一个class文件里吗


不需要,你在自定义的classloader中将class的字节数组修改了即可,这个有一个自定义classloader的例子:
http://blog.chinaunix.net/u/32945/showart_255326.html
[/Quote]

public Class findClass(String name)throws ClassNotFoundException
{
Class resultClass=null;
String pathName=name.replace('.','/');
byte[] data = loadClassData(pathName);
resultClass=defineClass(name, data, 0, data.length);
return resultClass;
}

1:这个方法是怎样调用的
2:defineClass(String name, byte[] b, int off, int len)

String name 这个参数是什么,看不懂
huoyin 2008-10-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 cooc123 的回复:]
那我解密后,要将解密的数据写入到一个class文件里吗
[/Quote]

不需要,你在自定义的classloader中将class的字节数组修改了即可,这个有一个自定义classloader的例子:
http://blog.chinaunix.net/u/32945/showart_255326.html
showde123 2008-10-25
  • 打赏
  • 举报
回复
帮顶
java__king 2008-10-25
  • 打赏
  • 举报
回复
CLASS 用des加密??
貌似很有意思,怎么实现的,楼主说下啊.
cooc123 2008-10-25
  • 打赏
  • 举报
回复
那我解密后,要将解密的数据写入到一个class文件里吗
nine_suns99 2008-10-25
  • 打赏
  • 举报
回复
自定义一个DecryptClassLoader,在内存中解密之后加载该class
楼主去看看关于java类加载机制方面的资料吧。

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧