> theUser BL wrote: > > Hi! > > > But where can I find documentations about .class files? How are they are > > structures and so on? > > In the JVM specification, 2nd edition, for example. There is quite a > bunch of literature explaining the workings of bytecode and the class > file format, depending on the background you're after, from compiler > design books, over interactive introductions, to formal methods. Thx. It helps, but not much. I have written a little HelloWorld program in Java and have then treied to understand the created binary. The most things I understand, but there are three big fields where I don't know for what they are. But if I change there a bit, the program will not run, so that areas seens to be important. To understand it, I have written a little QBasic, program which generates that .class file. But as I said, there are the three big areas (one with 34 bytes and two with 39 bytes at a time) , which I don't understand. ------------------------------------ DECLARE FUNCTION invokespecial$ (a&) DECLARE FUNCTION invokevirtual$ (a&) DECLARE FUNCTION ldc$ (a%) DECLARE FUNCTION getstatic$ (a&) DECLARE FUNCTION LStr$ (name$) DECLARE FUNCTION unhex$ (hexa$) aload0$ = CHR$(42) return$ = CHR$(177) CLS OPEN "HW.dat" FOR OUTPUT AS #1 PRINT #1, "" CLOSE #1 OPEN "HW.dat" FOR BINARY AS #1 co$ = "" co$ = co$ + unhex$("CAFEBABE") co$ = co$ + unhex$("00000032") ' Classversion Number 0x32=50 co$ = co$ + unhex$("0024") 'Length of the now comming field+1 co$ = co$ + unhex$("0A00090012") '0x01 'java/lang/Object."<init>":()V co$ = co$ + unhex$("0900130014") '0x02 'java/lang/System.out:Ljava/io/PrintStream; co$ = co$ + unhex$("080015") '0x03 'der erste Text, co$ = co$ + unhex$("0A00160017") '0x04 'java/io/PrintStream.println:(Ljava/lang/String;)V co$ = co$ + unhex$("080018") '0x05 'der zweite Text co$ = co$ + unhex$("0A00160019") '0x06 'java/io/PrintStream.print:(Ljava/lang/String;)V co$ = co$ + unhex$("08001A") '0x07 'und der dritte Text. co$ = co$ + unhex$("07001B") '0x08 'HalloWelt co$ = co$ + unhex$("07001C") '0x09 'java/lang/Object co$ = co$ + LStr$("<init>") '0x0A co$ = co$ + LStr$("()V") '0x0B co$ = co$ + LStr$("Code") '0x0C co$ = co$ + LStr$("LineNumberTable") '0x0D co$ = co$ + LStr$("main") '0x0E co$ = co$ + LStr$("([Ljava/lang/String;)V") '0x0F co$ = co$ + LStr$("SourceFile") '0x10 co$ = co$ + LStr$("HalloWelt.java") '0x11 co$ = co$ + unhex$("0C000A000B") '0x12 '"<init>":()V co$ = co$ + unhex$("07001D") '0x13 'java/lang/System. co$ = co$ + unhex$("0C001E001F") '0x14 'out:Ljava/io/PrintStream; co$ = co$ + LStr$("der erste Text,") '0x15 co$ = co$ + unhex$("070020") '0x16 'java/io/PrintStream. co$ = co$ + unhex$("0C00210022") '0x17 'println:(Ljava/lang/String;)V co$ = co$ + LStr$("der zweite Text ") '0x18 co$ = co$ + unhex$("0C00230022") '0x19 'print:(Ljava/lang/String;)V co$ = co$ + LStr$("und der dritte Text.") '0x1A co$ = co$ + LStr$("HalloWelt") '0x1B co$ = co$ + LStr$("java/lang/Object") '0x1C co$ = co$ + LStr$("java/lang/System") '0x1D co$ = co$ + LStr$("out") '0x1E co$ = co$ + LStr$("Ljava/io/PrintStream;") '0x1F co$ = co$ + LStr$("java/io/PrintStream") '0x20 co$ = co$ + LStr$("println") '0x21 co$ = co$ + LStr$("(Ljava/lang/String;)V") '0x22 co$ = co$ + LStr$("print") '0x23 co$ = co$ + unhex$("0020000800090000000000020000000A") ' for what is this ??? possible is the 0x20=32 the number of bytes until co$ = co$ + unhex$("000B0001000C0000001D000100010000") ' the first assembler code. But what is with the rest? co$ = co$ + unhex$("0005") co$ = co$ + aload0$ co$ = co$ + invokespecial$(1) co$ = co$ + return$ co$ = co$ + unhex$("00000001000D00000006000100000001") ' and for what this ??? co$ = co$ + unhex$("0009000E000F0001000C0000003D0002") co$ = co$ + unhex$("000100000019") co$ = co$ + getstatic$(2) co$ = co$ + ldc$(3) co$ = co$ + invokevirtual$(4) co$ = co$ + getstatic$(2) co$ = co$ + ldc$(5) co$ = co$ + invokevirtual$(6) co$ = co$ + getstatic$(2) co$ = co$ + ldc$(7) co$ = co$ + invokevirtual$(4) co$ = co$ + return$ co$ = co$ + unhex$("00000001000D00000012000400000003") ' and this ??? co$ = co$ + unhex$("00080004001000050018000600010010") co$ = co$ + unhex$("000000020011") PUT #1, 1, co$ CLOSE #1 SHELL "xcopy /y HW.dat HalloWelt.class" SHELL "java HalloWelt" 'SHELL "c:\Progra~1\java\jdk16~1.0_1\bin\javap.exe -c HalloWelt" FUNCTION getstatic$ (a&) IF a& > 65535 THEN PRINT "*** Error": END a1& = INT(a& / 256) a2& = a& - a1& * 256 getstatic$ = CHR$(178) + CHR$(a1&) + CHR$(a2&) END FUNCTION FUNCTION invokespecial$ (a&) IF a& > 65535 THEN PRINT "*** Error": END a1& = INT(a& / 256) a2& = a& - a1& * 256 invokespecial$ = CHR$(183) + CHR$(a1&) + CHR$(a2&) END FUNCTION FUNCTION invokevirtual$ (a&) IF a& > 65535 THEN PRINT "*** Error": END a1& = INT(a& / 256) a2& = a& - a1& * 256 invokevirtual$ = CHR$(182) + CHR$(a1&) + CHR$(a2&) END FUNCTION FUNCTION ldc$ (a%) IF a% > 255 THEN PRINT "*** Error": END ldc$ = CHR$(18) + CHR$(a%) END FUNCTION FUNCTION LStr$ (name$) ' gives out the length of name$ as character and adds the name$ to it a& = LEN(name$) IF a& > 65535 THEN PRINT "*** Error": END a1& = INT(a& / 256) a2& = a& - a1& * 256 LStr$ = CHR$(1) + CHR$(a1&) + CHR$(a2&) + name$ END FUNCTION FUNCTION unhex$ (hexa$) uhex$ = "" FOR i = 1 TO LEN(hexa$) / 2 ahex$ = MID$(hexa$, i * 2 - 1, 1) IF ahex$ = "0" THEN abyte% = 0 IF ahex$ = "1" THEN abyte% = 1 IF ahex$ = "2" THEN abyte% = 2 IF ahex$ = "3" THEN abyte% = 3 IF ahex$ = "4" THEN abyte% = 4 IF ahex$ = "5" THEN abyte% = 5 IF ahex$ = "6" THEN abyte% = 6 IF ahex$ = "7" THEN abyte% = 7 IF ahex$ = "8" THEN abyte% = 8 IF ahex$ = "9" THEN abyte% = 9 IF ahex$ = "A" THEN abyte% = 10 IF ahex$ = "B" THEN abyte% = 11 IF ahex$ = "C" THEN abyte% = 12 IF ahex$ = "D" THEN abyte% = 13 IF ahex$ = "E" THEN abyte% = 14 IF ahex$ = "F" THEN abyte% = 15 bhex$ = MID$(hexa$, i * 2, 1) IF bhex$ = "0" THEN bbyte% = 0 IF bhex$ = "1" THEN bbyte% = 1 IF bhex$ = "2" THEN bbyte% = 2 IF bhex$ = "3" THEN bbyte% = 3 IF bhex$ = "4" THEN bbyte% = 4 IF bhex$ = "5" THEN bbyte% = 5 IF bhex$ = "6" THEN bbyte% = 6 IF bhex$ = "7" THEN bbyte% = 7 IF bhex$ = "8" THEN bbyte% = 8 IF bhex$ = "9" THEN bbyte% = 9 IF bhex$ = "A" THEN bbyte% = 10 IF bhex$ = "B" THEN bbyte% = 11 IF bhex$ = "C" THEN bbyte% = 12 IF bhex$ = "D" THEN bbyte% = 13 IF bhex$ = "E" THEN bbyte% = 14 IF bhex$ = "F" THEN bbyte% = 15 uhex$ = uhex$ + CHR$(abyte% * 16 + bbyte%) NEXT i unhex$ = uhex$ END FUNCTION Schlafmütze oder Querdenker? Zeig bei Live Battle, was du auf dem Kasten hast! |