Пример #1
0
        /// <summary>
        /// Puts in a single substitution. This function takes the highest and last types of substitutions, and puts them where they belong.
        /// </summary>
        /// <param name="input">The bytest to which to sustitute</param>
        /// <param name="what">The substitution to put in</param>
        void Substitute(IUnsubstitutedBytes input, Substitution what)
        {
            switch (what.type)
            {
                case (substitutionType.FileSize):
                    input.WriteSlice(what.position, toBytes(input.Count));
                    break;
                case (substitutionType.Ramstart):
                    input.WriteSlice(what.position, toBytes(ramstart));
                    break;
                case (substitutionType.MagicNumber):
                    input.WriteSlice(what.position, new byte[] { 0x47, 0x6C, 0x75, 0x6C }); //Glul
                    break;
                case (substitutionType.DecodingTable):
                    input.WriteSlice(what.position, new byte[4]);
                    break;
                case (substitutionType.Version):
                    input.WriteSlice(what.position, new byte[] { 0x00, 0x03, 0x01, 0xFF });
                    break;
                case (substitutionType.maxMemory):
                    input.WriteSlice(what.position, toBytes(input.Count.RoundUp(256)));
                    break;
                case (substitutionType.StartFunction):
                    input.WriteSlice(what.position, toBytes(startFunctionDefinition));
                    break;
                case substitutionType.StackSize:
                    input.WriteSlice(what.position, toBytes(1024));
                    break;
                case substitutionType.WriterRef:
                    WriterComponent wrtcmp=null;
                    foreach (WriterComponent p in ExistingComponents)
                    {
                        if (p.getID() == what.data)
                        {
                            wrtcmp = p;
                            break;
                        }
                    }
                    if (wrtcmp != null)
                    {
                        input.WriteSlice(what.position, toBytes(wrtcmp.GetPosition()));
                    }
                    else
                    {
                        throw new Errors.IDMismatchException("ID " + what.data.ToString() + " refered to, but not set to any object");
                    }

                    break;
                case substitutionType.attrID:
                    bool sucess=false;
                    foreach (KeyValuePair<string, KindPrototype> p in cdtb.existingTypes)
                    {
                        KAttribute attribute = p.Value.getAttributeByID((int)what.data);
                        if (attribute != null)
                        {
                            input.WriteSlice(what.position, toBytes((int)attribute.pos));
                            Console.WriteLine("sucessuflly wrote attrID at " + what.position.ToString()+
                                " attr="+attribute.pos.ToString())
                                ;
                            sucess = true;
                        }
                    }
                    if (!sucess)
                    {
                        throw new Errors.IDMismatchException("No attribute with id " + what.data.ToString());
                    }
                    break;

            }
        }
Пример #2
0
 public void Combine(IUnsubstitutedBytes other, int position)
 {
     if (position+other.Count > Count)
     {
         resize(position + other.Count);
     }
     Bytes.WriteSlice(position, other.bytes.ToArray());
     List<Substitution> f = new List<Substitution>(substitutions);
     foreach (Substitution sub in other.substitutions)
     {
         Substitution l = sub;
         l.position += position;
         f.Add(l);
     }
     Substitutions = f.ToArray();
 }
Пример #3
0
        public void Combine(IUnsubstitutedBytes other, int position)
        {
            int index = 0;
            int sum;
            IEnumerator<byte> numerator = other.bytes.GetEnumerator();
            while (index < other.Count)
            {
                sum = index + position;
                if (sum > Count)
                {
                    Bytes.Add(0);
                }
                else if (sum == Count)
                {
                    numerator.MoveNext();
                    Bytes.Add(numerator.Current);
                    index += 1;
                }
                else
                {
                    numerator.MoveNext();
                    Bytes[sum] = numerator.Current;
                    index += 1;
                }
            }

            foreach (Substitution s in other.substitutions)
            {
                Substitutions.Add(s.moveTo(s.position + position));
            }
        }
Пример #4
0
 public void Combine(IUnsubstitutedBytes other)
 {
     Combine(other, Bytes.Length);
 }
Пример #5
0
 public void Combine(IUnsubstitutedBytes other)
 {
     int index=Bytes.Count;
     Bytes.AddRange(other.bytes);
     foreach (Substitution b in other.substitutions)
     {
         Substitutions.Add(b.moveTo(b.position + index));
     }
 }