public void cmDeobf_Click(object sender, EventArgs e)
        {
            if (_currentMethod == null) return;

            if (_frmDeobfMethod == null)
            {
                _frmDeobfMethod = new frmDeobfMethod(_currentMethod);
            }
            else
            {
                _frmDeobfMethod.InitForm(_currentMethod);
            }

            if (_frmDeobfMethod.ShowDialog() != DialogResult.OK) return;

            bool resolveDirAdded = false;
            SimpleWaitCursor wc = new SimpleWaitCursor();
            try
            {
                resolveDirAdded = _form.Host.AddAssemblyResolveDir(_form.SourceDir);

                AssemblyDefinition ad = _currentMethod.DeclaringType.Module.Assembly;
                string file = null;
                foreach (TreeNode n in _form.TreeView.Nodes)
                {
                    if (ad.Equals(n.Tag))
                    {
                        file = _form.TreeViewHandler.GetTreeNodeText(n);
                        break;
                    }
                }

                if (file == null)
                    return;
                
                file = Path.Combine(_form.SourceDir, file);
                if (String.IsNullOrEmpty(file) || !File.Exists(file))
                {
                    throw new ApplicationException("Cannot find assembly file: " + file);
                }
                

                DeobfOptions options = new DeobfOptions();
                options.Clear();

                options.Host = _form.Host;
                options.Rows = new string[] { file };
                options.SourceDir = _form.SourceDir;
                options.OutputDir = _form.SourceDir;
                options.BranchDirection = _frmDeobfMethod.BranchDirection;

                options.LoopCount = Config.DeobfFlowOptionBranchLoopCount;
                options.MaxRefCount = Config.DeobfFlowOptionMaxRefCount;
                options.MaxMoveCount = Config.DeobfFlowOptionMaxMoveCount;

                options.chkPatternChecked = _frmDeobfMethod.AutoFlowPattern;
                options.chkBranchChecked = _frmDeobfMethod.AutoFlowBranch;
                options.chkCondBranchDownChecked = _frmDeobfMethod.AutoFlowConditionalBranchDown;
                options.chkCondBranchUpChecked = _frmDeobfMethod.AutoFlowConditionalBranchUp;
                
                options.chkSwitchChecked = _frmDeobfMethod.AutoFlowSwitch;
                options.chkUnreachableChecked = _frmDeobfMethod.AutoFlowUnreachable;
                options.chkRemoveExceptionHandlerChecked = _frmDeobfMethod.AutoFlowExceptionHandler;
                options.chkBoolFunctionChecked = _frmDeobfMethod.AutoFlowBoolFunction;
                options.chkDelegateCallChecked = _frmDeobfMethod.AutoFlowDelegateCall;
                options.chkDirectCallChecked = _frmDeobfMethod.AutoFlowDirectCall;
                options.chkBlockMoveChecked = _frmDeobfMethod.AutoFlowBlockMove;
                options.chkReflectorFixChecked = _frmDeobfMethod.AutoFlowReflectorFix;
                options.chkRemoveInvalidInstructionChecked = _frmDeobfMethod.AutoFlowRemoveInvalidInstruction;

                options.chkAutoStringChecked = _frmDeobfMethod.AutoString || _frmDeobfMethod.SelectedMethod != null;
                options.StringOptionSearchForMethod = _frmDeobfMethod.SelectedMethod;

                options.PluginList = _frmDeobfMethod.PluginList;
                options.chkInitLocalVarsChecked = _frmDeobfMethod.InitLocalVars;

                Deobfuscator deobf = new Deobfuscator(options);
                int deobfCount = deobf.DeobfMethod(file, _currentMethod);
                
                if (deobfCount > 0)
                {
                    InitBody(_currentMethod);
                }

                //need to be after InitBody
                _form.SetStatusCount(deobfCount);

            }
            catch (Exception ex)
            {
                SimpleMessage.ShowException(ex);
                InitBody(_currentMethod);
            }
            finally
            {
                if (resolveDirAdded)
                    _form.Host.RemoveAssemblyResolveDir(_form.SourceDir);
                wc.Dispose();
            }
        }
 public virtual void Init()
 {
     if (!IsReady)
     {
         SimpleWaitCursor wc = new SimpleWaitCursor();
         try
         {
             _form.SetStatusText(String.Format("Loading {0} ...", _name));
             Initializing = true;
             InitControls();
             InitAssemblyPath();
         }
         catch
         {
             _form.TabControl.SelectedTab = _form.DetailsTabPage;
             throw;
         }
         finally
         {
             wc.Dispose();
             Initializing = false;
             _form.SetStatusText(null);
         }
     }
 }
        public virtual void InitRichText(object cecilObject)
        {
            rtbText.Clear();

            object o = GetDecompileObject(cecilObject);
            if (o == null) return;

            SimpleWaitCursor wc = new SimpleWaitCursor();
            try
            {
                highlightText = null;
                rtbText.SuspendLayout();
                DecompileObject(o);
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                rtbText.Rtf = GetRtf(ex.Message, ex.StackTrace);
            }
            finally
            {
                rtbText.ResumeLayout();
                wc.Dispose();
            }
        }
        private void AddFiles(string path)
        {
            int saveCurrentRowIndex = -1;
            if (treeView1.SelectedNode != null
                && path == treeView1.SelectedNode.FullPath
                && this.dgvData.CurrentRow != null)
                saveCurrentRowIndex = dgvData.CurrentRow.Index;

            SimpleWaitCursor wc = new SimpleWaitCursor();
            try
            {
                _form.AssemblyDataGridBindingSource.DataSource = null;
                dtFiles.Clear();
                AddFiles(path, "*.dll");
                if (!escPressed) AddFiles(path, "*.exe");
                if (!escPressed) AddFiles(path, "*.netmodule");
                if (!escPressed) AddFiles(path, "*.il");
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (String.IsNullOrEmpty(dtFiles.DefaultView.Sort))
                    dtFiles.DefaultView.Sort = dtFiles.Columns[0].ColumnName;
                _form.AssemblyDataGridBindingSource.DataSource = dtFiles;
                wc.Dispose();
            }

            if (saveCurrentRowIndex >= 0)
            {
                SetCurrentRow(saveCurrentRowIndex);
            }
        }