示例#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;

            }
        }
 public void Complete(Substitution s)
 {
     for (int i=0; i<Substitutions.Length; i++)
     {
         if (Substitutions[i].Equals(s))
         {
             Substitutions[i].completed = true;
             return;
         }
     }
 }
        public void addSubstitution(Substitution s)
        {
            for (int i=0; i<Substitutions.Length; i++)
            {
                if (Substitutions[i].completed)
                {
                    Substitutions[i] = s;
                    return;
                }
            }

            Substitution[] copy = Substitutions;
            Substitutions = new Substitution[Substitutions.Length + 1];
            Substitutions.WriteSlice(0, copy);
            Substitutions[Substitutions.Length - 1] = s;
        }
 public UnsubstitutedBytes(byte[] bytes, Substitution[] substitutions)
 {
     Bytes = bytes;
     Substitutions = substitutions;
 }
 public void Complete(Substitution sub)
 {
     Substitutions.Remove(sub);
 }
 public void addSubstitution(Substitution s)
 {
     Substitutions.Add(s);
 }