如何禁止JAVA程序源代码被反编译
来源:优易学  2011-12-23 16:27:45   【优易学:中国教育考试门户网】   资料下载   IT书店

 

  请注意 ,一定要放在catch才有用,其他地方无用。

  方案二。

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

  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,然后无法进行下去。大家可以多测试变得反编译工具。建议推荐用第二个方法。

上一页  [1] [2] 

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训