?????????????Java Class??????
?????tinylcy ???????[ 2017/2/15 10:42:40 ] ??????????????????? Java
????????д??????????????????ClassAnalyzer??ClassAnalyzer????????????????Java Class??????????????????????????????????????????????????????Щ?????????????????????JDK????????????й???javap????????Class????????????????????????????????·??
????Class???
??????????????????????壬???Class?????????????????????????Java???????“??д??Σ?????????”??Java??????淶??Class?????????????漲??????Class?????????????λ????????Щ???????????κη??????????????Class????д洢????????????????????е???????????????????????????????????????????????
????????Java??????淶??Class????????????????C????????α?????洢?????????α???????????????????????????????Java??????淶??????u1??u2??u4??u8???????1??????2??????4??????8??????????????????????????????????????????????á???????????????????????????????????????????????????????????????????????????????в?ι??????????????????????Class??????????????????ClassAnalyzer??u1??u2??u4??u8???????byte??short??int??long??Class??????????????Java??
public class ClassFile {
public U4 magic; // magic
public U2 minorVersion; // minor_version
public U2 majorVersion; // major_version
public U2 constantPoolCount; // constant_pool_count
public ConstantPoolInfo[] cpInfo; // cp_info
public U2 accessFlags; // access_flags
public U2 thisClass; // this_class
public U2 superClass; // super_class
public U2 interfacesCount; // interfaces_count
public U2[] interfaces; // interfaces
public U2 fieldsCount; // fields_count
public FieldInfo[] fields; // fields
public U2 methodsCount; // methods_count
public MethodInfo[] methods; // methods
public U2 attributesCount; // attributes_count
public BasicAttributeInfo[] attributes; // attributes
}
??????ν???
???????Class???????????????У??????????Class?????汾??????????????????????????????????????????Class????ж???ù?????????????????????????????????????????????????????????????4??????????????α??????????????????????????κ??????????????????????Class????????????????????????????α??????????????????????????????????
???????????????Class?????????????????????洢???е?????????????????????????????????????????????????????????Java??????淶???????????????????????????????????????????????????????????????м?????????
????· ??????????????????u1?????tag???????
????· ???????????????С??constantPoolCount????????1?????磬???constantPoolCount????47???????????????46??????
????· ?????????????Χ??1????????磬???constantPoolCount????47??????????????????Χ?1~46??????????0???????????????????“???????κ?????????????”??
????· CONSTANT_Utf8_info?????????а???u1?????tag??u2?????length????length??u1????????bytes????length????????????????????MUTF-8??Modified UTF-8??????????????MUTF-8??UTF-8?????????????????????????null??????????2????0xC0??0x80???????????????????UTF-16??????????????????????????????????UTF-8????
??????????????????Щ??????е??????Class???????α????????????????????????Java??????淶??????????????ClassAnalyzer???????????????????????????????????????????????????tag????????????????????????????????????u2?????attribute_name_index??attribute_name_index????????е????CONSTANT_Utf8_info???????????ó???????????????????????????????ClassAnalyzer???????attribute_name_index???????????????????????????????????
??????α?????????????????????????????????????????????????????????α??????????u2?????access_flags?????u2?????name_index?????u2?????descriptor_index?????u2?????attributes_count??attributes_count??attribute_info?????attributes??????????????????????????attributes??????????????????????????
????Class???????????????????α??????洢????????access_flags?????????????????????????????????????????Code?????Code????洢??Java???????????????????ClassAnalyzer?У?Code?????Java??????????????г????????????
public class Code extends BasicAttributeInfo {
private short maxStack;
private short maxLocals;
private long codeLength;
private byte[] code;
private short exceptionTableLength;
private ExceptionInfo[] exceptionTable;
private short attributesCount;
private BasicAttributeInfo[] attributes;
...
private class ExceptionInfo {
public short startPc;
public short endPc;
public short handlerPc;
public short catchType;
...
}
}
??????Code?????У?codeLength??code???????洢?????????????????????????????u1??????????????????????????code?е?????????????????????????????????????codeLength?????u4?????????????????????????????????65535?????????
???????????
????ClassAnalyzer????????????GitHub?????ClassAnalyzer??README?У???????????Class???????????Class??????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11