Exemplo n.º 1
0
        public void SetBreakpointOnFirstInstruction()
        {
            if (NuGenProject.Instance.StartupAssembly != null)
            {
                bool entryMethodNotFound = false;

                if (NuGenProject.Instance.StartupAssembly.AllTokens.ContainsKey(NuGenProject.Instance.StartupAssembly.EntryPointToken))
                {
                    NuGenMethodDefinition entryMethod = NuGenProject.Instance.StartupAssembly.AllTokens[NuGenProject.Instance.StartupAssembly.EntryPointToken] as NuGenMethodDefinition;

                    if (entryMethod == null)
                    {
                        entryMethodNotFound = true;
                    }
                    else
                    {
                        NuGenBreakpointHandler.Instance.RunToCursor(entryMethod, 0, false);
                        RunDebuggee();
                    }
                }
                else
                {
                    entryMethodNotFound = true;
                }

                if (entryMethodNotFound)
                {
                    NuGenUIHandler.Instance.DisplayUserWarning("The entry method is not found in the startup assembly.");
                }
            }
        }
Exemplo n.º 2
0
 private void RefreshBreakpoints(NuGenMethodDefinition methodDefinition)
 {
     foreach (NuGenFunctionBreakpointInformation functionBreakpoint in NuGenProject.Instance.FunctionBreakpoints)
     {
         if (functionBreakpoint.MethodDefinition == methodDefinition)
         {
             RefreshBreakpoint(functionBreakpoint);
         }
     }
 }
Exemplo n.º 3
0
        private void RefreshControl(bool forceFormatRefresh, bool keepScrollPosition)
        {
            DisableRedraw();
            bool isFormattingCleared = false;
            NuGenMethodDefinition methodDefinition = CodeObject as NuGenMethodDefinition;
            bool  displayBreakpoints    = (methodDefinition != null && NuGenProject.Instance.HasBreakpointsInMethod(methodDefinition));
            bool  displaySpecialLines   = (SpecialLines.Count > 0);
            Point scrollPosition        = new Point();
            int   selectionStart        = 0;
            int   selectionLength       = 0;
            bool  restoreScrollPosition = true;

            if (keepScrollPosition && (forceFormatRefresh || displayBreakpoints || displaySpecialLines))
            {
                scrollPosition  = GetScrollPosition();
                selectionStart  = SelectionStart;
                selectionLength = SelectionLength;
                SelectAll();
                SetColor(DefaultLine.BackColor);
                isFormattingCleared = true;
            }

            if (displaySpecialLines)
            {
                int newSelectionStart = RefreshSpecialLines();

                if (newSelectionStart >= 0)
                {
                    selectionStart        = newSelectionStart;
                    selectionLength       = 0;
                    restoreScrollPosition = false;
                }
            }

            if (displayBreakpoints)
            {
                RefreshBreakpoints(methodDefinition);
            }

            if (keepScrollPosition && (forceFormatRefresh || displayBreakpoints || displaySpecialLines))
            {
                SelectionStart  = selectionStart;
                SelectionLength = selectionLength;

                if (restoreScrollPosition)
                {
                    SetScrollPosition(scrollPosition);
                }
            }

            RefreshCurrentLine(isFormattingCleared, keepScrollPosition);

            EnableRedraw();
            Refresh();
        }
Exemplo n.º 4
0
 public NuGenParameter(NuGenIMetaDataImport2 import, Dictionary <uint, NuGenTokenBase> allTokens, uint token, NuGenMethodDefinition method, uint ordinalIndex, string name, uint attributeFlags, uint elementType, IntPtr defaultValue, uint defaultValueLength)
 {
     Token              = token;
     Method             = method;
     OrdinalIndex       = ordinalIndex;
     Name               = name;
     AttributeFlags     = (CorParamAttr)attributeFlags;
     ElementType        = (CorElementType)elementType;
     DefaultValue       = defaultValue;
     DefaultValueLength = defaultValueLength;
     ReadDefaultValue();
 }
Exemplo n.º 5
0
        public void Initialize()
        {
            ReadMetadata();
            NuGenAssembly assembly = BaseTypeDefinition.ModuleScope.Assembly;

            CodeLines = new List <NuGenCodeLine>();
            NuGenCodeLine definitionLine = new NuGenCodeLine();

            definitionLine.Indentation = 0;

            CodeLines.Add(definitionLine);
            CodeLines.Add(new NuGenCodeLine(0, "{"));

            if (CustomAttributes != null)
            {
                foreach (NuGenCustomAttribute customAttribute in CustomAttributes)
                {
                    customAttribute.SetText(assembly.AllTokens);
                    CodeLines.Add(new NuGenCodeLine(1, customAttribute.Name));
                }
            }

            if (assembly.AllTokens.ContainsKey(GetterMethodToken))
            {
                NuGenMethodDefinition getMethod = (NuGenMethodDefinition)assembly.AllTokens[GetterMethodToken];
                CodeLines.Add(new NuGenCodeLine(1, ".get " + getMethod.Text));
            }

            for (int index = 0; index < OtherMethodsCount; index++)
            {
                uint token = OtherMethods[index];

                if (assembly.AllTokens.ContainsKey(token))
                {
                    NuGenMethodDefinition otherMethod = (NuGenMethodDefinition)assembly.AllTokens[token];
                    CodeLines.Add(new NuGenCodeLine(1, ".other " + otherMethod.Text));
                }
            }

            if (assembly.AllTokens.ContainsKey(SetterMethodToken))
            {
                NuGenMethodDefinition setMethod = (NuGenMethodDefinition)assembly.AllTokens[setterMethodToken];
                CodeLines.Add(new NuGenCodeLine(1, ".set " + setMethod.Text));
            }

            Definition          = ".property " + Definition;
            definitionLine.Text = Definition;

            CodeLines.Add(new NuGenCodeLine(0, string.Format("}} //end of property {0}::{1}", BaseTypeDefinition.Name, Name)));
        }
Exemplo n.º 6
0
        public void SetRunToCursorAtSelection()
        {
            NuGenMethodDefinition methodDefinition = CodeObject as NuGenMethodDefinition;

            if (methodDefinition != null)
            {
                NuGenBaseILCode ilCode = FindILCodeByIndex(SelectionStart);

                if (ilCode != null)
                {
                    NuGenBreakpointHandler.Instance.RunToCursor(methodDefinition, ilCode.Offset, false);
                }
            }
        }
Exemplo n.º 7
0
        public bool HasBreakpointsInMethod(NuGenMethodDefinition methodDefinition)
        {
            bool result = false;
            int  index  = 0;

            while (!result && index < FunctionBreakpoints.Count)
            {
                NuGenFunctionBreakpointInformation functionBreakpoint = FunctionBreakpoints[index++];

                if (functionBreakpoint.MethodDefinition == methodDefinition)
                {
                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 8
0
        public NuGenFunctionBreakpointInformation FindFunctionBreakpoint(NuGenMethodDefinition methodDefinition, uint offset)
        {
            NuGenFunctionBreakpointInformation result = null;
            int index = 0;

            while (result == null && index < NuGenProject.Instance.FunctionBreakpoints.Count)
            {
                NuGenFunctionBreakpointInformation functionBreakpoint = NuGenProject.Instance.FunctionBreakpoints[index++];

                if (functionBreakpoint.MethodDefinition == methodDefinition && functionBreakpoint.Offset == offset)
                {
                    result = functionBreakpoint;
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        public void SetBreakpointAtSelection()
        {
            NuGenMethodDefinition methodDefinition = CodeObject as NuGenMethodDefinition;

            if (methodDefinition != null)
            {
                NuGenBaseILCode ilCode = FindILCodeByIndex(SelectionStart);

                if (ilCode != null)
                {
                    NuGenFunctionBreakpointInformation breakpointInformation = NuGenBreakpointHandler.Instance.AddRemoveBreakpoint(methodDefinition, ilCode.Offset, false);

                    if (breakpointInformation != null)
                    {
                        UpdateBreakpoint(breakpointInformation);
                        NuGenProject.Instance.IsSaved = false;
                    }
                }
            }
        }
Exemplo n.º 10
0
        public override void DecodeParameter()
        {
            if (DecodedParameter is NuGenMethodDefinition)
            {
                NuGenMethodDefinition methodDefinition = (NuGenMethodDefinition)DecodedParameter;

                Text = string.Format("{0} {1}", OpCode.Name, methodDefinition.Text);
            }
            else if (DecodedParameter is NuGenMemberReference)
            {
                NuGenMemberReference memberReference = (NuGenMemberReference)DecodedParameter;

                Text = string.Format("{0} {1}", OpCode.Name, memberReference.Text);
            }
            else if (DecodedParameter is NuGenMethodSpec)
            {
                NuGenMethodSpec methodSpec = (NuGenMethodSpec)DecodedParameter;

                Text = string.Format("{0} {1}", OpCode.Name, methodSpec.Name);
            }
        }
Exemplo n.º 11
0
        private void contextMenu_Opening(object sender, CancelEventArgs e)
        {
            setIPToolStripMenuItem.Visible = false;

            if (NuGenDebugEventHandler.Instance.EventObjects.Frame != null && NuGenDebugEventHandler.Instance.EventObjects.Frame.IsActiveFrame && CurrentLine != null)
            {
                NuGenMethodDefinition displayedMethod = CodeObject as NuGenMethodDefinition;

                if (displayedMethod != null)
                {
                    FunctionWrapper currentFunction      = NuGenDebugEventHandler.Instance.EventObjects.Frame.GetFunction();
                    uint            currentFunctionToken = currentFunction.GetToken();

                    if (displayedMethod.Token == currentFunctionToken)
                    {
                        ModuleWrapper currentModule           = currentFunction.GetModule();
                        bool          isInMemoryCurrentModule = currentModule.IsInMemory();
                        string        currentModuleName       = string.Empty;

                        if (isInMemoryCurrentModule)
                        {
                            currentModuleName = currentModule.GetNameFromMetaData();
                        }
                        else
                        {
                            currentModuleName = currentModule.GetName();

                            try
                            {
                                currentModuleName = Path.GetFileNameWithoutExtension(currentModuleName);
                            }
                            catch
                            {
                            }
                        }

                        currentModuleName = currentModuleName.ToLower();

                        if ((isInMemoryCurrentModule && displayedMethod.BaseTypeDefinition.ModuleScope.Name.ToLower() == currentModuleName) || (!isInMemoryCurrentModule && Path.GetFileNameWithoutExtension(displayedMethod.BaseTypeDefinition.ModuleScope.Assembly.FullPath).ToLower() == currentModuleName))
                        {
                            NuGenBaseILCode currentILCode = ilEditor.GetILCodeAtMouseCursor();
                            setIPToolStripMenuItem.Visible = true;

                            if (currentILCode != null)
                            {
                                int hResult = NuGenDebugEventHandler.Instance.EventObjects.Frame.CanSetIP(Convert.ToUInt32(currentILCode.Offset));

                                if (hResult == 0)
                                {
                                    setIPToolStripMenuItem.Enabled = true;
                                    setIPToolStripMenuItem.Tag     = currentILCode;
                                }
                                else
                                {
                                    COMException comException = Marshal.GetExceptionForHR(hResult) as COMException;

                                    if (comException != null)
                                    {
                                        NuGenUIHandler.Instance.DisplayUserWarning(Marshal.GetExceptionForHR(hResult).Message);
                                    }

                                    setIPToolStripMenuItem.Enabled = false;
                                }
                            }
                            else
                            {
                                setIPToolStripMenuItem.Enabled = false;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
        private static TreeNode SearchNodes(TreeNode parentNode, NuGenTokenBase tokenObject)
        {
            TreeNode result = null;

            if (parentNode != null)
            {
                switch (tokenObject.ItemType)
                {
                case SearchOptions.Assembly:
                    NuGenAssembly assembly = (NuGenAssembly)tokenObject;
                    parentNode.Expand();
                    result = FindNodeByName(parentNode.Nodes, assembly.FileName);
                    break;

                case SearchOptions.AssemblyReference:
                    NuGenAssemblyReference assemblyReference = (NuGenAssemblyReference)tokenObject;

                    result = SearchTokenNode(parentNode, assemblyReference.Assembly, " References", assemblyReference.Name);
                    break;

                case SearchOptions.FieldDefintion:
                    NuGenFieldDefinition fieldDefinition = (NuGenFieldDefinition)tokenObject;

                    result = SearchTokenNode(parentNode, fieldDefinition.BaseTypeDefinition, "Fields", fieldDefinition.Name);
                    break;

                case SearchOptions.File:
                    NuGenFile file = (NuGenFile)tokenObject;

                    result = SearchTokenNode(parentNode, file.Assembly, " Files", file.Name);
                    break;

                case SearchOptions.ManifestResource:
                    NuGenManifestResource manifestResource = (NuGenManifestResource)tokenObject;

                    result = SearchTokenNode(parentNode, manifestResource.Assembly, " Manifest Resources", manifestResource.Name);
                    break;

                case SearchOptions.MethodDefinition:
                    NuGenMethodDefinition methodDefinition = (NuGenMethodDefinition)tokenObject;

                    if (methodDefinition.OwnerProperty == null)
                    {
                        result = SearchTokenNode(parentNode, methodDefinition.BaseTypeDefinition, "Methods", methodDefinition.DisplayName);
                    }
                    else
                    {
                        result = SearchNodes(parentNode, methodDefinition.OwnerProperty);
                        result.Expand();
                        result = FindNodeByName(result.Nodes, methodDefinition.DisplayName);
                    }
                    break;

                case SearchOptions.ModuleReference:
                    NuGenModuleReference moduleReference = (NuGenModuleReference)tokenObject;

                    result = SearchTokenNode(parentNode, moduleReference.Assembly, " Module References", moduleReference.Name);
                    break;

                case SearchOptions.ModuleScope:
                    NuGenModuleScope moduleScope = (NuGenModuleScope)tokenObject;

                    result = SearchTokenNode(parentNode, moduleScope.Assembly, null, moduleScope.Name);
                    break;

                case SearchOptions.Property:
                    NuGenProperty property = (NuGenProperty)tokenObject;

                    result = SearchTokenNode(parentNode, property.BaseTypeDefinition, "Properties", property.Name);
                    break;

                case SearchOptions.TypeDefinition:
                    NuGenTypeDefinition typeDefinition = (NuGenTypeDefinition)tokenObject;
                    string typeNamespace = typeDefinition.Namespace;

                    if (typeNamespace.Length == 0)
                    {
                        typeNamespace = NuGenConstants.DefaultNamespaceName;
                    }

                    result = SearchTokenNode(parentNode, typeDefinition.ModuleScope, typeNamespace, typeDefinition.FullName);
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 13
0
        public void DisplayCallStack(List <FrameWrapper> callStack)
        {
            if (callStack != null)
            {
                callStackView.BeginUpdate();
                callStackView.Items.Clear();

                for (int index = 0; index < callStack.Count; index++)
                {
                    FrameWrapper    frame           = callStack[index];
                    ListViewItem    item            = new ListViewItem();
                    bool            isCodeAvailable = false;
                    FunctionWrapper function        = null;

                    try
                    {
                        function        = frame.GetFunction();
                        isCodeAvailable = true;
                    }
                    catch (COMException comException)
                    {
                        //0x80131309 == CORDBG_E_CODE_NOT_AVAILABLE
                        if ((uint)comException.ErrorCode == 0x80131309)
                        {
                            isCodeAvailable = false;
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (isCodeAvailable)
                    {
                        ModuleWrapper module        = function.GetModule();
                        uint          functionToken = function.GetToken();

                        NuGenTokenBase        tokenObject      = NuGenHelperFunctions.FindObjectByToken(functionToken, module);
                        NuGenMethodDefinition methodDefinition = tokenObject as NuGenMethodDefinition;

                        if (methodDefinition != null)
                        {
                            bool activeFrame = (index == 0);
                            NuGenFrameInformation frameInformation = new NuGenFrameInformation(NuGenDebugEventHandler.Instance.EventObjects.Thread, methodDefinition, activeFrame, frame);
                            item.Tag  = frameInformation;
                            item.Text = string.Format("{0}::{1}", methodDefinition.BaseTypeDefinition.FullName, methodDefinition.DisplayName);

                            if (!frameInformation.IsExactLocation)
                            {
                                item.Text += " - not exact offset";
                            }
                        }
                        else
                        {
                            string moduleName = module.GetName();

                            if (module.IsInMemory())
                            {
                                item.Tag = new NuGenMissingModule(module);
                            }
                            else
                            {
                                item.Tag = new NuGenMissingModule(moduleName);
                            }

                            item.Text = "Unknown method (perhaps a reference is not loaded). Module name: " + moduleName;
                        }
                    }

                    if (!frame.IsILFrame())
                    {
                        if (isCodeAvailable)
                        {
                            item.Text = "Native frame, IP offset is not available (" + item.Text + ")";
                        }
                        else
                        {
                            item.Text = "Native frame, IP offset is not available (code is unavailable).";
                        }
                    }

                    item.ToolTipText = item.Text;
                    callStackView.Items.Add(item);
                }

                callStackView.EndUpdate();
            }
        }
Exemplo n.º 14
0
        private static void CreateTypeDefinitionSubnodes(NuGenTypeDefinition typeDefinition, TreeNode typeDefinitionNode)
        {
            NuGenAssembly assembly = typeDefinition.ModuleScope.Assembly;

            typeDefinition.LazyInitialize(assembly.AllTokens);
            Dictionary <uint, NuGenMethodDefinition> methodDefinitions = null;

            if (typeDefinition.MethodDefinitions != null)
            {
                methodDefinitions = new Dictionary <uint, NuGenMethodDefinition>(typeDefinition.MethodDefinitions);
            }

            if (typeDefinition.FieldDefinitions != null)
            {
                TreeNode fieldsNode = new TreeNode("Fields");
                fieldsNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(fieldsNode);

                foreach (NuGenFieldDefinition field in typeDefinition.FieldDefinitions.Values)
                {
                    field.LazyInitialize(assembly.AllTokens);
                    TreeNode fieldNode = new TreeNode(NuGenHelperFunctions.TruncateText(field.Name));
                    fieldNode.Tag        = field;
                    fieldNode.ImageIndex = 10;
                    fieldsNode.Nodes.Add(fieldNode);
                }
            }

            if (typeDefinition.Properties != null)
            {
                TreeNode propertiesNode = new TreeNode("Properties");
                propertiesNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(propertiesNode);

                foreach (NuGenProperty property in typeDefinition.Properties.Values)
                {
                    property.LazyInitialize(assembly.AllTokens);
                    TreeNode propertyNode = new TreeNode(NuGenHelperFunctions.TruncateText(property.Name));
                    propertyNode.ImageIndex = 11;
                    propertiesNode.Nodes.Add(propertyNode);

                    TreeNode definitionNode = new TreeNode(" definition");
                    definitionNode.Tag        = property;
                    definitionNode.ImageIndex = 2;
                    propertyNode.Nodes.Add(definitionNode);

                    if (methodDefinitions != null)
                    {
                        if (methodDefinitions.ContainsKey(property.GetterMethodToken))
                        {
                            NuGenMethodDefinition getterMethod = methodDefinitions[property.GetterMethodToken];
                            getterMethod.LazyInitialize(assembly.AllTokens);

                            TreeNode getterNode = new TreeNode(NuGenHelperFunctions.TruncateText(getterMethod.DisplayName));
                            getterNode.ImageIndex = 10;
                            getterNode.Tag        = getterMethod;
                            propertyNode.Nodes.Add(getterNode);

                            methodDefinitions.Remove(property.GetterMethodToken);
                        }

                        if (methodDefinitions.ContainsKey(property.SetterMethodToken))
                        {
                            NuGenMethodDefinition setterMethod = methodDefinitions[property.SetterMethodToken];
                            setterMethod.LazyInitialize(assembly.AllTokens);

                            TreeNode setterNode = new TreeNode(NuGenHelperFunctions.TruncateText(setterMethod.DisplayName));
                            setterNode.ImageIndex = 10;
                            setterNode.Tag        = setterMethod;
                            propertyNode.Nodes.Add(setterNode);

                            methodDefinitions.Remove(property.SetterMethodToken);
                        }

                        for (int index = 0; index < property.OtherMethodsCount; index++)
                        {
                            uint token = property.OtherMethods[index];

                            if (methodDefinitions.ContainsKey(token))
                            {
                                NuGenMethodDefinition otherMethod = methodDefinitions[token];
                                otherMethod.LazyInitialize(assembly.AllTokens);

                                TreeNode otherNode = new TreeNode(NuGenHelperFunctions.TruncateText(otherMethod.DisplayName));
                                otherNode.ImageIndex = 10;
                                otherNode.Tag        = otherMethod;
                                propertyNode.Nodes.Add(otherNode);

                                methodDefinitions.Remove(token);
                            }
                        }
                    }
                }
            }

            if (methodDefinitions != null && methodDefinitions.Count > 0)
            {
                TreeNode methodsNode = new TreeNode("Methods");
                methodsNode.ImageIndex = 9;
                typeDefinitionNode.Nodes.Add(methodsNode);

                foreach (NuGenMethodDefinition method in methodDefinitions.Values)
                {
                    method.LazyInitialize(assembly.AllTokens);
                    TreeNode methodNode = new TreeNode(NuGenHelperFunctions.TruncateText(method.DisplayName));
                    methodNode.ImageIndex = 12;
                    methodNode.Tag        = method;
                    methodsNode.Nodes.Add(methodNode);
                }
            }
        }
Exemplo n.º 15
0
 private void ValueDisplayer_ToStringEvaluated(NuGenValueDisplayer sender, NuGenMethodDefinition toStringMethodDef, NuGenIValueFormatter toStringValueFormatter)
 {
     InvokeDisplayValueFormatter(toStringValueFormatter, sender.ParentNode);
     InvokeStepEvaluationProgress();
     UpdateCancelEvaluation(sender);
 }