Example #1
0
    public async Task<bool> ParseFromFile(string filename)
    {
      const Int32 BufferSize = 1024 * 4;
      using (var fileStream = File.OpenRead(filename))
      {
        using (var InputStreamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
        {
          String line;
          while ((line = InputStreamReader.ReadLine()) != null)
          {
            line = line.Substring(line.IndexOf('>') + 1);
            line = line.Trim();
            if (line.Length == 0)
              continue;

            var StartMatch = ClassLayoutStartRegex.Match(line);
            if (StartMatch.Success)
            {
              string DecoratedSymbol = StartMatch.Groups[1].ToString();

              Dbghelp.UnDecorateSymbolName(DecoratedSymbol, UnDecoratedSymbol, UnDecoratedSymbol.Capacity, Dbghelp.UnDecorateFlags.UNDNAME_COMPLETE);
              string ClassSymbol = UnDecoratedSymbol.ToString();

              Int32 ClassSize = Int32.Parse(StartMatch.Groups[2].ToString());

              ClassLayout ClassResult = new ClassLayout();

              // only save the result if its the first time we have seen the name
              if ( !Classes.ContainsKey( ClassSymbol ) )
              {
                ClassResult.Name = ClassSymbol;
                ClassResult.Size = ClassSize;

                Classes.Add( ClassSymbol, ClassResult );
              }

              // consume this layout descriptor
              ParseClass( ClassResult, InputStreamReader );

              await Task.Yield();
            }

          }
        }
      }

      return true;
    }
Example #2
0
        public bool ParseFromFile(string filename)
        {
            const int BufferSize = 1024 * 4;

            using (var fileStream = File.OpenRead(filename))
                using (var InputStreamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize))
                {
                    string line;
                    while ((line = InputStreamReader.ReadLine()) != null)
                    {
                        line = line.Substring(line.IndexOf('>') + 1);
                        line = line.Trim();
                        if (line.Length == 0)
                        {
                            continue;
                        }

                        var startMatch = ClassLayoutStartRegex.Match(line);
                        if (startMatch.Success)
                        {
                            string decoratedSymbol = startMatch.Groups[1].ToString();

                            Dbghelp.UnDecorateSymbolName(decoratedSymbol, UnDecoratedSymbol, UnDecoratedSymbol.Capacity, Dbghelp.UnDecorateFlags.UNDNAME_COMPLETE);
                            string classSymbol = UnDecoratedSymbol.ToString();

                            int classSize = int.Parse(startMatch.Groups[2].ToString());

                            var classResult = new ClassLayout();

                            // only save the result if its the first time we have seen the name
                            if (!Classes.ContainsKey(classSymbol))
                            {
                                classResult.Name = classSymbol;
                                classResult.Size = classSize;

                                Classes.Add(classSymbol, classResult);
                            }

                            // consume this layout descriptor
                            ParseClass(classResult, InputStreamReader);
                        }
                    }
                }

            return(true);
        }
Example #3
0
        void ParseClass(ClassLayout ClassResult, StreamReader InputStreamReader)
        {
            ClassMember previousMemberAlignSkip = null;
            ClassMember previousMember          = null;

            string line;

            while ((line = InputStreamReader.ReadLine()) != null)
            {
                line = line.Substring(line.IndexOf('>') + 1);
                line = line.Trim();

                if (line.Length == 0)
                {
                    break;
                }

                #region ExtractClassMember
                var classMemberMatch = ExtractClassMember.Match(line);
                if (classMemberMatch.Success)
                {
                    string memberOffsetString = classMemberMatch.Groups[1].ToString();
                    int    memberOffset       = int.Parse(memberOffsetString);

                    string memberName = classMemberMatch.Groups[2].ToString().Trim();
                    string memberType = null;

                    if (memberName.IndexOf(' ') > 0)
                    {
                        string[] memberTypeAndName = memberName.Split(' ');
                        string   decMemberType     = memberTypeAndName[0].Trim();
                        memberName = memberTypeAndName[1].Trim();

                        if (Dbghelp.UnDecorateSymbolName(decMemberType, UnDecoratedSymbol, UnDecoratedSymbol.Capacity, Dbghelp.UnDecorateFlags.UNDNAME_COMPLETE) > 0)
                        {
                            memberType = UnDecoratedSymbol.ToString();
                        }
                        else
                        {
                            memberType = decMemberType;
                        }
                    }

                    if (previousMember != null)
                    {
                        if (previousMemberAlignSkip != null)
                        {
                            previousMemberAlignSkip.Size = memberOffset - (previousMemberAlignSkip.Offset + previousMember.Size);
                        }
                        else
                        {
                            previousMember.Size = memberOffset - previousMember.Offset;
                        }
                    }

                    var newMember = new ClassMember()
                    {
                        Type   = memberType,
                        Name   = memberName,
                        Offset = memberOffset,
                    };

                    previousMember          = newMember;
                    previousMemberAlignSkip = null;

                    ClassResult.Members.Add(newMember);
                    continue;
                }
                #endregion

                #region ExtractAlignmentMember
                var AlignmentMemberMatch = ExtractAlignmentMember.Match(line);
                if (AlignmentMemberMatch.Success)
                {
                    string memberSizeString = AlignmentMemberMatch.Groups[1].ToString();
                    int    memberSize       = int.Parse(memberSizeString);

                    var newMember = new ClassMember()
                    {
                        Size = memberSize,
                    };

                    previousMemberAlignSkip = previousMember;
                    previousMember          = newMember;

                    ClassResult.TotalAlignmentEntries++;
                    ClassResult.TotalAlignmentPadding += memberSize;

                    ClassResult.Members.Add(newMember);
                    continue;
                }
                #endregion
            }

            if (previousMember != null && previousMember.Name != null)
            {
                previousMember.Size = ClassResult.Size - previousMember.Offset;
            }
        }
Example #4
0
    internal void ParseClass( ClassLayout ClassResult, StreamReader InputStreamReader )
    {
      ClassMember PreviousMemberAlignSkip = null;
      ClassMember PreviousMember = null;

      String Line;
      while ((Line = InputStreamReader.ReadLine()) != null)
      {
        Line = Line.Substring( Line.IndexOf('>') + 1 );
        Line = Line.Trim();

        if (Line.Length == 0)
          break;

        var ClassMemberMatch      = ExtractClassMember.Match( Line );
        if ( ClassMemberMatch.Success )
        {
          string MemberOffsetString = ClassMemberMatch.Groups[1].ToString();
          Int32 MemberOffset = Int32.Parse(MemberOffsetString);

          string MemberName = ClassMemberMatch.Groups[2].ToString().Trim();
          string MemberType = null;

          if ( MemberName.IndexOf(' ') > 0 )
          {
            string[] MemberTypeAndName = MemberName.Split(' ');
            string DecMemberType = MemberTypeAndName[0].Trim();
            MemberName = MemberTypeAndName[1].Trim();

            if ( Dbghelp.UnDecorateSymbolName(DecMemberType, UnDecoratedSymbol, UnDecoratedSymbol.Capacity, Dbghelp.UnDecorateFlags.UNDNAME_COMPLETE) > 0 )
            {
              MemberType = UnDecoratedSymbol.ToString();
            }
            else
            {
              MemberType = DecMemberType;
            }
          }

          if ( PreviousMember != null )
          {
            if (PreviousMemberAlignSkip != null)
            {
              PreviousMemberAlignSkip.Size = MemberOffset - (PreviousMemberAlignSkip.Offset + PreviousMember.Size);
            }
            else
            {
              PreviousMember.Size = MemberOffset - PreviousMember.Offset;
            }
          }

          ClassMember NewMember = new ClassMember();
          NewMember.Type = MemberType;
          NewMember.Name = MemberName;
          NewMember.Offset = MemberOffset;
          NewMember.Size = -1;

          PreviousMember = NewMember;
          PreviousMemberAlignSkip = null;

          ClassResult.Members.Add(NewMember);
        }

        var AlignmentMemberMatch  = ExtractAlignmentMember.Match( Line );
        if ( AlignmentMemberMatch.Success )
        {
          string MemberSizeString = AlignmentMemberMatch.Groups[1].ToString();
          Int32 MemberSize = Int32.Parse(MemberSizeString);

          ClassMember NewMember = new ClassMember();
          NewMember.Name = null;
          NewMember.Offset = -1;
          NewMember.Size = MemberSize;

          PreviousMemberAlignSkip = PreviousMember;
          PreviousMember = NewMember;

          ClassResult.TotalAlignmentEntries ++;
          ClassResult.TotalAlignmentPadding += MemberSize;

          ClassResult.Members.Add(NewMember);
        }
      }

      if (PreviousMember != null && PreviousMember.Name != null)
      {
        PreviousMember.Size = ClassResult.Size - PreviousMember.Offset;
      }
    }