コード例 #1
0
ファイル: Progress.xaml.cs プロジェクト: n017/Confuser
        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();
        }
コード例 #2
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();
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
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;
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: n017/Confuser
        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;
            }
        }
コード例 #7
0
ファイル: Progress.xaml.cs プロジェクト: n017/Confuser
        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);
        }
コード例 #8
0
ファイル: Progress.xaml.cs プロジェクト: n017/Confuser
        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);
        }
コード例 #9
0
        public override AssemblyDefinition[] GetAssemblies(string src, Core.Preset preset, Core.Confuser cr, EventHandler <Confuser.Core.LogEventArgs> err)
        {
            List <AssemblyDefinition> ret = new List <AssemblyDefinition>();

            foreach (AssemblyDefinition asm in srcs.Values)
            {
                AssemblyDefinition n = AssemblyDefinition.ReadAssembly(asm.MainModule.FullyQualifiedName, new ReaderParameters(ReadingMode.Immediate));
                MarkAssembly(srcs[n.FullName], n);
                ret.Add(n);
            }
            return(ret.ToArray());
        }
コード例 #10
0
        private void DoConfuse(object sender, RoutedEventArgs e)
        {
            if ((string)doConfuse.Content == "Cancel")
            {
                confuser.Abort();
                return;
            }

            var param = new Core.ConfuserParameter();

            param.SourceAssembly     = path;
            param.DestinationPath    = output.Text;
            param.ReferencesPath     = System.IO.Path.GetDirectoryName(path);
            param.Confusions         = ldConfusions.Values.ToArray();
            param.Packers            = ldPackers.Values.ToArray();
            param.DefaultPreset      = Core.Preset.None;
            param.StrongNameKeyPath  = sn.Text;
            param.Marker             = marker;
            param.Logger.BeginPhase += new EventHandler <Core.PhaseEventArgs>((sender1, e1) =>
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    Monitor.Enter(this);
                    Border phase = Helper.FindChild <Border>(progress, "phase" + e1.Phase);
                    log          = Helper.FindChild <TextBox>(phase, null);
                    if (pBar != null)
                    {
                        pBar.Value = 1;
                    }
                    pBar = Helper.FindChild <ProgressBar>(phase, null);
                    if (pBar != null)
                    {
                        pBar.Value = 0;
                    }
                    Storyboard sb = this.Resources["showPhase"] as Storyboard;
                    Storyboard.SetTarget(sb.Children[0], phase);
                    Storyboard.SetTarget(sb.Children[1], phase);
                    sb.Completed += delegate
                    {
                        Monitor.Exit(this);
                        progress.ScrollTo(e1.Phase / 5.0);
                    };
                    sb.Begin();
                }), null);
                lock (this) { }
                Thread.Sleep(150);
            });
            param.Logger.Logging += new EventHandler <Core.LogEventArgs>((sender1, e1) =>
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    if (log != null)
                    {
                        log.AppendText(e1.Message + Environment.NewLine);
                        log.ScrollToEnd();
                    }
                }), null);
            });
            param.Logger.Progressing += new EventHandler <Core.ProgressEventArgs>((sender1, e1) =>
            {
                value = e1.Progress;
            });
            param.Logger.Fault += new EventHandler <Core.ExceptionEventArgs>((sender1, e1) =>
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    Monitor.Enter(this);
                    Border result = Helper.FindChild <Border>(progress, "result");
                    Helper.FindChild <UIElement>(result, "resultFail").Visibility = Visibility.Visible;
                    Helper.FindChild <UIElement>(result, "resultOk").Visibility   = Visibility.Hidden;
                    Helper.FindChild <TextBox>(result, null).Text = string.Format("Failed!\nException details : \n" + e1.Exception.ToString());
                    Storyboard sb = this.Resources["showPhase"] as Storyboard;
                    Storyboard.SetTarget(sb, result);
                    sb.Completed += delegate
                    {
                        Monitor.Exit(this);
                        progress.ScrollToEnd();
                    };
                    sb.Begin();
                    value             = -1;
                    doConfuse.Content = "Confuse!";
                    CONFUSED();
                }), null);
                lock (this) { }
            });
            param.Logger.End += new EventHandler <Core.LogEventArgs>((sender1, e1) =>
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    Monitor.Enter(this);
                    if (pBar != null)
                    {
                        pBar.Value = 1;
                    }
                    Border result = Helper.FindChild <Border>(progress, "result");
                    Helper.FindChild <UIElement>(result, "resultOk").Visibility   = Visibility.Visible;
                    Helper.FindChild <UIElement>(result, "resultFail").Visibility = Visibility.Hidden;
                    Helper.FindChild <TextBox>(result, null).Text = string.Format("Succeeded!\n" + e1.Message.ToString());
                    Storyboard sb = this.Resources["showPhase"] as Storyboard;
                    Storyboard.SetTarget(sb, result);
                    sb.Completed += delegate
                    {
                        Monitor.Exit(this);
                        progress.ScrollToEnd();
                    };
                    sb.Begin();
                    value             = -1;
                    doConfuse.Content = "Confuse!";
                    CONFUSED();
                }), null);
                lock (this) { }
            });
            var cr = new Core.Confuser();

            progress.ScrollToBeginning();
            (this.Resources["resetProgress"] as Storyboard).Begin();
            Helper.FindChild <TextBox>(phase1, null).Text = "";
            Helper.FindChild <TextBox>(phase2, null).Text = "";
            Helper.FindChild <TextBox>(phase3, null).Text = "";
            Helper.FindChild <TextBox>(phase4, null).Text = "";
            (this.Resources["showProgress"] as Storyboard).Begin();
            Dispatcher.Invoke(new Action(delegate { Thread.Sleep(100); }), DispatcherPriority.Render);
            MoniterValue();
            CONFUSING();
            doConfuse.Content = "Cancel";
            confuser          = cr.ConfuseAsync(param);
        }
コード例 #11
0
ファイル: MSBuildTask.cs プロジェクト: n017/Confuser
        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;
        }
コード例 #12
0
ファイル: MSBuildTask.cs プロジェクト: zippy1981/Confuser
        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);
        }