27.09.2008, 05:05
|
#42
|
Нуждающийся
Регистрация: 10.02.2007
Сообщений: 99
Написано 18 полезных сообщений (для 28 пользователей)
|
Re: создание MIDletPascal compiler'a
Вобчем смотрим чо происходит
0009h 1 1 CONSTANT_Utf8-Unicode [10] = HelloWorld
0016h 2 7 CONSTANT_Class:1
0019h 3 1 CONSTANT_Utf8-Unicode [16] = java/lang/Object
002Ch 4 7 CONSTANT_Class:3
002Fh 5 1 CONSTANT_Utf8-Unicode [4] = main
0036h 6 1 CONSTANT_Utf8-Unicode [22] = ([Ljava/lang/String V
004Fh 7 1 CONSTANT_Utf8-Unicode [4] = Code
0056h 8 1 CONSTANT_Utf8-Unicode [15] = LineNumberTable
0068h 9 1 CONSTANT_Utf8-Unicode [3] = out
006Eh 10 1 CONSTANT_Utf8-Unicode [21] = Ljava/io/PrintStream;
0086h 11 12 CONSTANT_NameAndType: 9 10
008Bh 12 1 CONSTANT_Utf8-Unicode [16] = java/lang/System
009Eh 13 7 CONSTANT_Class: 12
00A1h 14 9 CONSTANT_Fieldref: 13 11
00A6h 15 1 CONSTANT_Utf8-Unicode [12] = Hello World!
00B5h 16 8 CONSTANT_String:15
00B8h 17 1 CONSTANT_Utf8-Unicode [7] = println
00C2h 18 1 CONSTANT_Utf8-Unicode [21] = (Ljava/lang/String V
00DAh 19 12 CONSTANT_NameAndType: 17 18
00DFh 20 1 CONSTANT_Utf8-Unicode [19] = java/io/PrintStream
00F5h 21 7 CONSTANT_Class: 20
00F8h 22 10 CONSTANT_Methodref: 21 19
00FDh 23 1 CONSTANT_Utf8-Unicode [6] = <init>
0106h 24 1 CONSTANT_Utf8-Unicode [3] = ()V
010Ch 25 12 CONSTANT_NameAndType: 23 24
0111h 26 10 CONSTANT_Methodref: 4 25
0116h 27 1 CONSTANT_Utf8-Unicode [10] = SourceFile
0123h 28 1 CONSTANT_Utf8-Unicode [15] = HelloWorld.java
0136h access_flags:32
0138h this_class:2
013Ah super_class:4
013Ch interfaces[0]=
013Eh field_info[0]=
0140h method_info [2]=
0142h method_info: 0---------
access_flags:9
name_index:5
signature_index:6
attributes_count:1 offs:[014Ah]
014Ah GenericAttribute_info
attribute_name:7 <- Ссылкана 7 элемент “Code”
attribute_length:37 <- Длинна
00 02 00 01 00 00 00 09 B2 00 0E 12 10 B6 00 16 B1 00 00 00 01 00 08 00 00 00 0A00 02 00 00 00 03 00 08 00 04
0175h method_info: 1---------
access_flags:0
name_index:23
signature_index:24
attributes_count:1 offs:[017Dh]
017Dh GenericAttribute_info
attribute_name:7 <- Ссылкана 7 элемент “Code”
attribute_length:33 <- Длинна
00 01 00 01 00 00 00 05 2A B7 00 1A B1 00 00 00 01 00 08 00 00 00 0A 00 02 00 00 00 01 00 04 00 01
OFFSET: 01A4
01A4h attribute_info [1]=
красным выделил где данные уже считываюца, тоесть у нас уже атрибуты получены, поэтому дальше надо сразу разбирать код
Вот на вскидку...
procedure load_attribute_info;
...
s := getConstStr(pGenericAttribute_info^.attribute_name - 1); // отнятьединицу так как элементы с нуля отчет ведут
...
if s='Code' then
...
pCode_attribute := swap2(swap4(swap2(swap2(swap4(p,0),0),0),0),0); // удалить красное
writeln(hexw(rc-sizeof(pCode_attribute^.attribute_name_index)),
' attribute_name_index:',pCode_attribute^.attribute_ name_index);
writeln(hexw(rc-sizeof(pCode_attribute^.attribute_length)),
' attribute_length:',pCode_attribute^.attribute_leng th); // Удалить
{}
tCode_attribute = record
attribute_name_index : word; // Удалить или задать pGenericAttribute_info^.attribute_name
attribute_length : longInt;// Удалить или задать pGenericAttribute_info ^.attribute_length
max_stack : word;
max_locals : word;
code_length : longInt;
end;
В итоге получаем типа вот этого
attribute_name:7 <- Ссылкана 7 элемент “Code”
attribute_length:37 <- Длинна
0150h Code:
0156 max_stack:2
0156 max_locals:1
0154 code_length:9
0165h GenericAttribute_info
attribute_name:8
attribute_length:10
00 02 00 00 00 03 00 08 00 04
где красным - это уже сам байт-код должен идти, а за ним уже разбор exception_table
и естественно если у нас тута будет attribute_name:NN <- Ссылка на элемент “Exceptions” то разбирать её...
Ужо голова не соображает
abcdef дружище ты если проснесся быстрее меня, замути тему... А то я ужо совсем в осадок выпадаю, кабы косяков не натворил...
|
(Offline)
|
|