示例#1
0
        // Token: 0x060001CF RID: 463 RVA: 0x0000F354 File Offset: 0x0000D554
        public void ParsePackerString(string str, out Packer packer, out Dictionary <string, string> packerParams)
        {
            packer       = null;
            packerParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
            if (str == null)
            {
                return;
            }
            this.str   = str;
            this.index = 0;
            ObfAttrParser.ParseState state  = ObfAttrParser.ParseState.ReadItemName;
            StringBuilder            buffer = new StringBuilder();

            new ProtectionSettings();
            while (state != ObfAttrParser.ParseState.End)
            {
                switch (state)
                {
                case ObfAttrParser.ParseState.ReadItemName:
                {
                    this.ReadId(buffer);
                    string packerId = buffer.ToString();
                    if (!this.items.Contains(packerId))
                    {
                        throw new KeyNotFoundException("Cannot find packer with id '" + packerId + "'.");
                    }
                    packer        = (Packer)this.items[packerId];
                    buffer.Length = 0;
                    if (this.IsEnd() || this.Peek() == ';')
                    {
                        state = ObfAttrParser.ParseState.EndItem;
                    }
                    else
                    {
                        if (this.Peek() != '(')
                        {
                            throw new ArgumentException("Unexpected character in ReadItemName state at " + this.index + ".");
                        }
                        this.Next();
                        state = ObfAttrParser.ParseState.ReadParam;
                    }
                    break;
                }

                case ObfAttrParser.ParseState.ReadParam:
                {
                    if (!this.ReadId(buffer))
                    {
                        throw new ArgumentException("Unexpected end of string in ReadParam state.");
                    }
                    string paramName = buffer.ToString();
                    buffer.Length = 0;
                    this.Expect('=');
                    if (!this.ReadId(buffer))
                    {
                        throw new ArgumentException("Unexpected end of string in ReadParam state.");
                    }
                    string paramValue = buffer.ToString();
                    buffer.Length = 0;
                    packerParams.Add(paramName, paramValue);
                    if (this.Peek() == ',')
                    {
                        this.Next();
                        state = ObfAttrParser.ParseState.ReadParam;
                    }
                    else
                    {
                        if (this.Peek() != ')')
                        {
                            throw new ArgumentException("Unexpected character in ReadParam state at " + this.index + ".");
                        }
                        this.Next();
                        state = ObfAttrParser.ParseState.EndItem;
                    }
                    break;
                }

                case ObfAttrParser.ParseState.EndItem:
                    if (this.IsEnd())
                    {
                        state = ObfAttrParser.ParseState.End;
                    }
                    else
                    {
                        this.Expect(';');
                        if (!this.IsEnd())
                        {
                            throw new ArgumentException("Unexpected character in EndItem state at " + this.index + ".");
                        }
                        state = ObfAttrParser.ParseState.End;
                    }
                    break;
                }
            }
        }
示例#2
0
        // Token: 0x060001CE RID: 462 RVA: 0x0000EFA0 File Offset: 0x0000D1A0
        public void ParseProtectionString(ProtectionSettings settings, string str)
        {
            if (str == null)
            {
                return;
            }
            this.str   = str;
            this.index = 0;
            ObfAttrParser.ParseState state  = ObfAttrParser.ParseState.Init;
            StringBuilder            buffer = new StringBuilder();
            bool   protAct = true;
            string protId  = null;
            Dictionary <string, string> protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            while (state != ObfAttrParser.ParseState.End)
            {
                switch (state)
                {
                case ObfAttrParser.ParseState.Init:
                    this.ReadId(buffer);
                    if (buffer.ToString().Equals("preset", StringComparison.OrdinalIgnoreCase))
                    {
                        if (this.IsEnd())
                        {
                            throw new ArgumentException("Unexpected end of string in Init state.");
                        }
                        this.Expect('(');
                        buffer.Length = 0;
                        state         = ObfAttrParser.ParseState.ReadPreset;
                    }
                    else if (buffer.Length == 0)
                    {
                        if (this.IsEnd())
                        {
                            throw new ArgumentException("Unexpected end of string in Init state.");
                        }
                        state = ObfAttrParser.ParseState.ReadItemName;
                    }
                    else
                    {
                        protAct = true;
                        state   = ObfAttrParser.ParseState.ProcessItemName;
                    }
                    break;

                case ObfAttrParser.ParseState.ReadPreset:
                {
                    if (!this.ReadId(buffer))
                    {
                        throw new ArgumentException("Unexpected end of string in ReadPreset state.");
                    }
                    this.Expect(')');
                    ProtectionPreset preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), buffer.ToString(), true);
                    foreach (Protection item in from prot in this.items.Values.OfType <Protection>()
                             where prot.Preset <= preset
                             select prot)
                    {
                        if (settings != null && !settings.ContainsKey(item))
                        {
                            settings.Add(item, new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase));
                        }
                    }
                    buffer.Length = 0;
                    if (this.IsEnd())
                    {
                        state = ObfAttrParser.ParseState.End;
                    }
                    else
                    {
                        this.Expect(';');
                        if (this.IsEnd())
                        {
                            state = ObfAttrParser.ParseState.End;
                        }
                        else
                        {
                            state = ObfAttrParser.ParseState.ReadItemName;
                        }
                    }
                    break;
                }

                case ObfAttrParser.ParseState.ReadItemName:
                    protAct = true;
                    if (this.Peek() == '+')
                    {
                        protAct = true;
                        this.Next();
                    }
                    else if (this.Peek() == '-')
                    {
                        protAct = false;
                        this.Next();
                    }
                    this.ReadId(buffer);
                    state = ObfAttrParser.ParseState.ProcessItemName;
                    break;

                case ObfAttrParser.ParseState.ProcessItemName:
                    protId        = buffer.ToString();
                    buffer.Length = 0;
                    if (this.IsEnd() || this.Peek() == ';')
                    {
                        state = ObfAttrParser.ParseState.EndItem;
                    }
                    else
                    {
                        if (this.Peek() != '(')
                        {
                            throw new ArgumentException("Unexpected character in ProcessItemName state at " + this.index + ".");
                        }
                        if (!protAct)
                        {
                            throw new ArgumentException("No parameters is allowed when removing protection.");
                        }
                        this.Next();
                        state = ObfAttrParser.ParseState.ReadParam;
                    }
                    break;

                case ObfAttrParser.ParseState.ReadParam:
                {
                    if (!this.ReadId(buffer))
                    {
                        throw new ArgumentException("Unexpected end of string in ReadParam state.");
                    }
                    string paramName = buffer.ToString();
                    buffer.Length = 0;
                    this.Expect('=');
                    if (!((this.Peek() == '\'') ? this.ReadString(buffer) : this.ReadId(buffer)))
                    {
                        throw new ArgumentException("Unexpected end of string in ReadParam state.");
                    }
                    string paramValue = buffer.ToString();
                    buffer.Length = 0;
                    protParams.Add(paramName, paramValue);
                    if (this.Peek() == ',')
                    {
                        this.Next();
                        state = ObfAttrParser.ParseState.ReadParam;
                    }
                    else
                    {
                        if (this.Peek() != ')')
                        {
                            throw new ArgumentException("Unexpected character in ReadParam state at " + this.index + ".");
                        }
                        this.Next();
                        state = ObfAttrParser.ParseState.EndItem;
                    }
                    break;
                }

                case ObfAttrParser.ParseState.EndItem:
                    if (settings != null)
                    {
                        if (!this.items.Contains(protId))
                        {
                            throw new KeyNotFoundException("Cannot find protection with id '" + protId + "'.");
                        }
                        if (protAct)
                        {
                            settings[(Protection)this.items[protId]] = protParams;
                        }
                        else
                        {
                            settings.Remove((Protection)this.items[protId]);
                        }
                    }
                    protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                    if (this.IsEnd())
                    {
                        state = ObfAttrParser.ParseState.End;
                    }
                    else
                    {
                        this.Expect(';');
                        if (this.IsEnd())
                        {
                            state = ObfAttrParser.ParseState.End;
                        }
                        else
                        {
                            state = ObfAttrParser.ParseState.ReadItemName;
                        }
                    }
                    break;
                }
            }
        }