コード例 #1
0
ファイル: plugin.cs プロジェクト: Nestor/TS3AudioBotPlugins
        public void Initialize(MainBot mainBot)
        {
            bot = mainBot;
            //var pluginPath = mainBot.ConfigManager.GetDataStruct<PluginManagerData>("PluginManager", true).PluginPath;
            var pluginPath = "Plugins";

            cfgfile = Path.Combine(pluginPath, $"{PluginInfo.Name}.cfg");
            try {
                if (File.Exists(cfgfile))
                {
                    var parser = new FileIniDataParser();
                    cfg = parser.ReadFile(cfgfile);
                    PluginLog(Log.Level.Debug, $"cfgfile = {cfgfile}");
                    if (cfg["Ignore"]["uids"].Contains(','))
                    {
                        whitelistUID = cfg["Ignore"]["uids"].Split(',').ToList();
                    }
                    else
                    {
                        whitelistUID.Add(cfg["Ignore"]["uids"]);
                    }
                    if (cfg["Ignore"]["sgids"].Contains(','))
                    {
                        var _whitelistSGID = cfg["Ignore"]["sgids"].Split(',');
                        foreach (var wsgid in _whitelistSGID)
                        {
                            whitelistSGID.Add(ServerGroupIdT.Parse(wsgid));
                        }
                    }
                    else
                    {
                        whitelistSGID.Add(ServerGroupIdT.Parse(cfg["Ignore"]["sgids"]));
                    }
                }
            } catch (Exception ex) {
                throw new Exception($"{PluginInfo.Name} Can't load \"{cfgfile}\"! Error:\n{ex}");
                cfg = new IniData();
                //while (!Setup()) { }
            }
            ispfile = Path.Combine(pluginPath, "ISPs.txt");
            PluginLog(Log.Level.Debug, $"ispfile = {ispfile}");
            if (File.Exists(ispfile))
            {
                isps = File.ReadAllLines(ispfile).ToList();
            }
            lib = mainBot.QueryConnection.GetLowLibrary <Ts3FullClient>();
            lib.OnClientEnterView += Lib_OnClientEnterView;
            lib.OnConnected       += Lib_OnConnected;
            ClearCache             = TickPool.RegisterTick(Tick, TimeSpan.FromMinutes(UInt64.Parse(cfg["General"]["clearcache"])), false);
            Enabled = true; PluginLog(Log.Level.Debug, "Plugin " + PluginInfo.Name + " v" + PluginInfo.Version + " by " + PluginInfo.Author + " loaded.");
        }
コード例 #2
0
    public PdbScopeMemoryGraph(string pdbScopeFile)
        : base(10000)
    {
        var children = new GrowableArray <NodeIndex>(1000);
        Dictionary <string, NodeTypeIndex> knownTypes = new Dictionary <string, NodeTypeIndex>(1000);

        XmlReaderSettings settings = new XmlReaderSettings()
        {
            IgnoreWhitespace = true, IgnoreComments = true
        };

        using (XmlReader reader = XmlReader.Create(pdbScopeFile, settings))
        {
            int     foundBestRoot     = int.MaxValue; // it is zero when when we find the best root.
            Address imageBase         = 0;
            uint    sizeOfImageHeader = 0;
            Address lastAddress       = 0;
            int     badValues         = 0;

            Queue <Section> sections     = new Queue <Section>();
            Address         prevAddr     = 0;
            Address         expectedAddr = 0;
            RootIndex = NodeIndex.Invalid;
            NodeIndex firstNodeIndex = NodeIndex.Invalid;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                    case "Section":
                    {
                        Section section = new Section();
                        section.Start = Address.Parse(reader.GetAttribute("Start"));
                        section.Size  = uint.Parse(reader.GetAttribute("Size"));
                        section.Name  = reader.GetAttribute("Name");
                        sections.Enqueue(section);
                        lastAddress = Math.Max(lastAddress, section.EndRoundedUpToPage);
                    } break;

                    case "Module":
                        if (imageBase == 0)
                        {
                            imageBase         = Address.Parse(reader.GetAttribute("Base"));
                            sizeOfImageHeader = 1024;            // We are using the file size number
                            NodeIndex     nodeIndex = GetNodeIndex(imageBase);
                            NodeTypeIndex typeIndex = CreateType("Image Header");
                            children.Clear();
                            SetNode(nodeIndex, typeIndex, (int)sizeOfImageHeader, children);
                            expectedAddr = imageBase + 0x1000;

                            DebugWriteLine("Loading Module Map table used to decode $N symbol prefixes.");
                            string dllFilePath = reader.GetAttribute("FilePath");
                            if (dllFilePath != null)
                            {
                                LoadModuleMap(dllFilePath, pdbScopeFile);
                            }
                            else
                            {
                                DebugWriteLine("Could not find path to original DLL being analyzed.");
                            }

                            if (m_moduleMap != null)
                            {
                                DebugWriteLine("Loaded Module Map of " + m_moduleMap.Count + " Project N style IL modules to unmangled $N_ prefixes.");
                            }
                            else
                            {
                                DebugWriteLine("Warning: No Module Map Found: $N_ prefixes will not be unmangled.");
                            }
                        }
                        break;

                    case "ObjectTypes":
                    case "Type":
                    case "Dicectory":
                    case "Sections":
                    case "PdbscopeReport":
                    case "Symbols":
                    case "SourceFiles":
                    case "File":
                        break;

                    case "Symbol":
                        string  addrStr = reader.GetAttribute("addr");
                        Address addr;
                        if (addrStr != null && Address.TryParse(addrStr, NumberStyles.AllowHexSpecifier, null, out addr))
                        {
                            if (addr < lastAddress)
                            {
                                // Get Size
                                string sizeStr = reader.GetAttribute("size");
                                uint   size    = 0;
                                if (sizeStr != null)
                                {
                                    uint.TryParse(sizeStr, out size);
                                }

                                // Get Children
                                children.Clear();
                                string to = reader.GetAttribute("to");
                                if (to != null)
                                {
                                    GetChildrenForAddresses(ref children, to);
                                }

                                // Get Name, make a type out of it
                                string        name;
                                NodeTypeIndex typeIndex = GetTypeForXmlElement(knownTypes, reader, size, out name);

                                // Currently PdbScope files have extra information lines where it shows the different generic instantiations associated
                                // with a given symbol.  These ways have the same address as the previous entry and have no size (size will be 0) so
                                // we filter these lines out with the following condition.
                                if (prevAddr != addr || size != 0)
                                {
                                    prevAddr = addr;

                                    if (addr < expectedAddr)
                                    {
                                        DebugWriteLine(string.Format("Got Address {0:x} which is less than the expected address {1:x}.  Discarding {2}",
                                                                     addr, expectedAddr, name));
                                        badValues++;
                                        if (50 < badValues)
                                        {
                                            throw new ApplicationException("Too many cases where the addresses were not ascending in the file");
                                        }
                                        continue;               // discard
                                    }
                                    /*** We want to make sure we account for all bytes, so log when we see gaps ***/
                                    // If we don't match see if it is because of section boundary.
                                    if (addr != expectedAddr)
                                    {
                                        EmitNodesForGaps(sections, expectedAddr, addr);
                                    }

                                    expectedAddr = addr + size;

                                    NodeIndex nodeIndex = GetNodeIndex((Address)addr);
                                    SetNode(nodeIndex, typeIndex, (int)size, children);

                                    // See if this is a good root
                                    if (foundBestRoot != 0 && name != null)
                                    {
                                        if (name == "RHBinder__ShimExeMain")
                                        {
                                            RootIndex     = nodeIndex;
                                            foundBestRoot = 0;
                                        }
                                        else if (0 < foundBestRoot && name.Contains("ILT$Main"))
                                        {
                                            RootIndex     = nodeIndex;
                                            foundBestRoot = 1;
                                        }
                                        else if (1 < foundBestRoot & name.Contains("DllMainCRTStartup"))
                                        {
                                            RootIndex     = nodeIndex;
                                            foundBestRoot = 1;
                                        }
                                        else if (2 < foundBestRoot & name.Contains("Main"))
                                        {
                                            RootIndex     = nodeIndex;
                                            foundBestRoot = 2;
                                        }
                                    }

                                    // Remember first node.
                                    if (firstNodeIndex == NodeIndex.Invalid)
                                    {
                                        firstNodeIndex = nodeIndex;
                                    }
                                }
                            }
                            else
                            {
                                DebugWriteLine(string.Format("Warning Discarding Symbol node {0:x} outside the last address in the image {1:x}", addr, lastAddress));
                            }
                        }
                        else
                        {
                            DebugWriteLine("Error: symbol without addr");
                        }
                        break;

                    default:
                        DebugWriteLine(string.Format("Skipping unknown element {0}", reader.Name));
                        break;
                    }
                }
            }

            EmitNodesForGaps(sections, expectedAddr, lastAddress);

            if (RootIndex == NodeIndex.Invalid)
            {
                RootIndex = firstNodeIndex;
            }
            DebugWriteLine(string.Format("Image Base {0:x} LastAddress {1:x}", imageBase, lastAddress));
            DebugWriteLine(string.Format("Total Virtual Size {0} ({0:x})", lastAddress - imageBase));
            DebugWriteLine(string.Format("Total File Size    {0} ({0:x})", TotalSize));
        }
        AllowReading();
    }
コード例 #3
0
        private void LoadFile(XContainer file, byte[] data, ADDR start)
        {
            // Grab all the <Pattern /> elements from the XML.
            IEnumerable <XElement> pats = from p in file.Descendants("Pattern") select p;

            // Each Pattern element needs to be handled seperately.
            // The enumeration we're goinv over, is in document order, so attributes such as 'start'
            // should work perfectly fine.
            foreach (XElement pat in pats)
            {
                ADDR tmpStart = 0;

                string name         = pat.Attribute("desc").Value;
                string mask         = pat.Attribute("mask").Value;
                byte[] patternBytes = GetBytesFromPattern(pat.Attribute("pattern").Value);

                // Make sure we're not getting some sort of screwy XML data.
                if (mask.Length != patternBytes.Length)
                {
                    throw new Exception("Pattern and mask lengths do not match!");
                }

                // If we run into a 'start' attribute, we need to remember that we're working from a 0
                // based 'memory pool'. So we just remove the 'start' from the address we found earlier.
                if (pat.Attribute("start") != null)
                {
                    tmpStart = (ADDR)(this[pat.Attribute("start").Value].ToInt32() - start + 1);
                }

                // Actually search for the pattern match...
                ADDR found = Find(data, mask, patternBytes, tmpStart);
                if (found == 0)
                {
                    throw new Exception("FindPattern failed... figure it out ****tard!");
                }

                // Handle specific child elements for the pattern.
                // <Lea> <Rel> <Add> <Sub> etc
                foreach (XElement e in pat.Elements())
                {
                    switch (e.Name.LocalName)
                    {
                    case "Lea":
                        found = BitConverter.ToUInt32(data, (int)found);
                        break;

                    case "Rel":
                        int instructionSize = int.Parse(e.Attribute("size").Value, NumberStyles.HexNumber);
                        int operandOffset   = int.Parse(e.Attribute("offset").Value, NumberStyles.HexNumber);
                        found = (ADDR)(BitConverter.ToUInt32(data, (int)found) + found + instructionSize - operandOffset);
                        break;

                    case "Add":
                        found += ADDR.Parse(e.Attribute("value").Value, NumberStyles.HexNumber);
                        break;

                    case "Sub":
                        found -= ADDR.Parse(e.Attribute("value").Value, NumberStyles.HexNumber);
                        break;
                    }
                }

                mPatterns.Add(name, (IntPtr)(found + start));
            }
        }
コード例 #4
0
ファイル: DataTypes.cs プロジェクト: zerodowned/Core
        public static bool TryParse(string data, DataType flag, out SimpleType value)
        {
            value = Null;

            try
            {
                var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any;

                if (numStyle == NumberStyles.HexNumber)
                {
                    data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2);
                }

                switch (flag)
                {
                case DataType.Bool:
                    value = new SimpleType(Boolean.Parse(data));
                    return(true);

                case DataType.Char:
                    value = new SimpleType(Char.Parse(data));
                    return(true);

                case DataType.Byte:
                    value = new SimpleType(Byte.Parse(data, numStyle));
                    return(true);

                case DataType.SByte:
                    value = new SimpleType(SByte.Parse(data, numStyle));
                    return(true);

                case DataType.Short:
                    value = new SimpleType(Int16.Parse(data, numStyle));
                    return(true);

                case DataType.UShort:
                    value = new SimpleType(UInt16.Parse(data, numStyle));
                    return(true);

                case DataType.Int:
                    value = new SimpleType(Int32.Parse(data, numStyle));
                    return(true);

                case DataType.UInt:
                    value = new SimpleType(UInt32.Parse(data, numStyle));
                    return(true);

                case DataType.Long:
                    value = new SimpleType(Int64.Parse(data, numStyle));
                    return(true);

                case DataType.ULong:
                    value = new SimpleType(UInt64.Parse(data, numStyle));
                    return(true);

                case DataType.Float:
                    value = new SimpleType(Single.Parse(data, numStyle));
                    return(true);

                case DataType.Decimal:
                    value = new SimpleType(Decimal.Parse(data, numStyle));
                    return(true);

                case DataType.Double:
                    value = new SimpleType(Double.Parse(data, numStyle));
                    return(true);

                case DataType.String:
                    value = new SimpleType(data);
                    return(true);

                case DataType.DateTime:
                    value = new SimpleType(DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces));
                    return(true);

                case DataType.TimeSpan:
                    value = new SimpleType(TimeSpan.Parse(data));
                    return(true);
                }
            }
            catch
            { }

            return(false);
        }
コード例 #5
0
ファイル: DataTypes.cs プロジェクト: zerodowned/Core
        public static bool TryParse <T>(string data, out T value)
        {
            value = default(T);

            try
            {
                object val = null;

                var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any;

                if (numStyle == NumberStyles.HexNumber)
                {
                    data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2);
                }

                var f = DataTypes.Lookup(value);

                switch (f)
                {
                case DataType.Bool:
                    val = Boolean.Parse(data);
                    break;

                case DataType.Char:
                    val = Char.Parse(data);
                    break;

                case DataType.Byte:
                    val = Byte.Parse(data, numStyle);
                    break;

                case DataType.SByte:
                    val = SByte.Parse(data, numStyle);
                    break;

                case DataType.Short:
                    val = Int16.Parse(data, numStyle);
                    break;

                case DataType.UShort:
                    val = UInt16.Parse(data, numStyle);
                    break;

                case DataType.Int:
                    val = Int32.Parse(data, numStyle);
                    break;

                case DataType.UInt:
                    val = UInt32.Parse(data, numStyle);
                    break;

                case DataType.Long:
                    val = Int64.Parse(data, numStyle);
                    break;

                case DataType.ULong:
                    val = UInt64.Parse(data, numStyle);
                    break;

                case DataType.Float:
                    val = Single.Parse(data, numStyle);
                    break;

                case DataType.Decimal:
                    val = Decimal.Parse(data, numStyle);
                    break;

                case DataType.Double:
                    val = Double.Parse(data, numStyle);
                    break;

                case DataType.String:
                    val = data;
                    break;

                case DataType.DateTime:
                    val = DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
                    break;

                case DataType.TimeSpan:
                    val = TimeSpan.Parse(data);
                    break;
                }

                value = (T)val;
                return(true);
            }
            catch
            { }

            return(false);
        }
コード例 #6
0
 public static nuint Parse(string s, NumberStyles style, IFormatProvider provider)
 {
     return(UInt64.Parse(s, style, provider));
 }
コード例 #7
0
 public static nuint Parse(string s)
 {
     return(UInt64.Parse(s));
 }
コード例 #8
0
 public static nuint Parse(string s, NumberStyles style)
 {
     return(UInt64.Parse(s, style));
 }
コード例 #9
0
 public static nuint Parse(string s, IFormatProvider provider)
 {
     return(UInt64.Parse(s, provider));
 }
コード例 #10
0
        public static bool TryConvert(string data, DataType flag, out object val)
        {
            val = null;

            if (flag == DataType.Null)
            {
                return(false);
            }

            try
            {
                var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any;

                if (numStyle == NumberStyles.HexNumber)
                {
                    data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2);
                }

                switch (flag)
                {
                case DataType.Bool:
                    val = Boolean.Parse(data);
                    return(true);

                case DataType.Char:
                    val = Char.Parse(data);
                    return(true);

                case DataType.Byte:
                    val = Byte.Parse(data, numStyle);
                    return(true);

                case DataType.SByte:
                    val = SByte.Parse(data, numStyle);
                    return(true);

                case DataType.Short:
                    val = Int16.Parse(data, numStyle);
                    return(true);

                case DataType.UShort:
                    val = UInt16.Parse(data, numStyle);
                    return(true);

                case DataType.Int:
                    val = Int32.Parse(data, numStyle);
                    return(true);

                case DataType.UInt:
                    val = UInt32.Parse(data, numStyle);
                    return(true);

                case DataType.Long:
                    val = Int64.Parse(data, numStyle);
                    return(true);

                case DataType.ULong:
                    val = UInt64.Parse(data, numStyle);
                    return(true);

                case DataType.Float:
                    val = Single.Parse(data, numStyle);
                    return(true);

                case DataType.Decimal:
                    val = Decimal.Parse(data, numStyle);
                    return(true);

                case DataType.Double:
                    val = Double.Parse(data, numStyle);
                    return(true);

                case DataType.String:
                    val = data;
                    return(true);

                case DataType.DateTime:
                    val = DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
                    return(true);

                case DataType.TimeSpan:
                    val = TimeSpan.Parse(data);
                    return(true);

                default:
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #11
0
        public static bool TryParse(string data, DataType flag, out SimpleType value)
        {
            try
            {
                switch (flag)
                {
                case DataType.Null:
                    value = new SimpleType(null);
                    break;

                case DataType.Bool:
                    value = new SimpleType(Boolean.Parse(data));
                    break;

                case DataType.Char:
                    value = new SimpleType(Char.Parse(data));
                    break;

                case DataType.Byte:
                    value = new SimpleType(Byte.Parse(data));
                    break;

                case DataType.SByte:
                    value = new SimpleType(SByte.Parse(data));
                    break;

                case DataType.Short:
                    value = new SimpleType(Int16.Parse(data));
                    break;

                case DataType.UShort:
                    value = new SimpleType(UInt16.Parse(data));
                    break;

                case DataType.Int:
                    value = new SimpleType(Int32.Parse(data));
                    break;

                case DataType.UInt:
                    value = new SimpleType(UInt32.Parse(data));
                    break;

                case DataType.Long:
                    value = new SimpleType(Int64.Parse(data));
                    break;

                case DataType.ULong:
                    value = new SimpleType(UInt64.Parse(data));
                    break;

                case DataType.Float:
                    value = new SimpleType(Single.Parse(data));
                    break;

                case DataType.Decimal:
                    value = new SimpleType(Decimal.Parse(data));
                    break;

                case DataType.Double:
                    value = new SimpleType(Double.Parse(data));
                    break;

                case DataType.String:
                    value = new SimpleType(data);
                    break;

                case DataType.DateTime:
                    value = new SimpleType(DateTime.Parse(data));
                    break;

                case DataType.TimeSpan:
                    value = new SimpleType(TimeSpan.Parse(data));
                    break;

                default:
                    value = new SimpleType(null);
                    break;
                }

                return(true);
            }
            catch
            {
                value = new SimpleType(null);
                return(false);
            }
        }