Example #1
0
        /// <summary>
        /// 重载配置
        /// </summary>
        public static void Reload()
        {
            if (Directory.Exists(Path) == false)
            {
                Directory.CreateDirectory(Path);
            }
            if (!File.Exists(Path + Logs.log))
            {
                try
                {
                    File.WriteAllText(Path + Logs.log, "正在尝试创建日志文件" + Environment.NewLine);
                }
                catch
                {
                    Console.WriteLine("[Minecraft_QQ]日志文件创建失败");
                    return;
                }
            }

            ConfigRead read = new ConfigRead();

            ConfigFile.主要配置文件 = new FileInfo(Path + "Mainconfig.json");

            //读取主配置文件
            if (ConfigFile.主要配置文件.Exists == false)
            {
                Logs.LogWrite("[Info][Config]新建主配置");
                MainConfig = new MainConfig();
                File.WriteAllText(ConfigFile.主要配置文件.FullName, JsonConvert.SerializeObject(MainConfig, Formatting.Indented));
            }
            else
            {
                MainConfig = read.ReadConfig();
            }
        }
Example #2
0
 public static TSConfig Read(Stream stream)
 {
     using (var sr = new StreamReader(stream))
     {
         var cf = JsonConvert.DeserializeObject <TSConfig>(sr.ReadToEnd());
         ConfigRead?.Invoke(cf);
         return(cf);
     }
 }
Example #3
0
 /// <summary>
 /// Reads the configuration file from a stream
 /// </summary>
 /// <param name="stream">stream</param>
 /// <param name="anyChanges"> Whether the config object required an upgrade or had unexpected fields added or missing</param>
 /// <returns>ConfigFile object</returns>
 public static ConfigFile Read(Stream stream, out bool anyChanges)
 {
     using (var sr = new StreamReader(stream))
     {
         var cf = FileTools.LoadConfigAndCheckForChanges <ConfigFile>(sr.ReadToEnd(), out anyChanges);
         ConfigRead?.Invoke(cf);
         return(cf);
     }
 }
Example #4
0
    public void Perform()
    {
        Process[] myProcesses;
        myProcesses        = Process.GetProcesses();
        MyFormPoster       = new FormPoster();
        MyConsoleLogger    = new ConsoleLogger();
        MyNTEventLogLogger = new NTEventLogLogger();
        myDiscovery        = new ToolSpecificEvent();

        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyConsoleLogger.handler);
        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyNTEventLogLogger.handler);
        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyFormPoster.handler);
        configuration_from_xml   = new ConfigRead();
        configuration_from_xml.LoadConfiguration("Configuration/ProcessDetection/Process", "ProcessName");
        string process_detector_expression = configuration_from_xml.DetectorExpression;
        Regex  process_detector_regex      = new Regex(process_detector_expression, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

        foreach (Process myProcess in myProcesses)
        {
            string res    = String.Empty;
            string sProbe = myProcess.ProcessName;
            //  myProcess.StartInfo.FileName - not accessible
            if (Debug)
            {
                Console.WriteLine("Process scan: {0}", process_detector_expression);
            }
            MatchCollection m = process_detector_regex.Matches(sProbe);
            if (sProbe != null && m.Count != 0)
            {
                try
                {
                    DialogDetected       = true;
                    process_command_line = new ProcessCommandLine(myProcess.Id.ToString());
                    if (Debug)
                    {
                        Console.WriteLine("{0}{1}", myProcess.Id.ToString(), process_command_line.CommandLine);
                    }
                    CommandLine = process_command_line.CommandLine;
                    // CommandLine = myProcess.ProcessName;
                    Console.WriteLine("--> {0} {1} {2} {3}", sProbe, myProcess.ProcessName, myProcess.Id, DateTime.Now - myProcess.StartTime);
                }
                catch (Win32Exception e) {
                    System.Diagnostics.Trace.Assert(e != null);
                }
            }
        }
        CallBackPtr callBackPtr = new CallBackPtr(EnumReport.Report);

        if (DialogDetected)
        {
            EnumReport.evt         = myDiscovery;
            EnumReport.CommandLine = CommandLine;
            EnumReport.EnumWindows(callBackPtr, 0);
        }
    }
Example #5
0
    // http://stackoverflow.com/questions/1145347/what-is-the-best-way-to-make-a-single-instance-application-in-net
    public static List <IntPtr> GetChildWindows(IntPtr parent)
    {
        List <IntPtr> result     = new List <IntPtr>();
        GCHandle      listHandle = GCHandle.Alloc(result);

        try
        {
            EnumWindowsProc childProc = new EnumWindowsProc(EnumWindow);
            EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));

            System.IntPtr[] sArray = new System.IntPtr[result.Count];
            result.CopyTo(sArray, 0);
            foreach (System.IntPtr s in sArray)
            {
                string sChT = GetText(s);
                Console.WriteLine(sChT);
                if (x == null)
                {
                    x = new ConfigRead();
                }
                x.LoadConfiguration("Configuration/DialogDetection/Pattern", "DialogText");
                string s2 = x.DetectorExpression;

                string res = String.Empty;
                Regex  r   = new Regex(s2,
                                       RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

                MatchCollection m = r.Matches(sChT);
                if (sChT != null && m.Count != 0)
                {
                    if (DEBUG)
                    {
                        Console.WriteLine(s.ToString());
                        Console.WriteLine(sChT);
                    }
                    bHasEnemyChild = true;

                    sDialogText = sChT;
                }
            }
        }

        finally
        {
            if (listHandle.IsAllocated)
            {
                listHandle.Free();
            }
        }
        return(result);
    }
    public void Perform()
    {
        Process[] myProcesses;
        myProcesses = Process.GetProcesses();
        MyFormPoster = new FormPoster();
        MyConsoleLogger = new ConsoleLogger();
        MyNTEventLogLogger = new NTEventLogLogger();
        myDiscovery = new ToolSpecificEvent();

        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyConsoleLogger.handler);
        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyNTEventLogLogger.handler);
        myDiscovery.ActionEvent += new ToolSpecificEventHandler(MyFormPoster.handler);
        configuration_from_xml = new ConfigRead();
        configuration_from_xml.LoadConfiguration("Configuration/ProcessDetection/Process", "ProcessName");
        string process_detector_expression = configuration_from_xml.DetectorExpression;
        Regex process_detector_regex = new Regex(process_detector_expression, RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

        foreach (Process myProcess in myProcesses)
        {
            string res = String.Empty;
            string sProbe = myProcess.ProcessName;
            //  myProcess.StartInfo.FileName - not accessible
            if (Debug) Console.WriteLine("Process scan: {0}", process_detector_expression); MatchCollection m = process_detector_regex.Matches(sProbe);
            if (sProbe != null && m.Count != 0)
            {
                try
                {
                    DialogDetected = true;
                    process_command_line = new ProcessCommandLine(myProcess.Id.ToString());
                    if (Debug) Console.WriteLine("{0}{1}", myProcess.Id.ToString(), process_command_line.CommandLine);
                    CommandLine = process_command_line.CommandLine;
                    // CommandLine = myProcess.ProcessName;
                    Console.WriteLine("--> {0} {1} {2} {3}", sProbe, myProcess.ProcessName, myProcess.Id, DateTime.Now - myProcess.StartTime);
                }
                catch (Win32Exception e) {
                     System.Diagnostics.Trace.Assert(e != null);
                }
            }
        }
        CallBackPtr callBackPtr = new CallBackPtr(EnumReport.Report);
        if (DialogDetected)
        {
            EnumReport.evt = myDiscovery;
            EnumReport.CommandLine = CommandLine;
            EnumReport.EnumWindows(callBackPtr, 0);
        }
    }
Example #7
0
    /// <summary>
    /// Checks  Window Caption and optionally inspects Dialog text
    /// </summary>

    public static bool Report(IntPtr hWnd, int lParam)
    {
        IntPtr lngPid = System.IntPtr.Zero;

        GetWindowThreadProcessId(hWnd, out lngPid);
        int PID = Convert.ToInt32(/* Marshal.ReadInt32 */ lngPid.ToString());

        if (x == null)
        {
            x = new ConfigRead();
        }
        x.LoadConfiguration("Configuration/WindowDetection/Window", "Text");
        string s = x.DetectorExpression;

        string res = String.Empty;
        Regex  r   = new Regex(s,
                               RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
        string          sToken = GetText(hWnd);
        MatchCollection m      = r.Matches(sToken);

        if (sToken != null && m.Count != 0)
        {
            Console.WriteLine(String.Format("==>{0}", sToken));

            EnumPropsEx(hWnd, EnumPropsExManaged, 0);

            bHasEnemyChild = false;
            GetChildWindows(hWnd);

            if (bHasEnemyChild)
            {
                if (DEBUG)
                {
                    Console.WriteLine("Window process ID is " + PID.ToString());
                    Console.WriteLine("Window handle is " + hWnd);
                    Console.WriteLine("Window title is " + sToken);
                    Console.WriteLine("Window match " + m.Count.ToString());
                }

                // Fire the event.

                evt.FireToolSpecificEvent(PID, CommandLine, sToken, sDialogText);
            }
        }
        return(true);
    }
Example #8
0
        public static void Register()
        {
            var builder = new ContainerBuilder();

            //注册Controller
            builder.RegisterControllers(typeof(AutofacConfig).Assembly);

            var business  = ConfigRead.Read("register").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var assemblys = business.Select(b => Assembly.Load(b)).ToArray();

            builder.RegisterAssemblyTypes(assemblys).AsImplementedInterfaces();

            //创建一个Autofac的容器
            var container = builder.Build();

            //将MVC的控制器对象实例 交由autofac来创建
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Example #9
0
        public async Task Initialize()
        {
            if (IsInitialize)
            {
                return;
            }
            ConfigRead.readConfig(dicTask);
            ConfigRead.readConfig(dicLanguage);
            ConfigRead.readConfig(dicEffect);

            //读取竖表配置

            //等待全部加载完再执行自定义解析
            await ConfigRead.waitLoadComplate();

            customRead();

            IsInitialize = true;
        }
    // http://stackoverflow.com/questions/1145347/what-is-the-best-way-to-make-a-single-instance-application-in-net
    public static List<IntPtr> GetChildWindows(IntPtr parent)
    {
        List<IntPtr> result = new List<IntPtr>();
        GCHandle listHandle = GCHandle.Alloc(result);
        try
        {
            EnumWindowsProc childProc = new EnumWindowsProc(EnumWindow);
            EnumChildWindows(parent, childProc, GCHandle.ToIntPtr(listHandle));

            System.IntPtr[] sArray = new System.IntPtr[result.Count];
            result.CopyTo(sArray, 0);
            foreach (System.IntPtr s in sArray)
            {
                string sChT = GetText(s);
                Console.WriteLine(sChT);
                if (x == null)
                    x = new ConfigRead();
                x.LoadConfiguration("Configuration/DialogDetection/Pattern", "DialogText");
                string s2 = x.DetectorExpression;

                string res = String.Empty;
                Regex r = new Regex(s2,
                                    RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);

                MatchCollection m = r.Matches(sChT);
                if (sChT != null && m.Count != 0)
                {
                    if (DEBUG)
                    {
                        Console.WriteLine(s.ToString());
                        Console.WriteLine(sChT);
                    }
                    bHasEnemyChild = true;

                    sDialogText = sChT;
                }
            }
        }

        finally
        {
            if (listHandle.IsAllocated)
                listHandle.Free();
        }
        return result;
    }
    /// <summary>
    /// Checks  Window Caption and optionally inspects Dialog text
    /// </summary>

    public static bool Report(IntPtr hWnd, int lParam)
    {

        IntPtr lngPid = System.IntPtr.Zero;

        GetWindowThreadProcessId(hWnd, out lngPid);
        int PID = Convert.ToInt32(/* Marshal.ReadInt32 */ lngPid.ToString());

        if (x == null)
            x = new ConfigRead();
        x.LoadConfiguration("Configuration/WindowDetection/Window", "Text");
        string s = x.DetectorExpression;

        string res = String.Empty;
        Regex r = new Regex(s,
                            RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
        string sToken = GetText(hWnd);
        MatchCollection m = r.Matches(sToken);
        if (sToken != null && m.Count != 0)
        {
            Console.WriteLine(String.Format("==>{0}", sToken));

            EnumPropsEx(hWnd, EnumPropsExManaged, 0);

            bHasEnemyChild = false;
            GetChildWindows(hWnd);

            if (bHasEnemyChild)
            {

                if (DEBUG)
                {

                    Console.WriteLine("Window process ID is " + PID.ToString());
                    Console.WriteLine("Window handle is " + hWnd);
                    Console.WriteLine("Window title is " + sToken);
                    Console.WriteLine("Window match " + m.Count.ToString());

                }

                // Fire the event.

                evt.FireToolSpecificEvent(PID, CommandLine, sToken, sDialogText);

            }

        }
        return true;
    }