服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|JavaScript|

服务器之家 - 编程语言 - JAVA教程 - java防反编译最简单的技巧分享

java防反编译最简单的技巧分享

2020-12-24 12:04jijs JAVA教程

这篇文章主要给大家分享了关于java防反编译最简单的技巧,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧。

前言

本文主要跟大家介绍了关于java防反编译的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。

示例代码:

源码使用try-catch代码包装下,如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class CompileForbid {
 
  public static void main(String[] args) {
    try {
      System.out.println("-------");
      //防止反编译的处理
      if (654789 == new Random().nextInt()) {
        throw new Exception("fewt43");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      try {
        //防止反编译的处理
        if (654789 == new Random().nextInt()) {
          throw new Exception("fewt43");
        }
      } catch (Exception ex) {
        System.out.print(ex);
      }
    }
  }
}

使用 jd 反编译工具翻遍后的效果,别的反编译可能会反编译出来,效果不是很好,但是简单实用

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
public class CompileForbid
{
 // ERROR //
 public static void main(java.lang.String[] args)
 {
  // Byte code:
  //  0: getstatic 16  java/lang/System:out  Ljava/io/PrintStream;
  //  3: ldc 22
  //  5: invokevirtual 24  java/io/PrintStream:println (Ljava/lang/String;)V
  //  8: ldc 30
  //  10: new 31 java/util/Random
  //  13: dup
  //  14: invokespecial 33  java/util/Random:<init> ()V
  //  17: invokevirtual 34  java/util/Random:nextInt  ()I
  //  20: if_icmpne +90 -> 110
  //  23: new 38 java/lang/Exception
  //  26: dup
  //  27: ldc 40
  //  29: invokespecial 42  java/lang/Exception:<init> (Ljava/lang/String;)V
  //  32: athrow
  //  33: astore_1
  //  34: aload_1
  //  35: invokevirtual 44  java/lang/Exception:printStackTrace ()V
  //  38: ldc 30
  //  40: new 31 java/util/Random
  //  43: dup
  //  44: invokespecial 33  java/util/Random:<init> ()V
  //  47: invokevirtual 34  java/util/Random:nextInt  ()I
  //  50: if_icmpne +93 -> 143
  //  53: new 38 java/lang/Exception
  //  56: dup
  //  57: ldc 40
  //  59: invokespecial 42  java/lang/Exception:<init> (Ljava/lang/String;)V
  //  62: athrow
  //  63: astore_3
  //  64: getstatic 16  java/lang/System:out  Ljava/io/PrintStream;
  //  67: aload_3
  //  68: invokevirtual 47  java/io/PrintStream:print  (Ljava/lang/Object;)V
  //  71: goto +72 -> 143
  //  74: astore_2
  //  75: ldc 30
  //  77: new 31 java/util/Random
  //  80: dup
  //  81: invokespecial 33  java/util/Random:<init> ()V
  //  84: invokevirtual 34  java/util/Random:nextInt  ()I
  //  87: if_icmpne +21 -> 108
  //  90: new 38 java/lang/Exception
  //  93: dup
  //  94: ldc 40
  //  96: invokespecial 42  java/lang/Exception:<init> (Ljava/lang/String;)V
  //  99: athrow
  //  100: astore_3
  //  101: getstatic 16 java/lang/System:out  Ljava/io/PrintStream;
  //  104: aload_3
  //  105: invokevirtual 47 java/io/PrintStream:print  (Ljava/lang/Object;)V
  //  108: aload_2
  //  109: athrow
  //  110: ldc 30
  //  112: new 31  java/util/Random
  //  115: dup
  //  116: invokespecial 33 java/util/Random:<init> ()V
  //  119: invokevirtual 34 java/util/Random:nextInt  ()I
  //  122: if_icmpne +21 -> 143
  //  125: new 38  java/lang/Exception
  //  128: dup
  //  129: ldc 40
  //  131: invokespecial 42 java/lang/Exception:<init> (Ljava/lang/String;)V
  //  134: athrow
  //  135: astore_3
  //  136: getstatic 16 java/lang/System:out  Ljava/io/PrintStream;
  //  139: aload_3
  //  140: invokevirtual 47 java/io/PrintStream:print  (Ljava/lang/Object;)V
  //  143: return
  //
  // Exception table:
  //  from  to target type
  //  0 33 33 java/lang/Exception
  //  38 63 63 java/lang/Exception
  //  0 38 74 finally
  //  75 100 100 java/lang/Exception
  //  110  135 135 java/lang/Exception
 }
}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对服务器之家的支持。

原文链接:http://blog.csdn.net/jijianshuai/article/details/75219946

延伸 · 阅读

精彩推荐