Esempio n. 1
0
        public void Write(BinaryWriter Writer, ConstantPool Pool)
        {
            Writer.WriteBE(Pool.AddConstant(new Java.Constants.Utf8(Type)));
            Writer.WriteBE((ushort)ValuePairs.Count);

            foreach (KeyValuePair <string, ElementValue> Element in ValuePairs)
            {
                Writer.WriteBE(Pool.AddConstant(new Java.Constants.Utf8(Element.Key)));
                Element.Value.Write(Writer, Pool);
            }
        }
Esempio n. 2
0
        public void Write(BinaryWriter Writer, ConstantPool Pool)
        {
            Writer.WriteBE((ushort)AccessFlags);
            Writer.WriteBE(Pool.AddConstant(new Constants.Utf8(Name)));
            Writer.WriteBE(Pool.AddConstant(new Constants.Utf8(Descriptor)));

            Writer.WriteBE((ushort)Attributes.Count);
            foreach (Attribute Attr in Attributes)
            {
                Attr.Write(Writer, Pool);
            }
        }
Esempio n. 3
0
        public void Write(BinaryWriter Writer, ConstantPool Pool)
        {
            Writer.WriteBE((ushort)AccessFlags);
            Writer.WriteBE(Pool.AddConstant(new Constants.Utf8(Name)));
            Writer.WriteBE(Pool.AddConstant(new Constants.Utf8(Descriptor)));

            Writer.WriteBE((ushort)Attributes.Count);
            foreach (Attribute Attribute in Attributes)
            {
                if (Attribute.Name == "Code")
                {
                    Java.Attributes.Code CodeAttr = (Java.Attributes.Code)Attribute;
                    CodeAttr.MaxLocals = Math.Max(CalculateParametesSlots(), CodeAttr.MaxLocals);
                }

                Attribute.Write(Writer, Pool);
            }
        }
Esempio n. 4
0
        private void LinkPass1(Java.ConstantPool pool)
        {
            int offset = StartOffset;

            bool lastWide = false;

            for (int i = 0; i < outputCode.Count; i++)
            {
                JavaInstruction instr = outputCode[i];
                outputCodeOffsets.Add(instr, offset);

                object lastOperand = instr.Operand;
                if (instr.Operand is Java.Constant)
                {
                    instr.Operand = pool.AddConstant((Java.Constant)instr.Operand);
                }
                else if (instr.Operand is MultianewarrayOperand)
                {
                    MultianewarrayOperand operand = (MultianewarrayOperand)instr.Operand;
                    instr.Operand = pool.AddConstant(operand.ClassOperand) | (operand.DimensionsOperand << 16);
                }

                if (instr.Opcode == Java.OpCodes.ldc)
                {
                    if (((ushort)instr.Operand) > byte.MaxValue)
                    {
                        instr.Opcode = Java.OpCodes.ldc_w;
                    }
                }

                if (instr.Opcode == Java.OpCodes.invokeinterface)
                {
                    if (lastOperand is Java.Constants.MethodRef)
                    {
                        Java.Constants.MethodRef m = (Java.Constants.MethodRef)lastOperand;

                        lastOperand = new Java.Constants.InterfaceMethodRef(m.Class, m.Name, m.Descriptor);
                    }

                    byte   argsCount  = CalculateInterfaceCallArgsCount(((Java.Constants.InterfaceMethodRef)lastOperand).Descriptor);
                    ushort constIndex = (ushort)instr.Operand;
                    instr.Operand = (uint)(constIndex | ((argsCount + 1) << 24));
                }

                int size = Java.ByteCode.JavaInstructions[instr.Opcode].Size;
                if ((size == -1) && (instr.Opcode == Java.OpCodes.lookupswitch))
                {
                    LookupswitchOperand op = (LookupswitchOperand)lastOperand;
                    instr.Operand = op;

                    int paddingLendth = (4 - ((offset + 1) % 4)) % 4;

                    size = 1                      //opcode
                           + paddingLendth        //padding
                           + 4                    //default
                           + 4                    //npairs
                           + op.Pairs.Length * 8; //pairs count * pairs size (8 = 4 + 4)
                }

                if (lastWide)
                {
                    size     = (size - 1) * 2 + 1;
                    lastWide = false;
                }

                offset += size;

                if (instr.Opcode == Java.OpCodes.wide)
                {
                    lastWide = true;
                }
            }
        }
 public override void Write(System.IO.BinaryWriter Writer, ConstantPool Pool)
 {
     base.Write(Writer, Pool);
     Writer.WriteBE(Pool.AddConstant(new Java.Constants.Integer(Value)));
 }
 public override void Write(System.IO.BinaryWriter Writer, ConstantPool Pool)
 {
     base.Write(Writer, Pool);
     Writer.WriteBE(Pool.AddConstant(new Java.Constants.Utf8(Class)));
 }
Esempio n. 7
0
 public virtual void Write(BinaryWriter Writer, ConstantPool Pool)
 {
     Writer.WriteBE(Pool.AddConstant(new Constants.Utf8(Name)));
 }