Ejemplo n.º 1
0
 private void WriteElementValue(BigEndianStream bes, object val)
 {
     if (val is object[])
     {
         object[] arr = (object[])val;
         if (AnnotationDefaultAttribute.TAG_ENUM.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ENUM);
             bes.WriteUInt16(classFile.AddUtf8((string)arr[1]));
             bes.WriteUInt16(classFile.AddUtf8((string)arr[2]));
             return;
         }
         else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY);
             object[] elemarr = (object[])arr[1];
             bes.WriteUInt16((ushort)elemarr.Length);
             foreach (object elem in elemarr)
             {
                 WriteElementValue(bes, elem);
             }
             return;
         }
     }
     throw new NotImplementedException(val.GetType().FullName);
 }
Ejemplo n.º 2
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 2 * classes.Count));
     bes.WriteUInt16((ushort)classes.Count);
     foreach (ushort idx in classes)
     {
         bes.WriteUInt16(idx);
     }
 }
Ejemplo n.º 3
0
 public void Write(BigEndianStream bes)
 {
     bes.WriteUInt16((ushort)access_flags);
     bes.WriteUInt16(name_index);
     bes.WriteUInt16(descriptor_index);
     bes.WriteUInt16((ushort)attribs.Count);
     for (int i = 0; i < attribs.Count; i++)
     {
         attribs[i].Write(bes);
     }
 }
Ejemplo n.º 4
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(1 + names.Length * 4));
     bes.WriteByte((byte)names.Length);
     foreach (ushort idx in names)
     {
         bes.WriteUInt16(idx);
         bes.WriteUInt16(0);
     }
 }
Ejemplo n.º 5
0
 internal void Add(object[] annot)
 {
     count++;
     bes.WriteUInt16(classFile.AddUtf8((string)annot[1]));
     bes.WriteUInt16((ushort)((annot.Length - 2) / 2));
     for (int i = 2; i < annot.Length; i += 2)
     {
         bes.WriteUInt16(classFile.AddUtf8((string)annot[i]));
         WriteElementValue(bes, annot[i + 1]);
     }
 }
Ejemplo n.º 6
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 8 * classes.Count));
     bes.WriteUInt16((ushort)classes.Count);
     foreach (Item i in classes)
     {
         bes.WriteUInt16(i.inner_class_info_index);
         bes.WriteUInt16(i.outer_class_info_index);
         bes.WriteUInt16(i.inner_name_index);
         bes.WriteUInt16(i.inner_class_access_flags);
     }
 }
Ejemplo n.º 7
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 2 + 4 + code.Length + 2 + 2));
     bes.WriteUInt16(max_stack);
     bes.WriteUInt16(max_locals);
     bes.WriteUInt32((uint)code.Length);
     for (int i = 0; i < code.Length; i++)
     {
         bes.WriteByte(code[i]);
     }
     bes.WriteUInt16(0);             // no exceptions
     bes.WriteUInt16(0);             // no attributes
 }
Ejemplo n.º 8
0
 internal void WriteImpl(BigEndianStream bes)
 {
     bes.WriteUInt16(count);
     foreach (byte b in mem.ToArray())
     {
         bes.WriteByte(b);
     }
 }
Ejemplo n.º 9
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     if (flags == null || names == null || flags.Length != names.Length)
     {
         // write a malformed MethodParameters attribute
         bes.WriteUInt32(0);
         return;
     }
     bes.WriteUInt32((uint)(1 + names.Length * 4));
     bes.WriteByte((byte)names.Length);
     for (int i = 0; i < names.Length; i++)
     {
         bes.WriteUInt16(names[i]);
         bes.WriteUInt16(flags[i]);
     }
 }
Ejemplo n.º 10
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(mem.Length + 2));
     bes.WriteUInt16(count);
     foreach (byte b in mem.ToArray())
     {
         bes.WriteByte(b);
     }
 }
Ejemplo n.º 11
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.Class);
     bes.WriteUInt16(name_index);
 }
Ejemplo n.º 12
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.Methodref);
     bes.WriteUInt16(class_index);
     bes.WriteUInt16(name_and_type_index);
 }
Ejemplo n.º 13
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 2 * classes.Count));
     bes.WriteUInt16((ushort)classes.Count);
     foreach (ushort idx in classes)
     {
         bes.WriteUInt16(idx);
     }
 }
Ejemplo n.º 14
0
        public void Write(Stream stream)
        {
            BigEndianStream bes = new BigEndianStream(stream);

            bes.WriteUInt32(0xCAFEBABE);
            bes.WriteUInt16(minorVersion);
            bes.WriteUInt16(majorVersion);
            bes.WriteUInt16((ushort)cplist.Count);
            foreach (ConstantPoolItem cpi in cplist)
            {
                if (cpi != null)
                {
                    cpi.Write(bes);
                }
            }
            bes.WriteUInt16((ushort)access_flags);
            bes.WriteUInt16(this_class);
            bes.WriteUInt16(super_class);
            // interfaces count
            bes.WriteUInt16((ushort)interfaces.Count);
            for (int i = 0; i < interfaces.Count; i++)
            {
                bes.WriteUInt16(interfaces[i]);
            }
            // fields count
            bes.WriteUInt16((ushort)fields.Count);
            for (int i = 0; i < fields.Count; i++)
            {
                fields[i].Write(bes);
            }
            // methods count
            bes.WriteUInt16((ushort)methods.Count);
            for (int i = 0; i < methods.Count; i++)
            {
                methods[i].Write(bes);
            }
            // attributes count
            bes.WriteUInt16((ushort)attribs.Count);
            for (int i = 0; i < attribs.Count; i++)
            {
                attribs[i].Write(bes);
            }
        }
Ejemplo n.º 15
0
 private static void WriteAnnotationElementValue(ClassFileWriter classFile, BigEndianStream bes, CustomAttributeTypedArgument value)
 {
     if (value.ArgumentType == Types.Boolean)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)value.Value ? 1 : 0));
     }
     else if (value.ArgumentType == Types.Byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)value.Value));
     }
     else if (value.ArgumentType == Types.Char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)value.Value));
     }
     else if (value.ArgumentType == Types.Int16)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)value.Value));
     }
     else if (value.ArgumentType == Types.Int32)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)value.Value));
     }
     else if (value.ArgumentType == Types.Single)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)value.Value));
     }
     else if (value.ArgumentType == Types.Int64)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)value.Value));
     }
     else if (value.ArgumentType == Types.Double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)value.Value));
     }
     else if (value.ArgumentType == Types.String)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)value.Value));
     }
     else if (value.ArgumentType == Types.Object.MakeArrayType())
     {
         CustomAttributeTypedArgument[] array = (CustomAttributeTypedArgument[])value.Value;
         byte type = (byte)array[0].Value;
         if (type == AnnotationDefaultAttribute.TAG_ARRAY)
         {
             bes.WriteByte((byte)'[');
             bes.WriteUInt16((ushort)(array.Length - 1));
             for (int i = 1; i < array.Length; i++)
             {
                 WriteAnnotationElementValue(classFile, bes, array[i]);
             }
         }
         else if (type == AnnotationDefaultAttribute.TAG_CLASS)
         {
             bes.WriteByte((byte)'c');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ENUM)
         {
             bes.WriteByte((byte)'e');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16(classFile.AddUtf8((string)array[2].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ANNOTATION)
         {
             bes.WriteByte((byte)'@');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16((ushort)((array.Length - 2) / 2));
             for (int i = 2; i < array.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)array[i].Value));
                 WriteAnnotationElementValue(classFile, bes, array[i + 1]);
             }
         }
         else
         {
             Warning("Warning: incorrect annotation default element tag: " + type);
         }
     }
     else
     {
         Warning("Warning: incorrect annotation default element type: " + value.ArgumentType);
     }
 }
Ejemplo n.º 16
0
 internal void WriteImpl(BigEndianStream bes)
 {
     bes.WriteUInt16(count);
     foreach (byte b in mem.ToArray())
     {
         bes.WriteByte(b);
     }
 }
		public override void Write(BigEndianStream bes)
		{
			base.Write(bes);
			if (flags == null || names == null || flags.Length != names.Length)
			{
				// write a malformed MethodParameters attribute
				bes.WriteUInt32(0);
				return;
			}
			bes.WriteUInt32((uint)(1 + names.Length * 4));
			bes.WriteByte((byte)names.Length);
			for (int i = 0; i < names.Length; i++)
			{
				bes.WriteUInt16(names[i]);
				bes.WriteUInt16(flags[i]);
			}
		}
Ejemplo n.º 18
0
 public virtual void Write(BigEndianStream bes)
 {
     bes.WriteUInt16(name_index);
 }
Ejemplo n.º 19
0
 public void Write(BigEndianStream bes)
 {
     bes.WriteUInt16((ushort)access_flags);
     bes.WriteUInt16(name_index);
     bes.WriteUInt16(descriptor_index);
     bes.WriteUInt16((ushort)attribs.Count);
     for (int i = 0; i < attribs.Count; i++)
     {
         attribs[i].Write(bes);
     }
 }
Ejemplo n.º 20
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(1 + names.Length * 4));
     bes.WriteByte((byte)names.Length);
     foreach (ushort idx in names)
     {
         bes.WriteUInt16(idx);
         bes.WriteUInt16(0);
     }
 }
Ejemplo n.º 21
0
 public void Write(Stream stream)
 {
     BigEndianStream bes = new BigEndianStream(stream);
     bes.WriteUInt32(0xCAFEBABE);
     bes.WriteUInt16(minorVersion);
     bes.WriteUInt16(majorVersion);
     bes.WriteUInt16((ushort)cplist.Count);
     foreach (ConstantPoolItem cpi in cplist)
     {
         if (cpi != null)
         {
             cpi.Write(bes);
         }
     }
     bes.WriteUInt16((ushort)access_flags);
     bes.WriteUInt16(this_class);
     bes.WriteUInt16(super_class);
     // interfaces count
     bes.WriteUInt16((ushort)interfaces.Count);
     for (int i = 0; i < interfaces.Count; i++)
     {
         bes.WriteUInt16(interfaces[i]);
     }
     // fields count
     bes.WriteUInt16((ushort)fields.Count);
     for (int i = 0; i < fields.Count; i++)
     {
         fields[i].Write(bes);
     }
     // methods count
     bes.WriteUInt16((ushort)methods.Count);
     for (int i = 0; i < methods.Count; i++)
     {
         methods[i].Write(bes);
     }
     // attributes count
     bes.WriteUInt16((ushort)attribs.Count);
     for (int i = 0; i < attribs.Count; i++)
     {
         attribs[i].Write(bes);
     }
 }
Ejemplo n.º 22
0
 public virtual void Write(BigEndianStream bes)
 {
     bes.WriteUInt16(name_index);
 }
Ejemplo n.º 23
0
 private void WriteElementValue(BigEndianStream bes, object val)
 {
     if (val is object[])
     {
         object[] arr = (object[])val;
         if (AnnotationDefaultAttribute.TAG_ENUM.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ENUM);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16(classFile.AddUtf8((string)arr[2]));
         }
         else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY);
             bes.WriteUInt16((ushort)(arr.Length - 1));
             for (int i = 1; i < arr.Length; i++)
             {
                 WriteElementValue(bes, arr[i]);
             }
         }
         else if (AnnotationDefaultAttribute.TAG_CLASS.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_CLASS);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
         }
         else if (AnnotationDefaultAttribute.TAG_ANNOTATION.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ANNOTATION);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16((ushort)((arr.Length - 2) / 2));
             for (int i = 2; i < arr.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)arr[i]));
                 WriteElementValue(bes, arr[i + 1]);
             }
         }
     }
     else if (val is bool)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)val ? 1 : 0));
     }
     else if (val is byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)val));
     }
     else if (val is char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)val));
     }
     else if (val is short)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)val));
     }
     else if (val is int)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)val));
     }
     else if (val is long)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)val));
     }
     else if (val is float)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)val));
     }
     else if (val is double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)val));
     }
     else if (val is string)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)val));
     }
 }
Ejemplo n.º 24
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.NameAndType);
     bes.WriteUInt16(name_index);
     bes.WriteUInt16(descriptor_index);
 }
Ejemplo n.º 25
0
 private static void WriteAnnotationElementValue(ClassFileWriter classFile, BigEndianStream bes, CustomAttributeTypedArgument value)
 {
     if (value.ArgumentType == Types.Boolean)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)value.Value ? 1 : 0));
     }
     else if (value.ArgumentType == Types.Byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)value.Value));
     }
     else if (value.ArgumentType == Types.Char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)value.Value));
     }
     else if (value.ArgumentType == Types.Int16)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)value.Value));
     }
     else if (value.ArgumentType == Types.Int32)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)value.Value));
     }
     else if (value.ArgumentType == Types.Single)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)value.Value));
     }
     else if (value.ArgumentType == Types.Int64)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)value.Value));
     }
     else if (value.ArgumentType == Types.Double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)value.Value));
     }
     else if (value.ArgumentType == Types.String)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)value.Value));
     }
     else if (value.ArgumentType == Types.Object.MakeArrayType())
     {
         CustomAttributeTypedArgument[] array = (CustomAttributeTypedArgument[])value.Value;
         byte type = (byte)array[0].Value;
         if (type == AnnotationDefaultAttribute.TAG_ARRAY)
         {
             bes.WriteByte((byte)'[');
             bes.WriteUInt16((ushort)(array.Length - 1));
             for (int i = 1; i < array.Length; i++)
             {
                 WriteAnnotationElementValue(classFile, bes, array[i]);
             }
         }
         else if (type == AnnotationDefaultAttribute.TAG_CLASS)
         {
             bes.WriteByte((byte)'c');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ENUM)
         {
             bes.WriteByte((byte)'e');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16(classFile.AddUtf8((string)array[2].Value));
         }
         else if (type == AnnotationDefaultAttribute.TAG_ANNOTATION)
         {
             bes.WriteByte((byte)'@');
             bes.WriteUInt16(classFile.AddUtf8((string)array[1].Value));
             bes.WriteUInt16((ushort)((array.Length - 2) / 2));
             for (int i = 2; i < array.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)array[i].Value));
                 WriteAnnotationElementValue(classFile, bes, array[i + 1]);
             }
         }
         else
         {
             Warning("Warning: incorrect annotation default element tag: " + type);
         }
     }
     else
     {
         Warning("Warning: incorrect annotation default element type: " + value.ArgumentType);
     }
 }
Ejemplo n.º 26
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.String);
     bes.WriteUInt16(string_index);
 }
		public override void Write(BigEndianStream bes)
		{
			base.Write(bes);
			bes.WriteUInt32((uint)(mem.Length + 2));
			bes.WriteUInt16(count);
			foreach (byte b in mem.ToArray())
			{
				bes.WriteByte(b);
			}
		}
Ejemplo n.º 28
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32(2);
     bes.WriteUInt16(string_index);
 }
Ejemplo n.º 29
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32(2);
     bes.WriteUInt16(constant_index);
 }
Ejemplo n.º 30
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 2 + 4 + code.Length + 2 + 2));
     bes.WriteUInt16(max_stack);
     bes.WriteUInt16(max_locals);
     bes.WriteUInt32((uint)code.Length);
     for (int i = 0; i < code.Length; i++)
     {
         bes.WriteByte(code[i]);
     }
     bes.WriteUInt16(0);	// no exceptions
     bes.WriteUInt16(0); // no attributes
 }
Ejemplo n.º 31
0
 public override void Write(BigEndianStream bes)
 {
     base.Write(bes);
     bes.WriteUInt32((uint)(2 + 8 * classes.Count));
     bes.WriteUInt16((ushort)classes.Count);
     foreach (Item i in classes)
     {
         bes.WriteUInt16(i.inner_class_info_index);
         bes.WriteUInt16(i.outer_class_info_index);
         bes.WriteUInt16(i.inner_name_index);
         bes.WriteUInt16(i.inner_class_access_flags);
     }
 }
Ejemplo n.º 32
0
 private void WriteElementValue(BigEndianStream bes, object val)
 {
     if (val is object[])
     {
         object[] arr = (object[])val;
         if (AnnotationDefaultAttribute.TAG_ENUM.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ENUM);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16(classFile.AddUtf8((string)arr[2]));
         }
         else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY);
             bes.WriteUInt16((ushort)(arr.Length - 1));
             for (int i = 1; i < arr.Length; i++)
             {
                 WriteElementValue(bes, arr[i]);
             }
         }
         else if (AnnotationDefaultAttribute.TAG_CLASS.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_CLASS);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
         }
         else if (AnnotationDefaultAttribute.TAG_ANNOTATION.Equals(arr[0]))
         {
             bes.WriteByte(AnnotationDefaultAttribute.TAG_ANNOTATION);
             bes.WriteUInt16(classFile.AddUtf8(DecodeTypeName((string)arr[1])));
             bes.WriteUInt16((ushort)((arr.Length - 2) / 2));
             for (int i = 2; i < arr.Length; i += 2)
             {
                 bes.WriteUInt16(classFile.AddUtf8((string)arr[i]));
                 WriteElementValue(bes, arr[i + 1]);
             }
         }
     }
     else if (val is bool)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt((bool)val ? 1 : 0));
     }
     else if (val is byte)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt((byte)val));
     }
     else if (val is char)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt((char)val));
     }
     else if (val is short)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt((short)val));
     }
     else if (val is int)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt((int)val));
     }
     else if (val is long)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong((long)val));
     }
     else if (val is float)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat((float)val));
     }
     else if (val is double)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble((double)val));
     }
     else if (val is string)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8((string)val));
     }
 }
Ejemplo n.º 33
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.Class);
     bes.WriteUInt16(name_index);
 }
Ejemplo n.º 34
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.Methodref);
     bes.WriteUInt16(class_index);
     bes.WriteUInt16(name_and_type_index);
 }
Ejemplo n.º 35
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.NameAndType);
     bes.WriteUInt16(name_index);
     bes.WriteUInt16(descriptor_index);
 }
Ejemplo n.º 36
0
 private static byte[] GetAnnotationDefault(ClassFileWriter classFile, TypeWrapper type)
 {
     MemoryStream mem = new MemoryStream();
     BigEndianStream bes = new BigEndianStream(mem);
     if (type == PrimitiveTypeWrapper.BOOLEAN)
     {
         bes.WriteByte((byte)'Z');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.BYTE)
     {
         bes.WriteByte((byte)'B');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.CHAR)
     {
         bes.WriteByte((byte)'C');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.SHORT)
     {
         bes.WriteByte((byte)'S');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.INT)
     {
         bes.WriteByte((byte)'I');
         bes.WriteUInt16(classFile.AddInt(0));
     }
     else if (type == PrimitiveTypeWrapper.FLOAT)
     {
         bes.WriteByte((byte)'F');
         bes.WriteUInt16(classFile.AddFloat(0));
     }
     else if (type == PrimitiveTypeWrapper.LONG)
     {
         bes.WriteByte((byte)'J');
         bes.WriteUInt16(classFile.AddLong(0));
     }
     else if (type == PrimitiveTypeWrapper.DOUBLE)
     {
         bes.WriteByte((byte)'D');
         bes.WriteUInt16(classFile.AddDouble(0));
     }
     else if (type == CoreClasses.java.lang.String.Wrapper)
     {
         bes.WriteByte((byte)'s');
         bes.WriteUInt16(classFile.AddUtf8(""));
     }
     else if ((type.Modifiers & Modifiers.Enum) != 0)
     {
         bes.WriteByte((byte)'e');
         bes.WriteUInt16(classFile.AddUtf8("L" + type.Name.Replace('.', '/') + ";"));
         bes.WriteUInt16(classFile.AddUtf8("__unspecified"));
     }
     else if (type == CoreClasses.java.lang.Class.Wrapper)
     {
         bes.WriteByte((byte)'c');
         bes.WriteUInt16(classFile.AddUtf8("Likvm/internal/__unspecified;"));
     }
     else if (type.IsArray)
     {
         bes.WriteByte((byte)'[');
         bes.WriteUInt16(0);
     }
     else
     {
         throw new InvalidOperationException();
     }
     return mem.ToArray();
 }
Ejemplo n.º 37
0
 public override void Write(BigEndianStream bes)
 {
     bes.WriteByte((byte)Constant.String);
     bes.WriteUInt16(string_index);
 }
Ejemplo n.º 38
0
    private static byte[] GetAnnotationDefault(IKVM.StubGen.ClassFileWriter classFile, TypeWrapper type)
    {
        MemoryStream mem = new MemoryStream();

        IKVM.StubGen.BigEndianStream bes = new IKVM.StubGen.BigEndianStream(mem);
        if (type == PrimitiveTypeWrapper.BOOLEAN)
        {
            bes.WriteByte((byte)'Z');
            bes.WriteUInt16(0);
        }
        else if (type == PrimitiveTypeWrapper.BYTE)
        {
            bes.WriteByte((byte)'B');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.CHAR)
        {
            bes.WriteByte((byte)'C');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.SHORT)
        {
            bes.WriteByte((byte)'S');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.INT)
        {
            bes.WriteByte((byte)'I');
            bes.WriteUInt16(classFile.AddInt(0));
        }
        else if (type == PrimitiveTypeWrapper.FLOAT)
        {
            bes.WriteByte((byte)'F');
            bes.WriteUInt16(classFile.AddFloat(0));
        }
        else if (type == PrimitiveTypeWrapper.LONG)
        {
            bes.WriteByte((byte)'J');
            bes.WriteUInt16(classFile.AddLong(0));
        }
        else if (type == PrimitiveTypeWrapper.DOUBLE)
        {
            bes.WriteByte((byte)'D');
            bes.WriteUInt16(classFile.AddDouble(0));
        }
        else if (type == CoreClasses.java.lang.String.Wrapper)
        {
            bes.WriteByte((byte)'s');
            bes.WriteUInt16(classFile.AddUtf8(""));
        }
        else if ((type.Modifiers & Modifiers.Enum) != 0)
        {
            bes.WriteByte((byte)'e');
            bes.WriteUInt16(classFile.AddUtf8("L" + type.Name.Replace('.', '/') + ";"));
            bes.WriteUInt16(classFile.AddUtf8("__unspecified"));
        }
        else if (type == CoreClasses.java.lang.Class.Wrapper)
        {
            bes.WriteByte((byte)'c');
            bes.WriteUInt16(classFile.AddUtf8("Likvm/internal/__unspecified;"));
        }
        else if (type.IsArray)
        {
            bes.WriteByte((byte)'[');
            bes.WriteUInt16(0);
        }
        else
        {
            throw new InvalidOperationException();
        }
        return(mem.ToArray());
    }
		private void WriteElementValue(BigEndianStream bes, object val)
		{
			if (val is object[])
			{
				object[] arr = (object[])val;
				if (AnnotationDefaultAttribute.TAG_ENUM.Equals(arr[0]))
				{
					bes.WriteByte(AnnotationDefaultAttribute.TAG_ENUM);
					bes.WriteUInt16(classFile.AddUtf8((string)arr[1]));
					bes.WriteUInt16(classFile.AddUtf8((string)arr[2]));
					return;
				}
				else if (AnnotationDefaultAttribute.TAG_ARRAY.Equals(arr[0]))
				{
					bes.WriteByte(AnnotationDefaultAttribute.TAG_ARRAY);
					object[] elemarr = (object[])arr[1];
					bes.WriteUInt16((ushort)elemarr.Length);
					foreach (object elem in elemarr)
					{
						WriteElementValue(bes, elem);
					}
					return;
				}
			}
			throw new NotImplementedException(val.GetType().FullName);
		}