예제 #1
0
static int
get_attribute (JCF *jcf, int index, 
	       jv_attr_type attr_type ATTRIBUTE_UNUSED)
{
  uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
  uint32 attribute_length = JCF_readu4 (jcf);
  uint32 start_pos = JCF_TELL(jcf);
  int name_length;
  const unsigned char *name_data;
  JCF_FILL (jcf, (long) attribute_length);
  if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf))
    return -2;
  if (JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
    return -2;
  name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
  name_data = JPOOL_UTF_DATA (jcf, attribute_name);

#define MATCH_ATTRIBUTE(S) \
  (name_length == sizeof (S)-1 && memcmp (name_data, S, sizeof (S)-1) == 0)

#ifdef IGNORE_ATTRIBUTE
   if (IGNORE_ATTRIBUTE (jcf, attribute_name, attribute_length))
     {
       JCF_SKIP (jcf, attribute_length);
     }
   else
#endif
#ifdef HANDLE_SOURCEFILE
  if (MATCH_ATTRIBUTE ("SourceFile"))
    {
      uint16 sourcefile_index = JCF_readu2 (jcf);
      HANDLE_SOURCEFILE(sourcefile_index);
    }
  else
#endif
#ifdef HANDLE_CONSTANTVALUE
  if (MATCH_ATTRIBUTE ("ConstantValue"))
    {
      uint16 constantvalue_index = JCF_readu2 (jcf);
      if (constantvalue_index <= 0 || constantvalue_index >= JPOOL_SIZE(jcf))
	return -2;
      HANDLE_CONSTANTVALUE(constantvalue_index);
    }
  else
#endif
#ifdef HANDLE_CODE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Code"))
    {
      uint16 j;
      uint16 max_stack ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
      uint16 max_locals ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
      uint32 code_length = JCF_readu4 (jcf);
      uint16 exception_table_length, attributes_count;
      if (code_length + 12 > attribute_length)
	return -1;
      HANDLE_CODE_ATTRIBUTE(max_stack, max_locals, code_length);
      JCF_SKIP (jcf, code_length);
      exception_table_length = JCF_readu2 (jcf);
      if (code_length + 8 * exception_table_length + 12 > attribute_length)
	return -1;
#ifdef HANDLE_EXCEPTION_TABLE
      HANDLE_EXCEPTION_TABLE (jcf->read_ptr, exception_table_length);
#endif
      JCF_SKIP (jcf, 2 * 4 * exception_table_length);
      attributes_count = JCF_readu2 (jcf);
      for (j = 0; j < attributes_count; j++)
	{
	  int code = get_attribute (jcf, index, JV_METHOD_ATTR);
	  if (code != 0)
	    return code;
	}
    }
  else
#endif /* HANDLE_CODE_ATTRIBUTE */
#ifdef HANDLE_EXCEPTIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Exceptions"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_EXCEPTIONS_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LINENUMBERTABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LineNumberTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LINENUMBERTABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LOCALVARIABLETABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LocalVariableTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LOCALVARIABLETABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("LocalVariableTypeTable"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("InnerClasses"))
    {
      uint16 count = JCF_readu2 (jcf);
      HANDLE_INNERCLASSES_ATTRIBUTE (count);
    }
  else
#endif
#ifdef HANDLE_SYNTHETIC_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Synthetic"))
    {
      HANDLE_SYNTHETIC_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_GCJCOMPILED_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("gnu.gcj.gcj-compiled"))
    {
      HANDLE_GCJCOMPILED_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_DEPRECATED_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Deprecated"))
    {
      HANDLE_DEPRECATED_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("SourceDebugExtension")) /* JSR 45 */
    {
      HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE (attribute_length);
    }
  else
#endif
#ifdef HANDLE_ENCLOSINGMETHOD_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("EnclosingMethod"))
    {
      HANDLE_ENCLOSINGMETHOD_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_SIGNATURE_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("Signature"))
    {
      HANDLE_SIGNATURE_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeVisibleAnnotations"))
    {
      HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeInvisibleAnnotations"))
    {
      HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeVisibleParameterAnnotations"))
    {
      HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("RuntimeInvisibleParameterAnnotations"))
    {
      HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
    }
  else
#endif
#ifdef HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE
  if (MATCH_ATTRIBUTE ("AnnotationDefault"))
    {
      HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE ();
    }
  else
#endif
  if (MATCH_ATTRIBUTE ("BootstrapMethods"))
    {
#ifdef HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE
      HANDLE_BOOTSTRAP_METHODS_ATTRIBUTE();
#else
      JCF_SKIP (jcf, attribute_length);
#endif
    }
   else
    {
#ifdef PROCESS_OTHER_ATTRIBUTE
      PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
#else
      JCF_SKIP (jcf, attribute_length);
#endif
    }
  if ((long) (start_pos + attribute_length) != JCF_TELL(jcf))
    return -1;
  return 0;
}
static int
get_attribute (JCF *jcf)
{
    uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
    uint32 attribute_length = JCF_readu4 (jcf);
    uint32 start_pos = JCF_TELL(jcf);
    int name_length;
    const unsigned char *name_data;
    JCF_FILL (jcf, (long) attribute_length);
    if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf))
        return -2;
    if (JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
        return -2;
    name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
    name_data = JPOOL_UTF_DATA (jcf, attribute_name);

#define MATCH_ATTRIBUTE(S) \
  (name_length == sizeof (S)-1 && memcmp (name_data, S, sizeof (S)-1) == 0)

#ifdef IGNORE_ATTRIBUTE
    if (IGNORE_ATTRIBUTE (jcf, attribute_name, attribute_length))
    {
        JCF_SKIP (jcf, attribute_length);
    }
    else
#endif
#ifdef HANDLE_SOURCEFILE
        if (MATCH_ATTRIBUTE ("SourceFile"))
        {
            uint16 sourcefile_index = JCF_readu2 (jcf);
            HANDLE_SOURCEFILE(sourcefile_index);
        }
        else
#endif
#ifdef HANDLE_CONSTANTVALUE
            if (MATCH_ATTRIBUTE ("ConstantValue"))
            {
                uint16 constantvalue_index = JCF_readu2 (jcf);
                if (constantvalue_index <= 0 || constantvalue_index >= JPOOL_SIZE(jcf))
                    return -2;
                HANDLE_CONSTANTVALUE(constantvalue_index);
            }
            else
#endif
#ifdef HANDLE_CODE_ATTRIBUTE
                if (MATCH_ATTRIBUTE ("Code"))
                {
                    uint16 j;
                    uint16 max_stack ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
                    uint16 max_locals ATTRIBUTE_UNUSED = JCF_readu2 (jcf);
                    uint32 code_length = JCF_readu4 (jcf);
                    uint16 exception_table_length, attributes_count;
                    if (code_length + 12 > attribute_length)
                        return -1;
                    HANDLE_CODE_ATTRIBUTE(max_stack, max_locals, code_length);
                    JCF_SKIP (jcf, code_length);
                    exception_table_length = JCF_readu2 (jcf);
                    if (code_length + 8 * exception_table_length + 12 > attribute_length)
                        return -1;
#ifdef HANDLE_EXCEPTION_TABLE
                    HANDLE_EXCEPTION_TABLE (jcf->read_ptr, exception_table_length);
#endif
                    JCF_SKIP (jcf, 2 * 4 * exception_table_length);
                    attributes_count = JCF_readu2 (jcf);
                    for (j = 0; j < attributes_count; j++)
                    {
                        int code = get_attribute (jcf);
                        if (code != 0)
                            return code;
                    }
                }
                else
#endif /* HANDLE_CODE_ATTRIBUTE */
#ifdef HANDLE_EXCEPTIONS_ATTRIBUTE
                    if (MATCH_ATTRIBUTE ("Exceptions"))
                    {
                        uint16 count = JCF_readu2 (jcf);
                        HANDLE_EXCEPTIONS_ATTRIBUTE (count);
                    }
                    else
#endif
#ifdef HANDLE_LINENUMBERTABLE_ATTRIBUTE
                        if (MATCH_ATTRIBUTE ("LineNumberTable"))
                        {
                            uint16 count = JCF_readu2 (jcf);
                            HANDLE_LINENUMBERTABLE_ATTRIBUTE (count);
                        }
                        else
#endif
#ifdef HANDLE_LOCALVARIABLETABLE_ATTRIBUTE
                            if (MATCH_ATTRIBUTE ("LocalVariableTable"))
                            {
                                uint16 count = JCF_readu2 (jcf);
                                HANDLE_LOCALVARIABLETABLE_ATTRIBUTE (count);
                            }
                            else
#endif
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
                                if (MATCH_ATTRIBUTE ("InnerClasses"))
                                {
                                    uint16 count = JCF_readu2 (jcf);
                                    HANDLE_INNERCLASSES_ATTRIBUTE (count);
                                }
                                else
#endif
#ifdef HANDLE_SYNTHETIC_ATTRIBUTE
                                    if (MATCH_ATTRIBUTE ("Synthetic"))
                                    {
                                        HANDLE_SYNTHETIC_ATTRIBUTE ();
                                    }
                                    else
#endif
#ifdef HANDLE_GCJCOMPILED_ATTRIBUTE
                                        if (MATCH_ATTRIBUTE ("gnu.gcj.gcj-compiled"))
                                        {
                                            HANDLE_GCJCOMPILED_ATTRIBUTE ();
                                        }
                                        else
#endif
#ifdef HANDLE_DEPRECATED_ATTRIBUTE
                                            if (MATCH_ATTRIBUTE ("Deprecated"))
                                            {
                                                HANDLE_DEPRECATED_ATTRIBUTE ();
                                            }
                                            else
#endif
                                            {
#ifdef PROCESS_OTHER_ATTRIBUTE
                                                PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
#else
                                                JCF_SKIP (jcf, attribute_length);
#endif
                                            }
    if ((long) (start_pos + attribute_length) != JCF_TELL(jcf))
        return -1;
    return 0;
}