Beispiel #1
0
        public static MemoryLocation ParseMemoryLocation(string str)
        {
            int bytes = 4;

            // remove whitespace and quotes
            str = str.Replace(" ", "").Replace("\n", "").Replace("\t", "").Replace("\"", "").Replace("'", "");
            // parse the amount of bytes for the memory location
            if (str.Contains("[") && str.Contains("]"))
            {
                int    start  = str.IndexOf('[');
                int    end    = str.IndexOf(']');
                string number = str.Substring(start + 1, end - start - 1);
                if (!int.TryParse(number, out bytes))
                {
                    return(null);
                }
                if (bytes != 1 && bytes != 2 && bytes != 4 && bytes != 8)
                {
                    return(null);
                }
                str = str.Substring(end + 1);
            }
            string[] splits = str.Split('+');
            if (splits.Length != 2)
            {
                return(null);
            }
            MemoryLocation location = new MemoryLocation();

            location.moduleName = splits[0].ToLower();
            string[] jump_splits = splits[1].Split('>');
            if (!TryParseHexNumber(jump_splits[0], out location.moduleOffset))
            {
                return(null);
            }
            // parse jumps
            for (int i = 1; i < jump_splits.Length; i++)
            {
                long jump_value;
                if (!TryParseHexNumber(jump_splits[i], out jump_value))
                {
                    return(null);
                }
                location.jumps.Add(jump_value);
            }
            location.bytes = bytes;
            return(location);
        }
Beispiel #2
0
        private static Tuple <Dictionary <string, UInt32>, Dictionary <string, MemoryLocation> > ParseAddresses()
        {
            var addresses = new Dictionary <string, UInt32>();
            var paths     = new Dictionary <string, MemoryLocation>();

            var results = new Tuple <Dictionary <string, uint>, Dictionary <string, MemoryLocation> >(addresses, paths);

            MemorySettings.Clear();
            using (StreamReader reader = new StreamReader(Constants.MemoryAddresses))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line.Contains("="))
                    {
                        string[] split = line.Split('=');

                        string         key      = split[0].Trim().ToLower();
                        UInt32         value    = 0;
                        MemoryLocation location = MemoryLocation.ParseMemoryLocation(split[1]);
                        if (location != null)
                        {
                            paths.Add(key, location);
                        }
                        else if (!key.Contains("noparse") && UInt32.TryParse(split[1].Replace("0x", ""), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
                        {
                            addresses.Add(key, value);
                        }
                        else
                        {
                            key = key.Replace("noparse", "");
                            if (!MemorySettings.ContainsKey(key))
                            {
                                MemorySettings.Add(key, split[1]);
                            }
                        }
                    }
                }
            }
            return(results);
        }