In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "java how to disassemble bytecode files", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "java how to disassemble bytecode files"!
Source code public class test {private static int classV = 2; public static void main (String [] args) {classV = 200; int localV = 4; localV = 400;}} javap instruction and option 0: no option to print package, protected and public fields, and methods public class com.example.test {public com.example.test (); public static void main (java.lang.String []); static {};} 1: auxiliary instruction
-help
-help
-?
2: local variables for line numbers and methods
-l
Public class com.example.test {/ / default constructor public com.example.test (); / / Line number: command offset position LineNumberTable: line 3: 0 / / Local variable table LocalVariableTable: Start Length Slot Name Signature 050 this Lcom/example/test; public static void main (java.lang.String []) / / Line number: command offset position LineNumberTable: line 6: 0 line 7: 6 line 8: 8 line 9: 12 / / Local variable table LocalVariableTable: Start Length Slot Name Signature 0130 args [Ljava/lang/String; / / method parameter 851 localV I. / local variable localV / / static code block static {}; LineNumberTable: line 4: 0} 3 filter method attribute classes by level
-public
-protected
-private
-p
4. Disassemble assembly instructions
Javap-c
/ / Pure assembly instruction public class com.example.test {public com.example.test (); Code: 0: aload_0 1: invokespecial # 1 / / Method java/lang/Object. "": () V 4: return public static void main (java.lang.String []) Code: 0: sipush 200 3: putstatic # 2 / / Field classV:I 6: iconst_4 7: istore_1 8: sipush 400 11: istore_1 12: return static {} Code: 0: iconst_2 1: putstatic # 2 / / Field classV:I 4: return} 5 displays verbose details
Javap-v
Classfile / Users/zhangshanxue/Downloads/akka-quickstart-java/target/classes/com/example/test.class//javap-sysinfo displays the following three lines Last modified 2021-4-5 Size 507 bytes MD5 checksum 24a0c74751aafd61d0f7f69be9c161db Compiled from "test.java" public class com.example.test// is 1.8 comparison table and reasons see Appendix 1 / / U2 type, that is, each occupies two bytes of minor version: 0 major version: 52 / / Class flag see Appendix 2 / / U2 type access_flags through bits and indicates multiple permissions flags: ACC_PUBLIC, ACC_SUPER / / constant pool. Class file structure emphasis / / u22 two bytes denote quantity / / pool constant pool / / constant_pool_count and constant_pool [] indicate that most of the contents in the constant pool depend on this constant pool Constant pool: # 1 = Methodref # 4.room22 / / java/lang/Object. "": () V # 2 = Fieldref # 3.room23 / / com/example/test.classV:I # 3 = Class # 24 / / com/example/test # 4 = Class # 25 / / java/lang/Object # 5 = Utf8 classV # 6 = Utf8 I # 7 = Utf8 # 8 = Utf8 () V # 9 = Utf8 Code # 10 = Utf8 LineNumberTable # 11 = Utf8 LocalVariableTable # 12 = Utf8 this # 13 = Utf8 Lcom/example/test # 14 = Utf8 main # 15 = Utf8 ([Ljava/lang/String;) V # 16 = Utf8 args # 17 = Utf8 [Ljava/lang/String # 18 = Utf8 localV # 19 = Utf8 # 20 = Utf8 SourceFile # 21 = Utf8 test.java # 22 = NameAndType # 7 / "": () V # 23 = NameAndType # 5 / / classV:I # 24 = Utf8 com/example / test # 25 = Utf8 java/lang/Object {public com.example.test () Descriptor: () V flags: ACC_PUBLIC Code: / / Code assembly instructions stack=1, locals=1 Args_size=1 0: aload_0 1: invokespecial # 1 / / Method java/lang/Object. ": () V 4: return / / Javap-l displays the following information / / line number and the corresponding instruction offset position above LineNumberTable: line 3: 0 LocalVariableTable: / / local variable table Valid Start Length Slot Name Signature 0 50 this Lcom/example/test between instruction offset position start start+length Public static void main (java.lang.String []); descriptor: ([Ljava/lang/String ) V flags: ACC_PUBLIC, ACC_STATIC Code: / / Code assembly instructions stack=1, locals=2 Args_size=1 0: sipush 2003: putstatic # 2 / / Field classV:I 6: iconst_4 7: istore_1 8: sipush 40011: istore_1 12: return / / Javap-l displays the following information / / line number and the corresponding instruction offset position above LineNumberTable: line 6: 0 line 7: 6 line 8: 8 line 9: 12 LocalVariableTable: Start Length Slot Name Signature 0 13 0 args [Ljava/lang/String 8 51 localV I static {}; descriptor: () V flags: ACC_STATIC Code: stack=1, locals=0, args_size=0 0: iconst_2 1: putstatic # 2 / / Field classV:I 4: return / / Line number and the corresponding instruction offset position LineNumberTable: line 4: 0 above
Direct analysis of bytecode blocks
1 to facilitate communication and expression of the structure of class files
Use U1u2u4u8 unsigned numbers to represent bytes and use * _ info to end with pools (arrays cp_info, field_info, method_info, attribute_info
ClassFile {/ / indicates that the file format of java class is fixed as cafe baby 4-byte U4 magic; / / major version number and minor version number together determine the version / / U2 type of class file format, that is, each occupies two bytes / / 56 contains 56 and later support for N.0 and N.65535u2 minor_version / / before the major version 56 (java12), minjor only supports 0 U2 major_version; / / constant pool number U2 constant_pool_count; cp_info constant_ pool. U2 access_flags. / / this_class, super_class and interfaces point to the CONSTANT_Class_info U2 this_class; U2 super_class; U2 interfaces_count; U2 interfaces of the constant pool [interfaces _ count]; U2 fields_count / / points to constant pool structures:CONSTANT_Fieldref_info structure field_info fields [fields _ count]; U2 methods_count; / / points to constant pool CONSTANT_Methodref_info structure method_info methods [count]; U2 attributes_count; attribute_info attributions [attributes _ count] } Thank you for reading, the above is the content of "how to disassemble the bytecode file by java". After the study of this article, I believe you have a deeper understanding of the problem of how to disassemble the bytecode file by java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.