Exemplo n.º 1
0
        private int FindPositionOfILCodeByOffset(int offset, out string line, out NuGenBaseILCode ilCode)
        {
            int  result        = 0;
            int  codeLineIndex = 0;
            int  lineIndex     = 0;
            bool found         = false;

            line   = string.Empty;
            ilCode = null;

            while (!found && codeLineIndex < CodeObject.CodeLines.Count)
            {
                NuGenCodeLine codeLine = CodeObject.CodeLines[codeLineIndex];
                ilCode = codeLine as NuGenBaseILCode;

                if (ilCode != null && ilCode.Offset >= offset)
                {
                    line  = Lines[lineIndex];
                    found = true;
                }
                else
                {
                    for (int lineNumber = 0; lineNumber < codeLine.TextLineNumber + 1; lineNumber++)
                    {
                        result += Lines[lineIndex].Length + 1;
                        lineIndex++;
                    }
                }

                codeLineIndex++;
            }

            return(result);
        }
Exemplo n.º 2
0
        public void Initialize()
        {
            CodeLines = new List <NuGenCodeLine>();

            StringBuilder definitionBuilder = new StringBuilder(".mresource ");

            if ((Flags & CorManifestResourceFlags.mrPublic) == CorManifestResourceFlags.mrPublic)
            {
                definitionBuilder.Append("public ");
            }
            else
            {
                definitionBuilder.Append("private ");
            }

            definitionBuilder.Append(Name);

            NuGenCodeLine definition = new NuGenCodeLine(0, definitionBuilder.ToString());

            CodeLines.Add(definition);

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

            CodeLines.Add(new NuGenCodeLine(1, string.Format(".file {0} at 0x{1}", Name, NuGenHelperFunctions.FormatAsHexNumber(Offset, 8))));

            CodeLines.Add(new NuGenCodeLine(0, "}"));
        }
Exemplo n.º 3
0
        private NuGenBaseILCode FindILCodeByIndex(int position)
        {
            NuGenBaseILCode result        = null;
            int             lineIndex     = 0;
            int             codeLineIndex = 0;
            bool            found         = false;

            while (!found && codeLineIndex < CodeObject.CodeLines.Count)
            {
                NuGenCodeLine codeLine = CodeObject.CodeLines[codeLineIndex];
                position -= Lines[lineIndex].Length + 1;

                for (int lineNumber = 0; lineNumber < codeLine.TextLineNumber; lineNumber++)
                {
                    lineIndex++;
                    position -= Lines[lineIndex].Length + 1;
                }

                if (position < 0)
                {
                    result = codeLine as NuGenBaseILCode;
                    found  = true;
                }

                lineIndex++;
                codeLineIndex++;
            }

            return(result);
        }
Exemplo n.º 4
0
        public void Initialize()
        {
            CodeLines = new List <NuGenCodeLine>();

            NuGenCodeLine definition = new NuGenCodeLine(0, "file " + Name);

            CodeLines.Add(definition);

            CodeLines.Add(new NuGenCodeLine(0, string.Format(".hash = {0}", NuGenHelperFunctions.ReadBlobAsString(Hash, HashLength))));
        }
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
        protected override void WndProc(ref Message m)
        {
            if (!IsRedrawDisabled || (m.Msg != 0x000F && m.Msg != 0x0014 && m.Msg != 0x0085))
            {
                base.WndProc(ref m);

                if (!DesignMode && m.Msg == 0x000F && CodeObject != null)
                {
                    Point firstCharPosition = GetPositionFromCharIndex(0);

                    if (firstCharPosition.X >= 0)
                    {
                        using (Graphics graphics = CreateGraphics())
                        {
                            Font regularFont           = Font;
                            Font boldFont              = new Font(Font, FontStyle.Bold);
                            Font boldItalicFont        = new Font(Font, FontStyle.Bold | FontStyle.Italic);
                            int  charIndex             = 1;
                            int  firstVisibleCharacter = GetCharIndexFromPosition(new Point(0, 0));
                            int  lastVisibleCharacter  = GetCharIndexFromPosition(new Point(ClientSize.Width, ClientSize.Height));

                            if (lastVisibleCharacter == 0)
                            {
                                lastVisibleCharacter = Text.Length;
                            }

                            for (int ilCodeIndex = 0; ilCodeIndex < CodeObject.CodeLines.Count && charIndex < lastVisibleCharacter; ilCodeIndex++)
                            {
                                NuGenCodeLine codeLine = CodeObject.CodeLines[ilCodeIndex];

                                if (charIndex >= firstVisibleCharacter && charIndex <= lastVisibleCharacter && codeLine is NuGenBaseILCode)
                                {
                                    Point           position = GetPositionFromCharIndex(charIndex);
                                    NuGenBaseILCode ilCode   = (NuGenBaseILCode)codeLine;

                                    Brush brush       = Brushes.Black;
                                    Font  currentFont = regularFont;

                                    graphics.DrawString(ilCode.Address, currentFont, brush, 0 + firstCharPosition.X - SelectionIndent, position.Y);
                                }

                                charIndex += codeLine.Text.Length + 1 + codeLine.Indentation * IndentationSize;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void ShowCodeObject(NuGenIMultiLine codeObject)
        {
            CodeObject = codeObject;
            StringBuilder ilCodeString = new StringBuilder();

            for (int ilCodeIndex = 0; ilCodeIndex < CodeObject.CodeLines.Count; ilCodeIndex++)
            {
                NuGenCodeLine codeLine = CodeObject.CodeLines[ilCodeIndex];
                string        text     = codeLine.Text;

                for (int indentationIndex = 0; indentationIndex < codeLine.Indentation; indentationIndex++)
                {
                    ilCodeString.Append("    ");
                }

                ilCodeString.AppendLine(codeLine.Text);
            }

            ilCodeString = ilCodeString.Replace("\0", string.Empty);
            Text         = ilCodeString.ToString();
        }
Exemplo n.º 8
0
        public void Initialize()
        {
            CodeLines = new List <NuGenCodeLine>();

            StringBuilder definition = new StringBuilder();

            definition.Append(".assembly extern ");
            definition.Append(NuGenHelperFunctions.EnumAsString(Flags, CorAssemblyFlags.afRetargetable, "retargetable "));
            definition.Append(Name);

            NuGenCodeLine definitionLine = new NuGenCodeLine(0, definition.ToString());

            CodeLines.Add(definitionLine);

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

            if (FullPath != null && FullPath.Length > 0)
            {
                CodeLines.Add(new NuGenCodeLine(1, "//Full Path: " + FullPath));
            }
            else
            {
                CodeLines.Add(new NuGenCodeLine(1, "//Full Path: exact location not found. "));
            }

            CodeLines.Add(new NuGenCodeLine(1, ".publickeytoken = " + NuGenHelperFunctions.ReadBlobAsString(PublicKeyOrToken, PublicKeyOrTokenLength)));

            if (HashBlobLength > 0)
            {
                CodeLines.Add(new NuGenCodeLine(1, ".hash = " + NuGenHelperFunctions.ReadBlobAsString(HashBlob, HashBlobLength)));
            }

            CodeLines.Add(new NuGenCodeLine(1, string.Format(".ver {0}:{1}:{2}:{3}", Metadata.usMajorVersion, Metadata.usMinorVersion, Metadata.usBuildNumber, Metadata.usRevisionNumber)));

            CodeLines.Add(new NuGenCodeLine(0, "} //end of assembly reference " + Name));
        }