Esempio n. 1
0
        private Layout.IChunkInfo ParseLine(string text)
        {
            // returns a ChunkEntry object from a line in the imp file

            // May 2014 - oh boy more uncommented code. At least this is relatively simple
            // time to rewrite and comment!

            // do some simple checks to make sure the line is valid
            if (!text.Contains("[") || !text.Contains("]") ||
                !(text.Contains("-") || text.Contains("+")) ||
                text.Length < 6)
            {
                throw new FormatException("Entry not properly formatted");
            }

            //get the text between the [] brackets, which should be the address and any arguments
            string offsets = dumplib.Text.Table.GetLabel(text);

            string[] args = null;

            // a comma delimits the address and all args, so if there's a comma in the text between []...
            if (offsets.Contains(","))
            {
                //... then split by args, set the first result to offsets and the rest to the args array
                string[] temp = offsets.Split(',');
                args    = new string[temp.Length - 1];
                offsets = temp[0];
                //Buffer.BlockCopy(temp, 1, args, 0, args.Length);
                Array.Copy(temp, 1, args, 0, args.Length);
            }

            // the offset string can have a - or + to delimit between the two numbers
            long first; int second;

            if (offsets.IndexOf('-') > 0)
            {
                string[] offsetsplit = offsets.Split('-');
                first  = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber);
                second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber);
                if (second < first)
                {
                    throw new ArgumentOutOfRangeException("Ending offset cannot be less than start offset");
                }
                second = (second - (int)first) + 1;
            }
            else if (offsets.IndexOf('+') > 0)
            {
                string[] offsetsplit = offsets.Split('+');
                first  = long.Parse(offsetsplit[0], System.Globalization.NumberStyles.HexNumber);
                second = int.Parse(offsetsplit[1], System.Globalization.NumberStyles.HexNumber);
                if (second < 1)
                {
                    throw new ArgumentOutOfRangeException("Length cannot be less than 1");
                }
            }
            else
            {
                throw new FormatException("Offsets incorrectly formatted");
            }

            string desc = text.Substring(text.IndexOf(']') + 1);

            //if (!ChunkTypes.ContainsKey(text.Substring(0, 1).ToUpper())) throw new ArgumentException("Specified chunk type not found");
            object[] thisinfo = new object[2];
            thisinfo[0] = new Range(first, second);
            thisinfo[1] = desc;
            IChunkInfo _out = Activator.CreateInstance(chunktypes[text.Substring(0, 1).ToUpper()], thisinfo) as IChunkInfo;

            if (args != null && args.Length > 0)
            {
                _out.ParseArgs(args);
            }

            return(_out);
        }