コード例 #1
0
        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();
            }
        }
コード例 #2
0
        public void InitBody(MethodDefinition md)
        {
            DateTime startTime = DateTime.Now;

            _form.SetStatusText(null);
            _form.SetStatusCount(0);
            _form.ResourceHandler.ShowDetailsControl(ClassEditResourceHandler.DetailTypes.MethodBody);
            SimpleWaitCursor wc = null;

            try
            {
                if (_currentMethod == md)
                {
                    if (dgBody.CurrentRow != null)
                    {
                        _currentRowIndex = dgBody.CurrentRow.Index;
                    }
                    if (dgVariable.CurrentRow != null)
                    {
                        _currentVarIndex = dgVariable.CurrentRow.Index;
                    }
                }

                tabDetails.SuspendLayout();
                dgBody.SuspendLayout();
                dgGeneral.SuspendLayout();

                _dtBody.Rows.Clear();
                _dtGeneral.Rows.Clear();
                _dtVariable.Rows.Clear();

                if (md == null)
                {
                    _currentMethod = null;
                    return;
                }

                _dtBody.BeginLoadData();
                _dtGeneral.BeginLoadData();
                _dtVariable.BeginLoadData();

                if (md.HasBody && md.Body.Instructions.Count > 100)
                {
                    wc = new SimpleWaitCursor();
                }

                _currentMethod = md;

                InitDataTableGeneral(md);
                InitDataTableBody(md);
                InitDataTableVariable(md);

                if (dgBody.DataSource == null)
                    dgBody.DataSource = _dtBody;

                if (dgGeneral.DataSource == null)
                    dgGeneral.DataSource = _dtGeneral;

                if (dgVariable.DataSource == null)
                    dgVariable.DataSource = _dtVariable;

                _dtBody.EndLoadData();
                _dtGeneral.EndLoadData();
                _dtVariable.EndLoadData();

                if (md.HasBody)
                {
                    Collection<ExceptionHandler> ehc = md.Body.ExceptionHandlers;

                    //check invalid exception handler
                    for (int i = dgBody.Rows.Count - 2; i >= 0; i--)
                    {
                        DataGridViewRow row = dgBody.Rows[i];
                        int ehIndex = GetExceptionHandlerIndex(row);
                        if (ehIndex >= 0)
                        {
                            if (!DeobfUtils.IsValidExceptionHandler(ehc[ehIndex]))
                            {
                                row.DefaultCellStyle.ForeColor = Color.Red;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                _form.SearchHandler.LastHighlightIndex = 0;

                if (_markBlocks)
                    MarkBlocks();

                if (_currentRowIndex >= 0)
                {
                    SetCurrentRow(_currentRowIndex);
                    _currentRowIndex = -1;
                }
                if (_currentVarIndex >= 0)
                {
                    SetCurrentVariable(_currentVarIndex);
                    _currentVarIndex = -1;
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                dgBody.ResumeLayout();
                dgGeneral.ResumeLayout();
                tabDetails.ResumeLayout();

                if (wc != null) wc.Dispose();

                if (_currentMethod != null)
                {
                    DateTime endTime = DateTime.Now;
                    _form.SetStatusText(String.Format("{0} (load time: {1} seconds)",
                        _currentMethod.ToString(),
                        (endTime - startTime).TotalSeconds));
                }
            }
        }
コード例 #3
0
 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);
         }
     }
 }
コード例 #4
0
        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();
            }
        }
コード例 #5
0
        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);
            }
        }