private static void WriteModifiers(BigEndianStream bes, TypeWrapper tw) { Modifiers mods = tw.ReflectiveModifiers & (Modifiers.Public | Modifiers.Final | Modifiers.Interface | Modifiers.Abstract); if ((mods & Modifiers.Interface) != 0) { mods &= ~Modifiers.Abstract; if (HasJavaMethods(tw)) { mods |= Modifiers.Abstract; } } bes.WriteUInt32((uint)mods); }
private static byte[] GetAnnotationDefault(IKVM.StubGen.ClassFileWriter classFile, CustomAttributeTypedArgument value) { MemoryStream mem = new MemoryStream(); IKVM.StubGen.BigEndianStream bes = new IKVM.StubGen.BigEndianStream(mem); try { WriteAnnotationElementValue(classFile, bes, value); } catch (InvalidCastException) { Console.Error.WriteLine("Warning: incorrect annotation default value"); } catch (IndexOutOfRangeException) { Console.Error.WriteLine("Warning: incorrect annotation default value"); } return(mem.ToArray()); }
internal static long Compute(TypeWrapper tw) { MemoryStream mem = new MemoryStream(); BigEndianStream bes = new BigEndianStream(mem); WriteClassName(bes, tw); WriteModifiers(bes, tw); WriteInterfaces(bes, tw); WriteFields(bes, tw); WriteStaticInitializer(bes, tw); WriteConstructors(bes, tw); WriteMethods(bes, tw); byte[] buf = sha1.ComputeHash(mem.ToArray()); long hash = 0; for (int i = 7; i >= 0; i--) { hash <<= 8; hash |= buf[i]; } return hash; }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Long); bes.WriteInt64(v); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.NameAndType); bes.WriteUInt16(name_index); bes.WriteUInt16(descriptor_index); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Class); bes.WriteUInt16(name_index); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Float); bes.WriteFloat(v); }
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()); }
public virtual void Write(BigEndianStream bes) { bes.WriteUInt16(name_index); }
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); } }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32(Length); WriteImpl(bes); }
public abstract void Write(BigEndianStream bes);
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)); } }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32(2); bes.WriteUInt16(string_index); }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32(0); }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)(buf.Length)); foreach (byte b in buf) { bes.WriteByte(b); } }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Methodref); bes.WriteUInt16(class_index); bes.WriteUInt16(name_and_type_index); }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32(2); bes.WriteUInt16(constant_index); }
private static byte[] GetAnnotationDefault(ClassFileWriter classFile, CustomAttributeTypedArgument value) { MemoryStream mem = new MemoryStream(); BigEndianStream bes = new BigEndianStream(mem); try { WriteAnnotationElementValue(classFile, bes, value); } catch (InvalidCastException) { Warning("Warning: incorrect annotation default value"); } catch (IndexOutOfRangeException) { Warning("Warning: incorrect annotation default value"); } return mem.ToArray(); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Utf8); bes.WriteUtf8(str); }
private static void WriteMethods(BigEndianStream bes, TypeWrapper tw) { List<MethodWrapper> list = new List<MethodWrapper>(); foreach (MethodWrapper mw in tw.GetMethods()) { if (mw.Name != StringConstants.INIT && !mw.IsHideFromReflection && !mw.IsPrivate) { list.Add(mw); } } list.Sort(delegate(MethodWrapper mw1, MethodWrapper mw2) { if (mw1.Name == mw2.Name) return String.CompareOrdinal(mw1.Signature, mw2.Signature); return String.CompareOrdinal(mw1.Name, mw2.Name); }); foreach (MethodWrapper mw in list) { Modifiers mods = mw.Modifiers & (Modifiers.Public | Modifiers.Private | Modifiers.Protected | Modifiers.Static | Modifiers.Final | Modifiers.Synchronized | Modifiers.Native | Modifiers.Abstract | Modifiers.Strictfp); bes.WriteUtf8(mw.Name); bes.WriteUInt32((uint)mods); bes.WriteUtf8(mw.Signature); } }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Integer); bes.WriteUInt32((uint)v); }
private static void WriteClassName(BigEndianStream bes, TypeWrapper tw) { bes.WriteUtf8(tw.Name); }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.Double); bes.WriteDouble(v); }
private static void WriteAnnotationElementValue(IKVM.StubGen.ClassFileWriter classFile, IKVM.StubGen.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 { Console.Error.WriteLine("Warning: incorrect annotation default element tag: " + type); } } else { Console.Error.WriteLine("Warning: incorrect annotation default element type: " + value.ArgumentType); } }
public override void Write(BigEndianStream bes) { bes.WriteByte((byte)Constant.String); bes.WriteUInt16(string_index); }
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); uint length = 1; foreach (RuntimeVisibleAnnotationsAttribute attr in parameters) { length += attr.Length; } bes.WriteUInt32(length); bes.WriteByte((byte)parameters.Count); foreach (RuntimeVisibleAnnotationsAttribute attr in parameters) { attr.WriteImpl(bes); } }
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(); }
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); } }
private static void WriteStaticInitializer(BigEndianStream bes, TypeWrapper tw) { Type type = tw.TypeAsTBD; if (!type.IsArray && type.TypeInitializer != null) { if (!AttributeHelper.IsHideFromJava(type.TypeInitializer)) { bes.WriteUtf8("<clinit>"); bes.WriteUInt32((uint)Modifiers.Static); bes.WriteUtf8("()V"); } } }
private static void WriteInterfaces(BigEndianStream bes, TypeWrapper tw) { TypeWrapper[] interfaces = (TypeWrapper[])tw.Interfaces.Clone(); Array.Sort(interfaces, delegate(TypeWrapper tw1, TypeWrapper tw2) { return String.CompareOrdinal(tw1.Name, tw2.Name); }); foreach (TypeWrapper iface in interfaces) { bes.WriteUtf8(iface.Name); } }
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); } }
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 }
private static void WriteFields(BigEndianStream bes, TypeWrapper tw) { List<FieldWrapper> list = new List<FieldWrapper>(); foreach (FieldWrapper fw in tw.GetFields()) { if (!fw.IsHideFromReflection) { list.Add(fw); } } list.Sort(delegate(FieldWrapper fw1, FieldWrapper fw2) { return String.CompareOrdinal(fw1.Name, fw2.Name); }); foreach (FieldWrapper fw in list) { Modifiers mods = fw.Modifiers & (Modifiers.Public | Modifiers.Private | Modifiers.Protected | Modifiers.Static | Modifiers.Final | Modifiers.Volatile | Modifiers.Transient); if (((mods & Modifiers.Private) == 0) || ((mods & (Modifiers.Static | Modifiers.Transient)) == 0)) { bes.WriteUtf8(fw.Name); bes.WriteUInt32((uint)mods); bes.WriteUtf8(fw.Signature.Replace('.', '/')); } } }
public override void Write(BigEndianStream bes) { base.Write(bes); bes.WriteUInt32((uint)data.Length); bes.WriteBytes(data); }