java anti decompilation the simplest tips to share

  • 2020-10-07 18:39:13
  • OfStack

preface

This article mainly introduces the java anti-decompilation related content, sharing for your reference and learning, the following words do not say much, to see a detailed introduction.

Sample code:

Source code using try-catch code packaging, as follows:


public class CompileForbid {

  public static void main(String[] args) {
    try {
      System.out.println("-------");
      // Prevent decompilation processing 
      if (654789 == new Random().nextInt()) {
        throw new Exception("fewt43");
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      try {
        // Prevent decompilation processing 
        if (654789 == new Random().nextInt()) {
          throw new Exception("fewt43");
        }
      } catch (Exception ex) {
        System.out.print(ex);
      }
    }
  }
}

jd decompiler tool after the effect, other decompilers may be decompiled out, the effect is not very good, but simple and practical


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
 }
}

conclusion


Related articles: