Esempio n. 1
0
        List <ParsedSection> GetAllSections()
        {
            List <ParsedSection> result = new List <ParsedSection>();
            var hdr     = ELFHeader;
            var strings = StringTable;

            for (int i = 0; i < hdr.e_shnum; i++)
            {
                var shdr = ReadStruct <Elf32_Shdr>((int)(hdr.e_shoff + i * hdr.e_shentsize));

                ParsedSection section = new ParsedSection
                {
                    OffsetInFile    = shdr.sh_offset,
                    Size            = shdr.sh_size,
                    VirtualAddress  = shdr.sh_addr,
                    Type            = (SectionType)shdr.sh_type,
                    HasData         = (shdr.sh_type != (uint)SectionType.SHT_NOBITS),
                    PresentInMemory = (shdr.sh_flags & 2) != 0,
                };

                int eidx;
                for (eidx = (int)shdr.sh_name; eidx < strings.Length; eidx++)
                {
                    if (strings[eidx] == 0)
                    {
                        break;
                    }
                }

                section.SectionName = Encoding.ASCII.GetString(strings, (int)shdr.sh_name, eidx - (int)shdr.sh_name);
                result.Add(section);
            }
            return(result);
        }
Esempio n. 2
0
 public byte[] LoadSection(ParsedSection section)
 {
     if (section == null)
     {
         return(null);
     }
     return(LoadSection((int)section.OffsetInFile, (int)section.Size));
 }
Esempio n. 3
0
 public ParsedSection(ParsedSection section)
 {
     SectionName    = section.SectionName;
     OffsetInFile   = section.OffsetInFile;
     Size           = section.Size;
     VirtualAddress = section.VirtualAddress;
     Type           = section.Type;
     HasData        = section.HasData;
 }
Esempio n. 4
0
        /// <summary>
        /// Parses the given Doxygen comment.
        /// </summary>
        /// <param name="comment">The comment to parse.</param>
        /// <returns>Parsed comment structure.</returns>
        private ParsedComment ParseComment(string comment)
        {
            ParsedComment parsedComment = new ParsedComment();

            if (comment.Length > 0)
            {
                string[] lines = comment.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

                // Trim leading and trailing whitespace before any parsing.
                for (int i = 0; i < lines.Length; ++i)
                {
                    lines[i] = lines[i].Trim();
                }

                for (int i = 0; i < lines.Length; ++i)
                {
                    // Skip empty lines and comment start/end lines.
                    string line = lines[i];

                    if (line.Length == 0 || line == "*" || line == "/*!" || line == "*/")
                    {
                        continue;
                    }

                    // Check if this is a template parameter line.
                    Match tparamMatch = m_regexTParam.Match(line);

                    if (tparamMatch.Success)
                    {
                        string name         = tparamMatch.Groups[1].Value;
                        string firstComment = tparamMatch.Groups[2].Value;

                        if (!parsedComment.TemplateParameters.ContainsKey(name) && firstComment.Length > 0)
                        {
                            ParsedParam param = new ParsedParam();
                            param.Name = name;
                            param.Comments.Add(firstComment);
                            i = ParseExtraComments(lines, i + 1, param.Comments);

                            parsedComment.TemplateParameters.Add(param.Name, param);
                        }
                    }
                    else
                    {
                        // Check if this is a parameter line.
                        Match paramMatch = m_regexParam.Match(line);

                        if (paramMatch.Success)
                        {
                            string name         = paramMatch.Groups[2].Value;
                            string firstComment = paramMatch.Groups[3].Value;

                            if (!parsedComment.Parameters.ContainsKey(name) && firstComment.Length > 0)
                            {
                                ParsedParam param = new ParsedParam();
                                param.Name      = name;
                                param.Direction = ToDirection(paramMatch.Groups[1].Value);
                                param.Comments.Add(firstComment);
                                i = ParseExtraComments(lines, i + 1, param.Comments);

                                parsedComment.Parameters.Add(param.Name, param);
                            }
                        }
                        else
                        {
                            // Otherwise check if it is some other tag.
                            Match sectionMatch = m_regexTagSection.Match(line);

                            if (sectionMatch.Success)
                            {
                                string tagName      = sectionMatch.Groups[1].Value;
                                string firstComment = sectionMatch.Groups[2].Value;

                                if (firstComment.Length > 0)
                                {
                                    ParsedSection section = new ParsedSection();
                                    section.TagName = tagName;
                                    section.Comments.Add(firstComment);
                                    i = ParseExtraComments(lines, i + 1, section.Comments);

                                    if (section.TagName == "return" || section.TagName == "returns")
                                    {
                                        parsedComment.Returns = section;
                                    }
                                    else
                                    {
                                        parsedComment.TagSections.Add(section);
                                    }
                                }
                            }
                            else
                            {
                                // If the line doesn't contain any tag, we try to extract text out of it.
                                Match textMatch = m_regexText.Match(line);

                                if (textMatch.Success)
                                {
                                    parsedComment.BriefComments.Add(textMatch.Groups[1].Value);
                                }
                            }
                        }
                    }
                }
            }

            return(parsedComment);
        }