Пример #1
0
        public static DebugNativeEntry[] From(BinaryReader rd, SmxNameTable names)
        {
            var header = new DebugNativesHeader();

            header.num_entries = rd.ReadUInt32();
            return(DebugNativeEntry.From(rd, header, names));
        }
Пример #2
0
        public SmxTagTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header)
        {
            var tags = TagEntry.From(file.SectionReader(header), header, names);

            tags_ = new Tag[tags.Length];
            for (var i = 0; i < tags.Length; i++)
            {
                tags_[i] = new Tag(tags[i]);
            }
        }
Пример #3
0
        public SmxDebugSymbols(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Entries = new DebugVarEntry[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                Entries[i] = DebugVarEntry.From(reader, i);
            }
        }
Пример #4
0
        public SmxRttiTypesetTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Typesets = new RttiTypeset[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                int index = reader.ReadInt32();
                Typesets[i].name      = names.StringAt(index);
                Typesets[i].signature = reader.ReadInt32();
            }
        }
Пример #5
0
        public SmxRttiMethodTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Methods = new RttiMethod[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                int index = reader.ReadInt32();
                Methods[i].name        = names.StringAt(index);
                Methods[i].pcode_start = reader.ReadInt32();
                Methods[i].pcode_end   = reader.ReadInt32();
                Methods[i].signature   = reader.ReadInt32();
            }
        }
Пример #6
0
        public SmxRttiEnumStructTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Entries = new RttiEnumStruct[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                Entries[i]             = new RttiEnumStruct();
                Entries[i].name_offset = reader.ReadInt32();
                Entries[i].first_field = reader.ReadInt32();
                Entries[i].size        = reader.ReadInt32();
                Entries[i].name        = names.StringAt(Entries[i].name_offset);
            }
        }
Пример #7
0
        public SmxRttiFieldTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Fields = new RttiField[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                Fields[i]             = new RttiField();
                Fields[i].flags       = reader.ReadInt16();
                Fields[i].name_offset = reader.ReadInt32();
                Fields[i].type_id     = reader.ReadInt32();
                Fields[i].name        = names.StringAt(Fields[i].name_offset);
            }
        }
Пример #8
0
        public static NativeEntry[] From(BinaryReader rd, SectionEntry header, SmxNameTable names)
        {
            if (header.Size % Size != 0)
            {
                throw new Exception("invalid native table size");
            }
            var count   = header.Size / Size;
            var entries = new NativeEntry[count];

            for (var i = 0; i < count; i++)
            {
                var entry = new NativeEntry();
                entry.nameoffs = rd.ReadInt32();
                entry.Name     = names.StringAt(entry.nameoffs);
                entries[i]     = entry;
            }
            return(entries);
        }
Пример #9
0
        public SmxRttiEnumTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Enums = new string[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                int index = reader.ReadInt32();
                Enums[i] = names.StringAt(index);
                // reserved0-2.
                reader.ReadInt32();
                reader.ReadInt32();
                reader.ReadInt32();
            }
        }
Пример #10
0
        public static DebugNativeArgEntry[] From(BinaryReader rd, SmxNameTable names, int count)
        {
            var entries = new DebugNativeArgEntry[count];

            for (var i = 0; i < count; i++)
            {
                var entry = new DebugNativeArgEntry();
                entry.Ident    = (SymKind)rd.ReadByte();
                entry.tagid    = rd.ReadUInt16();
                entry.dimcount = rd.ReadUInt16();
                entry.nameoffs = rd.ReadInt32();
                if (entry.dimcount > 0)
                {
                    entry.Dims = DebugSymbolDimEntry.From(null, rd, entry.dimcount);
                }
                entry.Name = names.StringAt(entry.nameoffs);
                entries[i] = entry;
            }
            return(entries);
        }
Пример #11
0
        public SmxRttiClassDefTable(FileHeader file, SectionEntry header, SmxNameTable names)
            : base(file, header, names)
        {
            var reader = file.SectionReader(header);

            base.init(reader);

            Defs = new RttiClassDef[row_count_];
            for (uint i = 0; i < row_count_; i++)
            {
                Defs[i]             = new RttiClassDef();
                Defs[i].flags       = reader.ReadInt32();
                Defs[i].name_offset = reader.ReadInt32();
                Defs[i].first_field = reader.ReadInt32();
                Defs[i].name        = names.StringAt(Defs[i].name_offset);
                // reserved0-3
                reader.ReadInt32();
                reader.ReadInt32();
                reader.ReadInt32();
                reader.ReadInt32();
            }
        }
Пример #12
0
 public SmxDebugSymbolsTable(FileHeader file, SectionEntry header, SmxDebugInfoSection info, SmxNameTable names)
     : base(file, header)
 {
     entries_ = DebugSymbolEntry.From(file, file.SectionReader(header), info, names);
 }
Пример #13
0
 public SmxDebugNativesTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     entries_ = DebugNativesHeader.From(file.SectionReader(header), names);
 }
Пример #14
0
 public SmxTagTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     var tags = TagEntry.From(file.SectionReader(header), header, names);
     tags_ = new Tag[tags.Length];
     for (var i = 0; i < tags.Length; i++)
         tags_[i] = new Tag(tags[i]);
 }
Пример #15
0
 public SmxPubvarTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     pubvars_ = PubvarEntry.From(file.SectionReader(header), header, names);
 }
Пример #16
0
        public static DebugNativeEntry[] From(BinaryReader rd, DebugNativesHeader header, SmxNameTable names)
        {
            var entries = new DebugNativeEntry[header.num_entries];

            for (var i = 0; i < header.num_entries; i++)
            {
                var entry = new DebugNativeEntry();
                entry.Index    = rd.ReadInt32();
                entry.nameoffs = rd.ReadInt32();
                entry.tagid    = rd.ReadUInt16();
                entry.nargs    = rd.ReadUInt16();
                entry.Name     = names.StringAt(entry.nameoffs);
                if (entry.nargs > 0)
                {
                    entry.Args = DebugNativeArgEntry.From(rd, names, entry.nargs);
                }
                else
                {
                    entry.Args = new DebugNativeArgEntry[0];
                }
                entries[i] = entry;
            }
            return(entries);
        }
Пример #17
0
 public static PublicEntry[] From(BinaryReader rd, SectionEntry header, SmxNameTable names)
 {
     if (header.Size % Size != 0)
         throw new Exception("invalid public table size");
     var count = header.Size / Size;
     var entries = new PublicEntry[count];
     for (var i = 0; i < count; i++)
     {
         var entry = new PublicEntry();
         entry.Address = rd.ReadUInt32();
         entry.nameoffs = rd.ReadInt32();
         entry.Name = names.StringAt(entry.nameoffs);
         entries[i] = entry;
     }
     return entries;
 }
Пример #18
0
 public static DebugNativeArgEntry[] From(BinaryReader rd, SmxNameTable names, int count)
 {
     var entries = new DebugNativeArgEntry[count];
     for (var i = 0; i < count; i++)
     {
         var entry = new DebugNativeArgEntry();
         entry.Ident = (SymKind)rd.ReadByte();
         entry.tagid = rd.ReadUInt16();
         entry.dimcount = rd.ReadUInt16();
         entry.nameoffs = rd.ReadInt32();
         if (entry.dimcount > 0)
             entry.Dims = DebugSymbolDimEntry.From(null, rd, entry.dimcount);
         entry.Name = names.StringAt(entry.nameoffs);
         entries[i] = entry;
     }
     return entries;
 }
Пример #19
0
 public static DebugNativeEntry[] From(BinaryReader rd, DebugNativesHeader header, SmxNameTable names)
 {
     var entries = new DebugNativeEntry[header.num_entries];
     for (var i = 0; i < header.num_entries; i++)
     {
         var entry = new DebugNativeEntry();
         entry.Index = rd.ReadInt32();
         entry.nameoffs = rd.ReadInt32();
         entry.tagid = rd.ReadUInt16();
         entry.nargs = rd.ReadUInt16();
         entry.Name = names.StringAt(entry.nameoffs);
         if (entry.nargs > 0)
             entry.Args = DebugNativeArgEntry.From(rd, names, entry.nargs);
         else
             entry.Args = new DebugNativeArgEntry[0];
         entries[i] = entry;
     }
     return entries;
 }
Пример #20
0
        public SmxFile(BinaryReader br)
        {
            Header = FileHeader.From(br);

            // Parse precursor sections.
            foreach (var section in Header.Sections)
            {
                if (section.Name == ".names")
                {
                    Names = new SmxNameTable(Header, section);
                }
                else if (section.Name == ".dbg.strings")
                {
                    DebugNames = new SmxNameTable(Header, section);
                }
                else if (section.Name == ".dbg.info")
                {
                    DebugInfo = new SmxDebugInfoSection(Header, section);
                }
            }

            // Parse out other sections.
            var unknown = new List <SectionEntry>();

            foreach (var section in Header.Sections)
            {
                switch (section.Name)
                {
                case ".names":
                case ".dbg.strings":
                case ".dbg.info":
                    break;

                case ".natives":
                    Natives = new SmxNativeTable(Header, section, Names);
                    break;

                case ".publics":
                    Publics = new SmxPublicTable(Header, section, Names);
                    break;

                case ".pubvars":
                    Pubvars = new SmxPubvarTable(Header, section, Names);
                    break;

                case ".tags":
                    Tags = new SmxTagTable(Header, section, Names);
                    break;

                case ".data":
                    Data = new SmxDataSection(Header, section);
                    break;

                case ".code":
                    CodeV1 = new SmxCodeV1Section(Header, section);
                    break;

                case ".dbg.files":
                    DebugFiles = new SmxDebugFilesTable(Header, section, DebugNames);
                    break;

                case ".dbg.lines":
                    DebugLines = new SmxDebugLinesTable(Header, section);
                    break;

                case ".dbg.natives":
                    DebugNatives = new SmxDebugNativesTable(Header, section, DebugNames);
                    break;

                case ".dbg.symbols":
                    DebugSymbols = new SmxDebugSymbolsTable(Header, section, DebugInfo, DebugNames);
                    break;

                default:
                    unknown.Add(section);
                    break;
                }
            }
            UnknownSections = unknown.ToArray();
        }
Пример #21
0
        public static DebugSymbolEntry[] From(FileHeader hdr, BinaryReader rd, SmxDebugInfoSection info, SmxNameTable names)
        {
            var entries = new DebugSymbolEntry[info.NumSymbols];

            for (var i = 0; i < info.NumSymbols; i++)
            {
                var entry = new DebugSymbolEntry();
                entry.Address = rd.ReadInt32();
                entry.TagId   = rd.ReadUInt16();
                // There's a padding of 2 bytes after this short.
                if (hdr.debugUnpacked)
                {
                    rd.ReadBytes(2);
                }
                entry.CodeStart = rd.ReadUInt32();
                entry.CodeEnd   = rd.ReadUInt32();
                entry.Ident     = (SymKind)rd.ReadByte();
                entry.Scope     = (SymScope)rd.ReadByte();
                entry.dimcount  = rd.ReadUInt16();
                entry.nameoffs  = rd.ReadInt32();
                entry.Name      = names.StringAt(entry.nameoffs);
                if (entry.dimcount > 0)
                {
                    entry.Dims = DebugSymbolDimEntry.From(hdr, rd, entry.dimcount);
                }
                entries[i] = entry;
            }
            return(entries);
        }
Пример #22
0
 public SmxPubvarTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     pubvars_ = PubvarEntry.From(file.SectionReader(header), header, names);
 }
Пример #23
0
 public SmxNativeTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     natives_ = NativeEntry.From(file.SectionReader(header), header, names);
 }
Пример #24
0
 public SmxDebugSymbolsTable(FileHeader file, SectionEntry header, SmxDebugInfoSection info, SmxNameTable names)
     : base(file, header)
 {
     entries_ = DebugSymbolEntry.From(file, file.SectionReader(header), info, names);
 }
Пример #25
0
 private void renderNamesList(TreeNode root, SmxNameTable names)
 {
     root.Tag = new NodeData(delegate()
     {
         renderSectionHeaderDetail(names.SectionHeader);
         foreach (var offset in names.Extents)
         {
             addDetailLine("0x{0:x}: {1}", offset, names.StringAt(offset));
         }
         endDetailUpdate();
     }, null);
 }
Пример #26
0
 public SmxRttiListTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     var reader = file.SectionReader(header);
 }
Пример #27
0
 public SmxNativeTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     natives_ = NativeEntry.From(file.SectionReader(header), header, names);
 }
Пример #28
0
 public SmxDebugFilesTable(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header)
 {
     entries_ = DebugFileEntry.From(file.SectionReader(header), header, names);
 }
Пример #29
0
        public SmxFile(BinaryReader br)
        {
            Header = FileHeader.From(br);

            // Parse precursor sections.
            foreach (var section in Header.Sections)
            {
                if (section.Name == ".names")
                {
                    Names = new SmxNameTable(Header, section);
                }
                else if (section.Name == ".dbg.strings")
                {
                    DebugNames = new SmxNameTable(Header, section);
                }
                else if (section.Name == ".dbg.info")
                {
                    DebugInfo = new SmxDebugInfoSection(Header, section);
                }
            }

            CalledFunctions = new SmxCalledFunctionsTable();

            // .dbg.names was removed when RTTI was added.
            if (DebugNames == null)
            {
                DebugNames = Names;
            }

            // Parse out other sections.
            var unknown = new List <SectionEntry>();

            foreach (var section in Header.Sections)
            {
                try
                {
                    switch (section.Name)
                    {
                    case ".names":
                    case ".dbg.strings":
                    case ".dbg.info":
                        break;

                    case ".natives":
                        Natives = new SmxNativeTable(Header, section, Names);
                        break;

                    case ".publics":
                        Publics = new SmxPublicTable(Header, section, Names);
                        break;

                    case ".pubvars":
                        Pubvars = new SmxPubvarTable(Header, section, Names);
                        break;

                    case ".tags":
                        Tags = new SmxTagTable(Header, section, Names);
                        break;

                    case ".data":
                        Data = new SmxDataSection(Header, section);
                        break;

                    case ".code":
                        CodeV1 = new SmxCodeV1Section(Header, section);
                        break;

                    case ".dbg.files":
                        DebugFiles = new SmxDebugFilesTable(Header, section, DebugNames);
                        break;

                    case ".dbg.lines":
                        DebugLines = new SmxDebugLinesTable(Header, section);
                        break;

                    case ".dbg.natives":
                        DebugNatives = new SmxDebugNativesTable(Header, section, DebugNames);
                        break;

                    case ".dbg.symbols":
                        DebugSymbols = new SmxDebugSymbolsTable(Header, section, DebugInfo, DebugNames);
                        break;

                    case ".dbg.methods":
                        DebugMethods = new SmxDebugMethods(Header, section, Names);
                        break;

                    case ".dbg.globals":
                        DebugGlobals = new SmxDebugGlobals(Header, section, Names);
                        break;

                    case ".dbg.locals":
                        DebugLocals = new SmxDebugLocals(this, Header, section, Names);
                        break;

                    case "rtti.data":
                        RttiData = new SmxRttiData(this, Header, section);
                        break;

                    case "rtti.classdefs":
                        RttiClassDefs = new SmxRttiClassDefTable(Header, section, Names);
                        break;

                    case "rtti.fields":
                        RttiFields = new SmxRttiFieldTable(Header, section, Names);
                        break;

                    case "rtti.methods":
                        RttiMethods = new SmxRttiMethodTable(Header, section, Names);
                        break;

                    case "rtti.natives":
                        RttiNatives = new SmxRttiNativeTable(Header, section, Names);
                        break;

                    case "rtti.enums":
                        RttiEnums = new SmxRttiEnumTable(Header, section, Names);
                        break;

                    case "rtti.typedefs":
                        RttiTypedefs = new SmxRttiTypedefTable(Header, section, Names);
                        break;

                    case "rtti.typesets":
                        RttiTypesets = new SmxRttiTypesetTable(Header, section, Names);
                        break;

                    default:
                        unknown.Add(section);
                        break;
                    }
                }
                catch
                {
                    // Set a breakpoint here to see why the section failed to be parsed.
                    unknown.Add(section);
                }
            }
            UnknownSections = unknown.ToArray();

            // Disassemble all functions right away to find all called functions.
            if (DebugSymbols != null)
            {
                foreach (var entry in DebugSymbols.Entries)
                {
                    if (entry.Ident != SymKind.Function)
                    {
                        continue;
                    }
                    V1Disassembler.TryDisassemble(this, CodeV1, entry.Address);
                }
            }
            if (Publics != null)
            {
                foreach (var pubfun in Publics.Entries)
                {
                    V1Disassembler.TryDisassemble(this, CodeV1, (int)pubfun.Address);
                }
            }
            if (CalledFunctions != null)
            {
                foreach (var fun in CalledFunctions.Entries)
                {
                    V1Disassembler.TryDisassemble(this, CodeV1, (int)fun.Address);
                }
            }
        }
Пример #30
0
 public SmxDebugGlobals(FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header, names)
 {
 }
Пример #31
0
 public static DebugSymbolEntry[] From(FileHeader hdr, BinaryReader rd, SmxDebugInfoSection info, SmxNameTable names)
 {
     var entries = new DebugSymbolEntry[info.NumSymbols];
     for (var i = 0; i < info.NumSymbols; i++)
     {
         var entry = new DebugSymbolEntry();
         entry.Address = rd.ReadInt32();
         entry.TagId = rd.ReadUInt16();
         // There's a padding of 2 bytes after this short.
         if (hdr.debugUnpacked)
             rd.ReadBytes(2);
         entry.CodeStart = rd.ReadUInt32();
         entry.CodeEnd = rd.ReadUInt32();
         entry.Ident = (SymKind)rd.ReadByte();
         entry.Scope = (SymScope)rd.ReadByte();
         entry.dimcount = rd.ReadUInt16();
         entry.nameoffs = rd.ReadInt32();
         entry.Name = names.StringAt(entry.nameoffs);
         if (entry.dimcount > 0)
             entry.Dims = DebugSymbolDimEntry.From(hdr, rd, entry.dimcount);
         entries[i] = entry;
     }
     return entries;
 }
Пример #32
0
 public static DebugNativeEntry[] From(BinaryReader rd, SmxNameTable names)
 {
     var header = new DebugNativesHeader();
     header.num_entries = rd.ReadUInt32();
     return DebugNativeEntry.From(rd, header, names);
 }
Пример #33
0
 public SmxDebugLocals(SmxFile smx_file, FileHeader file, SectionEntry header, SmxNameTable names)
     : base(file, header, names)
 {
     smx_file_ = smx_file;
 }
Пример #34
0
        public SmxFile(BinaryReader br)
        {
            Header = FileHeader.From(br);

            // Parse precursor sections.
            foreach (var section in Header.Sections)
            {
                if (section.Name == ".names")
                    Names = new SmxNameTable(Header, section);
                else if (section.Name == ".dbg.strings")
                    DebugNames = new SmxNameTable(Header, section);
                else if (section.Name == ".dbg.info")
                    DebugInfo = new SmxDebugInfoSection(Header, section);
            }
            
            // Parse out other sections.
            var unknown = new List<SectionEntry>();
            foreach (var section in Header.Sections)
            {
                switch (section.Name)
                {
                case ".names":
                case ".dbg.strings":
                case ".dbg.info":
                    break;
                case ".natives":
                    Natives = new SmxNativeTable(Header, section, Names);
                    break;
                case ".publics":
                    Publics = new SmxPublicTable(Header, section, Names);
                    break;
                case ".pubvars":
                    Pubvars = new SmxPubvarTable(Header, section, Names);
                    break;
                case ".tags":
                    Tags = new SmxTagTable(Header, section, Names);
                    break;
                case ".data":
                    Data = new SmxDataSection(Header, section);
                    break;
                case ".code":
                    CodeV1 = new SmxCodeV1Section(Header, section);
                    break;
                case ".dbg.files":
                    DebugFiles = new SmxDebugFilesTable(Header, section, DebugNames);
                    break;
                case ".dbg.lines":
                    DebugLines = new SmxDebugLinesTable(Header, section);
                    break;
                case ".dbg.natives":
                    DebugNatives = new SmxDebugNativesTable(Header, section, DebugNames);
                    break;
                case ".dbg.symbols":
                    DebugSymbols = new SmxDebugSymbolsTable(Header, section, DebugInfo, DebugNames);
                    break;
                default:
                    unknown.Add(section);
                    break;
                }
            }
            UnknownSections = unknown.ToArray();
        }