Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Byte Code Error? #37

Closed
addisoncrump opened this issue Jun 6, 2015 · 3 comments
Closed

Byte Code Error? #37

addisoncrump opened this issue Jun 6, 2015 · 3 comments

Comments

@addisoncrump
Copy link

I had lost some source code when I had a computer crash a few days ago, but I still had the compiled code, so I used this tool. It failed to decompile two of my files, the commonalities being that they both held try/catch statements, and they both attempted to extract data from a jar file for uses elsewhere (AppSupportExporter copies the data, SoundHandler plays sound clips). I also looked at the byte code and it seemed that the decompiler error occurred at the try/catch statement. Please see what caused this fault, my decompiler error results are below. It might be used for possible updates?

Class file extracts information from a jar file and exports it to the user's home directory/Library/Application Support (built for Mac OSX):

package com.crump.karelearning.start;

public class AppSupportExporter
{
  /* Error */
  public AppSupportExporter(String resourceName, String destination)
  {
    // Byte code:
    //   0: aload_0
    //   1: invokespecial 8 java/lang/Object:<init> ()V
    //   4: aconst_null
    //   5: astore_3
    //   6: aconst_null
    //   7: astore 4
    //   9: ldc 1
    //   11: aload_1
    //   12: invokevirtual 11   java/lang/Class:getResourceAsStream (Ljava/lang/String;)Ljava/io/InputStream;
    //   15: astore_3
    //   16: aload_3
    //   17: ifnonnull +32 -> 49
    //   20: new 17 java/lang/Exception
    //   23: dup
    //   24: new 19 java/lang/StringBuilder
    //   27: dup
    //   28: ldc 21
    //   30: invokespecial 23   java/lang/StringBuilder:<init>  (Ljava/lang/String;)V
    //   33: aload_1
    //   34: invokevirtual 26   java/lang/StringBuilder:append  (Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   37: ldc 30
    //   39: invokevirtual 26   java/lang/StringBuilder:append  (Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   42: invokevirtual 32   java/lang/StringBuilder:toString    ()Ljava/lang/String;
    //   45: invokespecial 36   java/lang/Exception:<init>  (Ljava/lang/String;)V
    //   48: athrow
    //   49: sipush 4096
    //   52: newarray <illegal type>
    //   54: astore 6
    //   56: aload_2
    //   57: ldc 37
    //   59: invokevirtual 39   java/lang/String:equals (Ljava/lang/Object;)Z
    //   62: ifeq +38 -> 100
    //   65: new 45 java/io/FileOutputStream
    //   68: dup
    //   69: new 19 java/lang/StringBuilder
    //   72: dup
    //   73: ldc 47
    //   75: invokestatic 49    java/lang/System:getProperty    (Ljava/lang/String;)Ljava/lang/String;
    //   78: invokestatic 55    java/lang/String:valueOf    (Ljava/lang/Object;)Ljava/lang/String;
    //   81: invokespecial 23   java/lang/StringBuilder:<init>  (Ljava/lang/String;)V
    //   84: ldc 59
    //   86: invokevirtual 26   java/lang/StringBuilder:append  (Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   89: invokevirtual 32   java/lang/StringBuilder:toString    ()Ljava/lang/String;
    //   92: invokespecial 61   java/io/FileOutputStream:<init> (Ljava/lang/String;)V
    //   95: astore 4
    //   97: goto +26 -> 123
    //   100: new 45    java/io/FileOutputStream
    //   103: dup
    //   104: aload_2
    //   105: invokespecial 61  java/io/FileOutputStream:<init> (Ljava/lang/String;)V
    //   108: astore 4
    //   110: goto +13 -> 123
    //   113: aload 4
    //   115: aload 6
    //   117: iconst_0
    //   118: iload 5
    //   120: invokevirtual 62  java/io/OutputStream:write  ([BII)V
    //   123: aload_3
    //   124: aload 6
    //   126: invokevirtual 68  java/io/InputStream:read    ([B)I
    //   129: dup
    //   130: istore 5
    //   132: ifgt -19 -> 113
    //   135: goto +56 -> 191
    //   138: astore 5
    //   140: aload 5
    //   142: invokevirtual 74  java/lang/Exception:printStackTrace ()V
    //   145: aload_3
    //   146: invokevirtual 77  java/io/InputStream:close   ()V
    //   149: aload 4
    //   151: invokevirtual 80  java/io/OutputStream:close  ()V
    //   154: goto +56 -> 210
    //   157: astore 8
    //   159: aload 8
    //   161: invokevirtual 81  java/io/IOException:printStackTrace ()V
    //   164: goto +46 -> 210
    //   167: astore 7
    //   169: aload_3
    //   170: invokevirtual 77  java/io/InputStream:close   ()V
    //   173: aload 4
    //   175: invokevirtual 80  java/io/OutputStream:close  ()V
    //   178: goto +10 -> 188
    //   181: astore 8
    //   183: aload 8
    //   185: invokevirtual 81  java/io/IOException:printStackTrace ()V
    //   188: aload 7
    //   190: athrow
    //   191: aload_3
    //   192: invokevirtual 77  java/io/InputStream:close   ()V
    //   195: aload 4
    //   197: invokevirtual 80  java/io/OutputStream:close  ()V
    //   200: goto +10 -> 210
    //   203: astore 8
    //   205: aload 8
    //   207: invokevirtual 81  java/io/IOException:printStackTrace ()V
    //   210: return
    // Line number table:
    //   Java source line #13   -> byte code offset #0
    //   Java source line #14   -> byte code offset #4
    //   Java source line #15   -> byte code offset #6
    //   Java source line #17   -> byte code offset #9
    //   Java source line #18   -> byte code offset #16
    //   Java source line #19   -> byte code offset #20
    //   Java source line #23   -> byte code offset #49
    //   Java source line #24   -> byte code offset #56
    //   Java source line #25   -> byte code offset #65
    //   Java source line #27   -> byte code offset #100
    //   Java source line #28   -> byte code offset #110
    //   Java source line #29   -> byte code offset #113
    //   Java source line #28   -> byte code offset #123
    //   Java source line #31   -> byte code offset #135
    //   Java source line #32   -> byte code offset #140
    //   Java source line #35   -> byte code offset #145
    //   Java source line #36   -> byte code offset #149
    //   Java source line #37   -> byte code offset #154
    //   Java source line #38   -> byte code offset #159
    //   Java source line #33   -> byte code offset #167
    //   Java source line #35   -> byte code offset #169
    //   Java source line #36   -> byte code offset #173
    //   Java source line #37   -> byte code offset #178
    //   Java source line #38   -> byte code offset #183
    //   Java source line #40   -> byte code offset #188
    //   Java source line #35   -> byte code offset #191
    //   Java source line #36   -> byte code offset #195
    //   Java source line #37   -> byte code offset #200
    //   Java source line #38   -> byte code offset #205
    //   Java source line #41   -> byte code offset #210
    // Local variable table:
    //   start  length  slot    name    signature
    //   0  211 0   this    AppSupportExporter
    //   0  211 1   resourceName    String
    //   0  211 2   destination String
    //   5  187 3   stream  java.io.InputStream
    //   7  189 4   resStreamOut    java.io.OutputStream
    //   113    6   5   readBytes   int
    //   130    3   5   readBytes   int
    //   138    3   5   ex  Exception
    //   54 71  6   buffer  byte[]
    //   167    22  7   localObject Object
    //   157    3   8   e   java.io.IOException
    //   181    3   8   e   java.io.IOException
    //   203    3   8   e   java.io.IOException
    // Exception table:
    //   from   to  target  type
    //   9  135 138 java/lang/Exception
    //   145    154 157 java/io/IOException
    //   9  145 167 finally
    //   169    178 181 java/io/IOException
    //   191    200 203 java/io/IOException
  }
}

Extracts a sound file from the jar file that the running main class is located within and plays it or loads it in for future use (because the first attempt to play it fails if not loaded in):

package com.crump.karelearning;

import java.net.URL;

public class SoundHandler
{
  public SoundHandler(String filename)
  {
    new Thread(new Runnable()
    {
      private final int EXTERNAL_BUFFER_SIZE = 524288;
      private URL soundFile;

      /* Error */
      public void run()
      {
        // Byte code:
        //   0: aload_0
        //   1: getfield 50 com/crump/karelearning/SoundHandler$1:soundFile Ljava/net/URL;
        //   4: invokevirtual 57    java/net/URL:openConnection ()Ljava/net/URLConnection;
        //   7: invokevirtual 63    java/net/URLConnection:connect  ()V
        //   10: aload_0
        //   11: getfield 50    com/crump/karelearning/SoundHandler$1:soundFile Ljava/net/URL;
        //   14: invokevirtual 68   java/net/URL:openStream ()Ljava/io/InputStream;
        //   17: invokevirtual 72   java/io/InputStream:close   ()V
        //   20: goto +5 -> 25
        //   23: astore_1
        //   24: return
        //   25: aconst_null
        //   26: astore_1
        //   27: aload_0
        //   28: getfield 50    com/crump/karelearning/SoundHandler$1:soundFile Ljava/net/URL;
        //   31: invokestatic 77    javax/sound/sampled/AudioSystem:getAudioInputStream (Ljava/net/URL;)Ljavax/sound/sampled/AudioInputStream;
        //   34: astore_1
        //   35: goto +7 -> 42
        //   38: astore_2
        //   39: return
        //   40: astore_2
        //   41: return
        //   42: aload_1
        //   43: invokevirtual 83   javax/sound/sampled/AudioInputStream:getFormat  ()Ljavax/sound/sampled/AudioFormat;
        //   46: astore_2
        //   47: aconst_null
        //   48: astore_3
        //   49: new 89 javax/sound/sampled/DataLine$Info
        //   52: dup
        //   53: ldc 91
        //   55: aload_2
        //   56: invokespecial 93   javax/sound/sampled/DataLine$Info:<init>    (Ljava/lang/Class;Ljavax/sound/sampled/AudioFormat;)V
        //   59: astore 4
        //   61: aload 4
        //   63: invokestatic 96    javax/sound/sampled/AudioSystem:getLine (Ljavax/sound/sampled/Line$Info;)Ljavax/sound/sampled/Line;
        //   66: checkcast 91   javax/sound/sampled/SourceDataLine
        //   69: astore_3
        //   70: aload_3
        //   71: aload_2
        //   72: invokeinterface 100 2 0
        //   77: goto +9 -> 86
        //   80: astore 5
        //   82: return
        //   83: astore 5
        //   85: return
        //   86: aload_3
        //   87: invokeinterface 104 1 0
        //   92: iconst_0
        //   93: istore 5
        //   95: ldc 10
        //   97: newarray <illegal type>
        //   99: astore 6
        //   101: goto +32 -> 133
        //   104: aload_1
        //   105: aload 6
        //   107: iconst_0
        //   108: aload 6
        //   110: arraylength
        //   111: invokevirtual 107 javax/sound/sampled/AudioInputStream:read   ([BII)I
        //   114: istore 5
        //   116: iload 5
        //   118: iflt +15 -> 133
        //   121: aload_3
        //   122: aload 6
        //   124: iconst_0
        //   125: iload 5
        //   127: invokeinterface 111 4 0
        //   132: pop
        //   133: iload 5
        //   135: iconst_m1
        //   136: if_icmpne -32 -> 104
        //   139: goto +35 -> 174
        //   142: astore 7
        //   144: aload_3
        //   145: invokeinterface 114 1 0
        //   150: aload_3
        //   151: invokeinterface 117 1 0
        //   156: return
        //   157: astore 8
        //   159: aload_3
        //   160: invokeinterface 114 1 0
        //   165: aload_3
        //   166: invokeinterface 117 1 0
        //   171: aload 8
        //   173: athrow
        //   174: aload_3
        //   175: invokeinterface 114 1 0
        //   180: aload_3
        //   181: invokeinterface 117 1 0
        //   186: return
        // Line number table:
        //   Java source line #29   -> byte code offset #0
        //   Java source line #30   -> byte code offset #10
        //   Java source line #31   -> byte code offset #20
        //   Java source line #32   -> byte code offset #24
        //   Java source line #34   -> byte code offset #25
        //   Java source line #37   -> byte code offset #27
        //   Java source line #36   -> byte code offset #34
        //   Java source line #38   -> byte code offset #35
        //   Java source line #39   -> byte code offset #39
        //   Java source line #40   -> byte code offset #40
        //   Java source line #41   -> byte code offset #41
        //   Java source line #43   -> byte code offset #42
        //   Java source line #44   -> byte code offset #47
        //   Java source line #45   -> byte code offset #49
        //   Java source line #46   -> byte code offset #55
        //   Java source line #45   -> byte code offset #56
        //   Java source line #48   -> byte code offset #61
        //   Java source line #49   -> byte code offset #70
        //   Java source line #50   -> byte code offset #77
        //   Java source line #51   -> byte code offset #82
        //   Java source line #52   -> byte code offset #83
        //   Java source line #53   -> byte code offset #85
        //   Java source line #55   -> byte code offset #86
        //   Java source line #56   -> byte code offset #92
        //   Java source line #57   -> byte code offset #95
        //   Java source line #59   -> byte code offset #101
        //   Java source line #60   -> byte code offset #104
        //   Java source line #61   -> byte code offset #108
        //   Java source line #60   -> byte code offset #111
        //   Java source line #62   -> byte code offset #116
        //   Java source line #63   -> byte code offset #121
        //   Java source line #59   -> byte code offset #133
        //   Java source line #66   -> byte code offset #139
        //   Java source line #69   -> byte code offset #144
        //   Java source line #70   -> byte code offset #150
        //   Java source line #67   -> byte code offset #156
        //   Java source line #68   -> byte code offset #157
        //   Java source line #69   -> byte code offset #159
        //   Java source line #70   -> byte code offset #165
        //   Java source line #71   -> byte code offset #171
        //   Java source line #69   -> byte code offset #174
        //   Java source line #70   -> byte code offset #180
        //   Java source line #72   -> byte code offset #186
        // Local variable table:
        //   start  length  slot    name    signature
        //   0  187 0   this    1
        //   23 2   1   e   Exception
        //   26 79  1   audioInputStream    javax.sound.sampled.AudioInputStream
        //   38 2   2   e   javax.sound.sampled.UnsupportedAudioFileException
        //   40 2   2   e   java.io.IOException
        //   46 26  2   format  javax.sound.sampled.AudioFormat
        //   48 133 3   auline  javax.sound.sampled.SourceDataLine
        //   59 3   4   info    javax.sound.sampled.DataLine.Info
        //   80 3   5   e   javax.sound.sampled.LineUnavailableException
        //   83 3   5   e   Exception
        //   93 41  5   nBytesRead  int
        //   99 24  6   abData  byte[]
        //   142    3   7   e   java.io.IOException
        //   157    15  8   localObject Object
        // Exception table:
        //   from   to  target  type
        //   0  20  23  java/lang/Exception
        //   27 35  38  javax/sound/sampled/UnsupportedAudioFileException
        //   27 35  40  java/io/IOException
        //   61 77  80  javax/sound/sampled/LineUnavailableException
        //   61 77  83  java/lang/Exception
        //   101    139 142 java/io/IOException
        //   101    144 157 finally
      }
    })

      .start();
  }

  protected SoundHandler(String filename, boolean x)
  {
    new Thread(new Runnable()
    {
      private final int EXTERNAL_BUFFER_SIZE = 524288;
      private URL soundFile = KarelKeyListener.class
        .getResource("/resources/bzzt.wav");

      /* Error */
      public void run()
      {
        // Byte code:
        //   0: aload_0
        //   1: getfield 35 com/crump/karelearning/SoundHandler$2:soundFile Ljava/net/URL;
        //   4: invokevirtual 42    java/net/URL:openConnection ()Ljava/net/URLConnection;
        //   7: invokevirtual 48    java/net/URLConnection:connect  ()V
        //   10: aload_0
        //   11: getfield 35    com/crump/karelearning/SoundHandler$2:soundFile Ljava/net/URL;
        //   14: invokevirtual 53   java/net/URL:openStream ()Ljava/io/InputStream;
        //   17: invokevirtual 57   java/io/InputStream:close   ()V
        //   20: goto +5 -> 25
        //   23: astore_1
        //   24: return
        //   25: aconst_null
        //   26: astore_1
        //   27: aload_0
        //   28: getfield 35    com/crump/karelearning/SoundHandler$2:soundFile Ljava/net/URL;
        //   31: invokestatic 62    javax/sound/sampled/AudioSystem:getAudioInputStream (Ljava/net/URL;)Ljavax/sound/sampled/AudioInputStream;
        //   34: astore_1
        //   35: goto +7 -> 42
        //   38: astore_2
        //   39: return
        //   40: astore_2
        //   41: return
        //   42: aload_1
        //   43: invokevirtual 68   javax/sound/sampled/AudioInputStream:getFormat  ()Ljavax/sound/sampled/AudioFormat;
        //   46: astore_2
        //   47: aconst_null
        //   48: astore_3
        //   49: new 74 javax/sound/sampled/DataLine$Info
        //   52: dup
        //   53: ldc 76
        //   55: aload_2
        //   56: invokespecial 78   javax/sound/sampled/DataLine$Info:<init>    (Ljava/lang/Class;Ljavax/sound/sampled/AudioFormat;)V
        //   59: astore 4
        //   61: aload 4
        //   63: invokestatic 81    javax/sound/sampled/AudioSystem:getLine (Ljavax/sound/sampled/Line$Info;)Ljavax/sound/sampled/Line;
        //   66: checkcast 76   javax/sound/sampled/SourceDataLine
        //   69: astore_3
        //   70: aload_3
        //   71: aload_2
        //   72: invokeinterface 85 2 0
        //   77: goto +9 -> 86
        //   80: astore 5
        //   82: return
        //   83: astore 5
        //   85: return
        //   86: iconst_0
        //   87: istore 5
        //   89: ldc 10
        //   91: newarray <illegal type>
        //   93: astore 6
        //   95: goto +32 -> 127
        //   98: aload_1
        //   99: aload 6
        //   101: iconst_0
        //   102: aload 6
        //   104: arraylength
        //   105: invokevirtual 89  javax/sound/sampled/AudioInputStream:read   ([BII)I
        //   108: istore 5
        //   110: iload 5
        //   112: iflt +15 -> 127
        //   115: aload_3
        //   116: aload 6
        //   118: iconst_0
        //   119: iload 5
        //   121: invokeinterface 93 4 0
        //   126: pop
        //   127: iload 5
        //   129: iconst_m1
        //   130: if_icmpne -32 -> 98
        //   133: goto +35 -> 168
        //   136: astore 7
        //   138: aload_3
        //   139: invokeinterface 96 1 0
        //   144: aload_3
        //   145: invokeinterface 99 1 0
        //   150: return
        //   151: astore 8
        //   153: aload_3
        //   154: invokeinterface 96 1 0
        //   159: aload_3
        //   160: invokeinterface 99 1 0
        //   165: aload 8
        //   167: athrow
        //   168: aload_3
        //   169: invokeinterface 96 1 0
        //   174: aload_3
        //   175: invokeinterface 99 1 0
        //   180: return
        // Line number table:
        //   Java source line #95   -> byte code offset #0
        //   Java source line #96   -> byte code offset #10
        //   Java source line #97   -> byte code offset #20
        //   Java source line #98   -> byte code offset #24
        //   Java source line #100  -> byte code offset #25
        //   Java source line #103  -> byte code offset #27
        //   Java source line #102  -> byte code offset #34
        //   Java source line #104  -> byte code offset #35
        //   Java source line #105  -> byte code offset #39
        //   Java source line #106  -> byte code offset #40
        //   Java source line #107  -> byte code offset #41
        //   Java source line #109  -> byte code offset #42
        //   Java source line #110  -> byte code offset #47
        //   Java source line #111  -> byte code offset #49
        //   Java source line #112  -> byte code offset #55
        //   Java source line #111  -> byte code offset #56
        //   Java source line #114  -> byte code offset #61
        //   Java source line #115  -> byte code offset #70
        //   Java source line #116  -> byte code offset #77
        //   Java source line #117  -> byte code offset #82
        //   Java source line #118  -> byte code offset #83
        //   Java source line #119  -> byte code offset #85
        //   Java source line #121  -> byte code offset #86
        //   Java source line #122  -> byte code offset #89
        //   Java source line #124  -> byte code offset #95
        //   Java source line #125  -> byte code offset #98
        //   Java source line #126  -> byte code offset #102
        //   Java source line #125  -> byte code offset #105
        //   Java source line #127  -> byte code offset #110
        //   Java source line #128  -> byte code offset #115
        //   Java source line #124  -> byte code offset #127
        //   Java source line #131  -> byte code offset #133
        //   Java source line #134  -> byte code offset #138
        //   Java source line #135  -> byte code offset #144
        //   Java source line #132  -> byte code offset #150
        //   Java source line #133  -> byte code offset #151
        //   Java source line #134  -> byte code offset #153
        //   Java source line #135  -> byte code offset #159
        //   Java source line #136  -> byte code offset #165
        //   Java source line #134  -> byte code offset #168
        //   Java source line #135  -> byte code offset #174
        //   Java source line #137  -> byte code offset #180
        // Local variable table:
        //   start  length  slot    name    signature
        //   0  181 0   this    2
        //   23 2   1   e   Exception
        //   26 73  1   audioInputStream    javax.sound.sampled.AudioInputStream
        //   38 2   2   e   javax.sound.sampled.UnsupportedAudioFileException
        //   40 2   2   e   java.io.IOException
        //   46 26  2   format  javax.sound.sampled.AudioFormat
        //   48 127 3   auline  javax.sound.sampled.SourceDataLine
        //   59 3   4   info    javax.sound.sampled.DataLine.Info
        //   80 3   5   e   javax.sound.sampled.LineUnavailableException
        //   83 3   5   e   Exception
        //   87 41  5   nBytesRead  int
        //   93 24  6   abData  byte[]
        //   136    3   7   e   java.io.IOException
        //   151    15  8   localObject Object
        // Exception table:
        //   from   to  target  type
        //   0  20  23  java/lang/Exception
        //   27 35  38  javax/sound/sampled/UnsupportedAudioFileException
        //   27 35  40  java/io/IOException
        //   61 77  80  javax/sound/sampled/LineUnavailableException
        //   61 77  83  java/lang/Exception
        //   95 133 136 java/io/IOException
        //   95 138 151 finally
      }
    })

      .start();
  }
}
@emmanue1
Copy link
Collaborator

emmanue1 commented Jun 6, 2015

Take a look on these projects : https://github.com/fesh0r/fernflower https://bitbucket.org/mstrobel/procyon. Today, they are the best decompilers that I tested.

@addisoncrump
Copy link
Author

Alright. Just giving that to you in case you wanted some extra error data. But thanks!

@emmanue1
Copy link
Collaborator

emmanue1 commented Jun 6, 2015

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants