Exemple #1
0
        void Begin()
        {
            var parameter = new ConfuserParameter();
            parameter.Project = host.Project.ToCrProj();
            parameter.Logger.BeginAssembly += Logger_BeginAssembly;
            parameter.Logger.EndAssembly += Logger_EndAssembly;
            parameter.Logger.Phase += Logger_Phase;
            parameter.Logger.Log += Logger_Log;
            parameter.Logger.Progress += Logger_Progress;
            parameter.Logger.Fault += Logger_Fault;
            parameter.Logger.End += Logger_End;

            cr = new Confuser.Core.Confuser();
            thread = cr.ConfuseAsync(parameter);
            host.EnabledNavigation = false;
            btn.IsEnabled = true;

            p = 0;
            Action check = null;
            check = new Action(() =>
            {
                progress.Value = p;
                if (p != -1)
                    Dispatcher.BeginInvoke(check, System.Windows.Threading.DispatcherPriority.Background);
            });
            check();
        }
Exemple #2
0
        static int Main(string[] args)
        {
            ConsoleColor color = System.Console.ForegroundColor;
            System.Console.ForegroundColor = ConsoleColor.White;

            WriteLine("Confuser Version v" + typeof(Core.Confuser).Assembly.GetName().Version);
            WriteLine();

            #if DEBUG
            for (int i = 0; i < 3; i++)
            {
                System.Console.Write('.');
                System.Threading.Thread.Sleep(1000);
            }
            WriteLine();
            #endif

            try
            {
                if (args.Length == 0 || args[0] == "-help")
                {
                    PrintUsage();
                    return 0;
                }

                ConfuserProject proj;
                int error = ParseCommandLine(args, out proj);
                if (error != 0)
                {
                    return error;
                }

                Core.Confuser cr = new Core.Confuser();
                ConfuserParameter param = new ConfuserParameter();
                param.Project = proj;
                ConsoleLogger.Initalize(param.Logger);
                WriteLine("Start working.");
                WriteLine(new string('*', 15));
                cr.Confuse(param);

                return ConsoleLogger.ReturnValue;
            }
            finally
            {
                System.Console.ForegroundColor = color;
            }
        }
Exemple #3
0
        void Logger_Fault(object sender, ExceptionEventArgs e)
        {
            if (!CheckAccess())
            {
                Dispatcher.Invoke(new EventHandler<ExceptionEventArgs>(Logger_Fault), sender, e);
                return;
            }
            asmLbl.DataContext = new AsmData()
            {
                Assembly = null,
                Icon = (BitmapSource)FindResource("error"),
                Filename = "Failure!",
                Fullname = e.Exception is ThreadAbortException ? "Cancelled." : e.Exception.Message
            };
            if (e.Exception is ThreadAbortException)
            {
                log.AppendText("Cancelled!\r\n");
            }
            else if (
                e.Exception is SecurityException ||
                e.Exception is DirectoryNotFoundException ||
                e.Exception is UnauthorizedAccessException ||
                e.Exception is IOException)
            {
                log.AppendText("\r\n\r\n\r\n");
                log.AppendText("Oops... Confuser crashed...\r\n");
                log.AppendText("\r\n");
                log.AppendText(e.Exception.GetType().FullName + "\r\n");
                log.AppendText("Message : " + e.Exception.Message + "\r\n");
                log.AppendText("Stack Trace :\r\n");
                log.AppendText(e.Exception.StackTrace + "\r\n");
                log.AppendText("\r\n");
                log.AppendText("Please ensure Confuser have enough permission!!!\r\n");
            }
            else
            {
                log.AppendText("\r\n\r\n\r\n");
                log.AppendText("Oops... Confuser crashed...\r\n");
                log.AppendText("\r\n");
                log.AppendText(e.Exception.GetType().FullName + "\r\n");
                log.AppendText("Message : " + e.Exception.Message + "\r\n");
                log.AppendText("Stack Trace :\r\n");
                log.AppendText(e.Exception.StackTrace + "\r\n");
                log.AppendText("\r\n");
                log.AppendText("Please report it!!!\r\n");
            }

            cr = null;
            thread = null;
            btn.IsEnabled = false;
            host.EnabledNavigation = true;
            p = -1;
            Dispatcher.BeginInvoke(new Action(() => GC.Collect()), System.Windows.Threading.DispatcherPriority.SystemIdle);
        }
Exemple #4
0
        void Logger_End(object sender, LogEventArgs e)
        {
            if (!CheckAccess())
            {
                Dispatcher.Invoke(new EventHandler<LogEventArgs>(Logger_End), sender, e);
                return;
            }
            asmLbl.DataContext = new AsmData()
            {
                Assembly = null,
                Icon = (BitmapSource)FindResource("ok"),
                Filename = "Success!",
                Fullname = e.Message
            };
            log.AppendText(e.Message + "\r\n");

            progress.Value = 10000;

            cr = null;
            thread = null;
            btn.IsEnabled = false;
            host.EnabledNavigation = true;
            p = -1;
            Dispatcher.BeginInvoke(new Action(() => GC.Collect()), System.Windows.Threading.DispatcherPriority.SystemIdle);
        }
Exemple #5
0
        public override bool Execute()
        {
            Log.LogMessage(MessageImportance.Low, "Confuser Version v{0}\n", typeof(Core.Confuser).Assembly.GetName().Version);

            string crproj = Path.Combine(
                Path.GetDirectoryName(BuildEngine.ProjectFileOfTaskNode),
                CrProj);

            if (!File.Exists(crproj))
            {
                Log.LogError("Confuser", "CR001", "Project", "",
                    0, 0, 0, 0,
                    string.Format("Error: Crproj file '{0}' not exist!", crproj));
                return false;
            }

            XmlDocument xmlDoc = new XmlDocument();
            ConfuserProject proj = new ConfuserProject();
            bool err = false;
            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.Schemas.Add(ConfuserProject.Schema);
                settings.ValidationType = ValidationType.Schema;
                settings.ValidationEventHandler += (sender, e) =>
                {
                    Log.LogError("Confuser", "CR002", "Project", crproj,
                        e.Exception.LineNumber, e.Exception.LinePosition,
                        e.Exception.LineNumber, e.Exception.LinePosition,
                        e.Message);
                    err = true;
                };
                var rdr = XmlReader.Create(crproj, settings);
                xmlDoc.Load(rdr);
                rdr.Close();
                if (err)
                    return false;
                proj.Load(xmlDoc);
            }
            catch (Exception ex)
            {
                Log.LogError("Confuser", "CR002", "Project", crproj,
                    0, 0, 0, 0,
                    ex.Message);
                return false;
            }
            proj.BasePath = BasePath;

            Core.Confuser cr = new Core.Confuser();
            ConfuserParameter param = new ConfuserParameter();
            param.Project = proj;

            var logger = new MSBuildLogger(Log);
            logger.Initalize(param.Logger);

            Log.LogMessage(MessageImportance.Low, "Start working.");
            Log.LogMessage(MessageImportance.Low, "***************");
            cr.Confuse(param);

            return logger.ReturnValue;
        }