diff --git a/attributes.js b/attributes.js index e19dd2b..c6acc23 100644 --- a/attributes.js +++ b/attributes.js @@ -1,3 +1,39 @@ +var ExceptionTableEntry = function(dStream, constantPool){ + this.start_pc = dStream.getU2(); + this.end_pc = dStream.getU2(); + this.handler_pc = dStream.getU2(); + var catchType = dStream.getU2(); + if (catchType){ + this.catch_type = ConstantPoolRef(catchType, constantPool,CONSTANT_Class); + }else{ + this.catch_type = null; + } +} + +var InnerClass = function(dStream, constantPool){ + this.inner_class_info = ConstantPoolRef(dStream.getU2(), constantPool,CONSTANT_Class); + var outerClassIndex = dStream.getU2(); + if (outerClassIndex){ + this.outer_class_info = ConstantPoolRef(outerClassIndex, constantPool,CONSTANT_Class); + }else{ + this.outer_class_info = null; + } + this.inner_name = ConstantPoolRef(dStream.getU2(), constantPool,CONSTANT_Utf8); + this.inner_class_access_flags = dStream.getU2(); +} + +var LineNumberTableEntry = function(dStream){ + this.start_pt = dStream.getU2(); + this.line_number = dStream.getU2(); +} + +var LocalVariableTableEntry = function(dStream, constantPool){ + this.start_pc = dStream.getU2(); + this.length =dStream.getU2(); + this.name = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8); + this.descriptor = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8); + this.index = dStream.getU2(); +} var Attributes_table = { ConstantValue: function(){ @@ -19,7 +55,100 @@ var Attributes_table = { Code: function(){ this.read = function(dStream, constantPool){ + this.max_stack = dStream.getU2(); + this.max_locals = dStream.getU2(); + this.code_length = dStream.getU4(); + this.code = []; + for (var i=0; i< this.code_length; i++){ + this.code[i] = dStream.getU1(); + } + + this.exception_table_length = dStream.getU2(); + this.exception_table = []; + for (var i=0; i< this.exception_table_length; i++){ + this.exception_table[i] = new ExceptionTableEntry(dStream, constantPool); + if (this.start_pc >= this.exception_table_length){ + throw "Code attr Invalid Exception Table Entry, start_pc >= table length"; + } + if (this.end_pc > this.exception_table_length){ + throw "Code attr Invalid Exception Table Entry, end_pc > table length"; + } + if (this.start_pc > this.end_pc){ + throw "Code attr Invalid Exception Table Entry, start_pc > end_pc"; + } + if (this.start_pc >= this.exception_table_length){ + throw "Code attr Invalid Exception Table Entry, handler_pc >= table length"; + } + } + + this.attributes_count = dStream.getU2(); + this.attributes = []; + for(var i=0; i= constantPool.constantPool.length){ + throw "ConstantPoolRef: ref out of bounds: " + (index-1).toString() + ", length: " + constantPool.constantPool.length; + } var result = constantPool.constantPool[index - 1]; if (expected && result.id != expected){ throw "ConstantPoolRef: ref was expected to be " + constTagName(expected) + " but at " + index + " there's a " + constTagName(result.id); diff --git a/fieldInfo.js b/fieldInfo.js deleted file mode 100644 index f782fb1..0000000 --- a/fieldInfo.js +++ /dev/null @@ -1,8 +0,0 @@ -var FieldInfo = function(dStream){ - this.access_flags = dStream.getU2(); - this.name_index = dStream.getU2(); - this.descriptor_index = dStream.getU2(); - this.attributes_count = dStream.getU2(); - // VER: attributes must be restricted. - this.attributes = []; -} \ No newline at end of file diff --git a/infos.js b/infos.js new file mode 100644 index 0000000..6b48bda --- /dev/null +++ b/infos.js @@ -0,0 +1,21 @@ +var FieldInfo = function(dStream,constantPool){ + this.access_flags = dStream.getU2(); + this.name_index = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8); + this.descriptor_index = ConstantPoolRef(dStream.getU2(), constantPool, CONSTANT_Utf8); + this.attributes_count = dStream.getU2(); + this.attributes = []; + for (var i=0; i 50 || this.majorVersion < 45){ throw "Unsuported java class file format version"; @@ -81,6 +83,17 @@ ClassDefinition = function (file){ } this.fields_count = dataStream.getU2(); + this.fields = [] + for(var i=0; i