Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SourceDebugExtension属性的Pack200/网络传输格式规范格式规范_Java_Format_Pack - Fatal编程技术网

Java SourceDebugExtension属性的Pack200/网络传输格式规范格式规范

Java SourceDebugExtension属性的Pack200/网络传输格式规范格式规范,java,format,pack,Java,Format,Pack,如果您试图用pack200打包spring context 5.0.1.RELEASE JAR,打包程序会抱怨它不知道在其中的几个类中使用的class属性SourceDebugExtension,这些类是从Kotlin类编译而来的 将此属性定义为 The SourceDebugExtension attribute is an optional attribute in the attributes table of the ClassFile structure. There can be

如果您试图用pack200打包spring context 5.0.1.RELEASE JAR,打包程序会抱怨它不知道在其中的几个类中使用的class属性
SourceDebugExtension
,这些类是从Kotlin类编译而来的


将此属性定义为

The SourceDebugExtension attribute is an optional attribute in the attributes table of the ClassFile structure. There can be no more than one SourceDebugExtension attribute in the attributes table of a given ClassFile structure.

The SourceDebugExtension attribute has the following format:


    SourceDebugExtension_attribute {
       u2 attribute_name_index;
       u4 attribute_length;
       u1 debug_extension[attribute_length];
    }

The items of the SourceDebugExtension_attribute structure are as follows:

attribute_name_index
    The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure representing the string "SourceDebugExtension".

attribute_length
    The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes. The value of the attribute_length item is thus the number of bytes in the debug_extension[] item.

debug_extension[]
    The debug_extension array holds a string, which must be in UTF-8 format. There is no terminating zero byte.

    The string in the debug_extension item will be interpreted as extended debugging information. The content of this string has no semantic effect on the Java Virtual Machine.

定义如何定义此类属性的格式,以便pack200可以处理它们


Pack200允许跳过具有这些属性的文件,或抛出这些属性,或根据网络传输格式规范定义其格式。不幸的是,我没有获得正确解析属性的格式说明符。需要由格式说明符匹配的实际数据的Hexdump示例是
debug_extension[]
的值

00000b90:                   53 4d  41 50 0a 42 65 61 6e 44 ;      SMAP.BeanD
00000ba0: 65 66 69 6e 69 74 69 6f  6e 44 73 6c 2e 6b 74 0a ;efinitionDsl.kt.
00000bb0: 4b 6f 74 6c 69 6e 0a 2a  53 20 4b 6f 74 6c 69 6e ;Kotlin.*S Kotlin
00000bc0: 0a 2a 46 0a 2b 20 31 20  42 65 61 6e 44 65 66 69 ;.*F.+ 1 BeanDefi
00000bd0: 6e 69 74 69 6f 6e 44 73  6c 2e 6b 74 0a 6f 72 67 ;nitionDsl.kt.org
00000be0: 2f 73 70 72 69 6e 67 66  72 61 6d 65 77 6f 72 6b ;/springframework
00000bf0: 2f 63 6f 6e 74 65 78 74  2f 73 75 70 70 6f 72 74 ;/context/support
00000c00: 2f 42 65 61 6e 44 65 66  69 6e 69 74 69 6f 6e 44 ;/BeanDefinitionD
00000c10: 73 6c 24 62 65 61 6e 24  31 24 63 75 73 74 6f 6d ;sl$bean$1$custom
00000c20: 69 7a 65 72 24 31 0a 2a  4c 0a 31 23 31 2c 32 37 ;izer$1.*L.1#1,27
00000c30: 33 3a 31 0a 2a 45 0a                             ;3:1.*E.


不幸的是,我还没有找到正确的格式。我希望这里有人已经这样做了,或者找到了正确的格式,运气更好。

最后我自己找到了一个可行的解决方案

格式有点棘手,因为
SourceDebugExtension
属性被定义为一个直接的UTF-8字符串,没有任何终止字符,如
\0
,并且在格式字符串中,您不能定义“获取所有剩余字节”或“直到到达字节数组的末尾为止”

但是,在阅读了一些关于格式字符串中的可能性以及
SourceDebugExtension
属性的内容格式之后,我想出了一种在大多数情况下都适用的格式

SourceDebugExtension
属性包含已解析的SMAP。在这种情况下,“已解决”是很重要的,因为在未解决的SMAP中,可能存在已包含结束部分的嵌入式SMAP,这将使其变得更复杂,但并非不可能。在已解决的SMAP中,您始终在最后有
*E
,其中
可能是常见的可疑对象
\r
\n
\r\n
,如果已解决,则此序列不可能出现在SMAP的前面

现在,我们可以使用UNIONLAYOUT元素和递归自调用来构建以下格式字符串,在大多数情况下,该字符串将与SMAP正确匹配。此格式字符串假定的唯一情况是,如果在
*E
之前找到行终止符
\r\n
,则它也应在它之后,如果之前只找到
\r
\n
,则它之后只应找到
\r
\n
。哪一个不重要,只是不重要。\r\n。如果发生这种情况,打包将失败,并抱怨一个字节未被处理。但是如果我们检查两个字符,并且只剩下一个字符,我们将得到一个
ArrayIndexOutOfBoundsException
,我认为这是不太可能的情况,不同的行终止符是混合的

因此,我目前的做法是:

[TB(10)[TB(42)[TB(69)[TB(13,10)[]()[(0)]]()[(0)]]()[(0)]](13)[TB(10)[TB(42)[TB(69)[TB(13)[TB(10)[]()[(0)]]()[(0)]]()[(0)]]()[(0)]](42)[TB(69)[TB(13,10)[]()[(0)]]()[(0)]]()[(0)]]()[(0)]]
为了更好地理解这里的相同格式,有一些间距和语义内容。这样就不能直接使用。它必须通过
com.sun.java.util.jar.pack.Attribute#normalizeLayoutString
传递,这是包私有类中的一个
公共静态
方法,因此通常不可访问。如果您使用反射或Groovy为您执行此操作,或者将方法体复制到您自己的方法中,那么您当然可以在代码中使用此版本

[
   # covered likely cases:
   # \\n*E\\n
   # \\r\\n*E\\r\\n
   # \\r*E\\r
   #
   # covered unlikely cases:
   # \\n*E\\r
   # \\r*E\\n
   #
   # uncovered unlikely cases:
   # \\n*E\\r\\n
   # \\r*E\\r\\n
   # \\r\\n*E\\r
   # \\r\\n*E\\n
   TB
      (\\\n) [
         # covered cases:
         # \\n*E\\r
         # \\n*E\\n
         TB
            (\\*) [
               TB
                  (\\E) [
                     TB
                        (\\\r, \\\n) []
                        () [(0)]
                  ]
                  () [(0)]
            ]
            () [(0)]
      ]
      (\\\r) [
         # covered cases:
         # \\r\\n*E\\r\\n
         # \\r*E\\r
         # \\r*E\\n
         TB
            (\\\n) [
               # covered cases:
               # \\r\\n*E\\r\\n
               TB
                  (\\*) [
                     TB
                        (\\E) [
                           TB
                              (\\\r) [
                                 TB
                                    (\\\n) []
                                    () [(0)]
                              ]
                              () [(0)]
                        ]
                        () [(0)]
                  ]
                  () [(0)]
            ]
            (\\*) [
               # covered cases:
               # \\r*E\\r
               # \\r*E\\n
               TB
                  (\\E) [
                     TB
                        (\\\r, \\\n) []
                        () [(0)]
                  ]
                  () [(0)]
            ]
            () [(0)]
      ]
      () [(0)]
]

最后我自己找到了一个可行的解决方案

格式有点棘手,因为
SourceDebugExtension
属性被定义为一个直接的UTF-8字符串,没有任何终止字符,如
\0
,并且在格式字符串中,您不能定义“获取所有剩余字节”或“直到到达字节数组的末尾为止”

但是,在阅读了一些关于格式字符串中的可能性以及
SourceDebugExtension
属性的内容格式之后,我想出了一种在大多数情况下都适用的格式

SourceDebugExtension
属性包含已解析的SMAP。在这种情况下,“已解决”是很重要的,因为在未解决的SMAP中,可能存在已包含结束部分的嵌入式SMAP,这将使其变得更复杂,但并非不可能。在已解决的SMAP中,您始终在最后有
*E
,其中
可能是常见的可疑对象
\r
\n
\r\n
,如果已解决,则此序列不可能出现在SMAP的前面

现在,我们可以使用UNIONLAYOUT元素和递归自调用来构建以下格式字符串,在大多数情况下,该字符串将与SMAP正确匹配。此格式字符串假定的唯一情况是,如果在
*E
之前找到行终止符
\r\n
,则它也应在它之后,如果之前只找到
\r
\n
,则它之后只应找到
\r
\n
。哪一个不重要,只是不重要。\r\n。如果发生这种情况,打包将失败,并抱怨一个字节未被处理。但是如果我们检查两个字符,并且只剩下一个字符,我们将得到一个
ArrayIndexOutOfBoundsException
,我认为这是不太可能的情况,不同的行终止符是混合的

因此,我目前的做法是:

[TB(10)[TB(42)[TB(69)[TB(13,10)[]()[(0)]]()[(0)]]()[(0)]](13)[TB(10)[TB(42)[TB(69)[TB(13)[TB(10)[]()[(0)]]()[(0)]]()[(0)]]()[(0)]](42)[TB(69)[TB(13,10)[]()[(0)]]()[(0)]]()[(0)]]()[(0)]]
为了更好地理解这里的相同格式,有一些间距和语义内容。这样就不能直接使用。它必须通过
com.sun.java.util.jar.pack.Attribute#normalizeLayoutString
传递,这是包私有类中的一个
公共静态
方法,因此通常不可访问。如果您使用反射或Groovy为您执行此操作,或者将方法体复制到您自己的方法中,那么您当然可以在代码中使用此版本

[
   # covered likely cases:
   # \\n*E\\n
   # \\r\\n*E\\r\\n
   # \\r*E\\r
   #
   # covered unlikely cases:
   # \\n*E\\r
   # \\r*E\\n
   #
   # uncovered unlikely cases:
   # \\n*E\\r\\n
   # \\r*E\\r\\n
   # \\r\\n*E\\r
   # \\r\\n*E\\n
   TB
      (\\\n) [
         # covered cases:
         # \\n*E\\r
         # \\n*E\\n
         TB
            (\\*) [
               TB
                  (\\E) [
                     TB
                        (\\\r, \\\n) []
                        () [(0)]
                  ]
                  () [(0)]
            ]
            () [(0)]
      ]
      (\\\r) [
         # covered cases:
         # \\r\\n*E\\r\\n
         # \\r*E\\r
         # \\r*E\\n
         TB
            (\\\n) [
               # covered cases:
               # \\r\\n*E\\r\\n
               TB
                  (\\*) [
                     TB
                        (\\E) [
                           TB
                              (\\\r) [
                                 TB
                                    (\\\n) []
                                    () [(0)]
                              ]
                              () [(0)]
                        ]
                        () [(0)]
                  ]
                  () [(0)]
            ]
            (\\*) [
               # covered cases:
               # \\r*E\\r
               # \\r*E\\n
               TB
                  (\\E) [
                     TB
                        (\\\r, \\\n) []
                        () [(0)]
                  ]
                  () [(0)]
            ]
            () [(0)]
      ]
      () [(0)]
]