手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

如何防止JAVA程序源代码被反编译

[日期:2009-12-22] 来源:JAVA社区  作者:JAVA编辑 [字体:大 中 小]

方案二。

如果以上方法还不够专业,我们再来一个。呵呵~

1,同样的,我们定义一个类,这个类叫做AntiCrack.。名字好像有点大。。。代码如下:


public class AntiCrack
{

private AntiCrack()
{
}

public static Throwable Fake(Throwable throwable, Throwable throwable1)
{
try
{
throwable.getClass().getMethod("initCause", new Class[] {
Java.lang.Throwable.class
}).invoke(throwable, new Object[] {
throwable1
});
}
catch(Exception exception) { }

        return throwable;
}
}

2,同样的,我们在catch里面调用该函数。例如如下。

try
{

//your code here

}
catch(IOException ioexception)


            {
IllegalArgumentException illegalargumentexception = new IllegalArgumentException(ioexception.toString());

                AntiCrack.fake(illegalargumentexception, ioexception);
throw illegalargumentexception;
}

或者也可以这样


public class AntiException extends Exception
{

public AntiException()
{
}

public AntiException(String s)
{
super(s);
}

    public AntiException(String s, Throwable throwable)
{
super(s);
AntiCrack.fake(this, throwable);
}
}

然后在你的程序里面

try
{

}

catch(IoException e)

{


throw new AntiException(ioexception.toString(), ioexception);


}

 

当采用以上方式后,任何类只要调用了该函数,生成的class反编译后出错,得不到结果。

Decafe、FrontEnd和YingJAD,反编译时都有exception,然后无法进行下去。大家可以多测试变得反编译工具。建议推荐用第二个方法。

linux
相关资讯       Java 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款