Exemplo n.º 1
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);
                }
            }
        }
Exemplo n.º 2
0
        private void renderDebugSymbols(TreeNode root, SmxDebugSymbolsTable syms)
        {
            var globals = root.Nodes.Add("globals");
            foreach (var sym_ in syms.Entries)
            {
                var sym = sym_;
                if (sym.Scope != SymScope.Global)
                    continue;
                if (sym.Ident == SymKind.Function)
                    continue;
                var node = globals.Nodes.Add(sym.Name);
                node.Tag = new NodeData(delegate()
                {
                    renderSymbolDetail(sym);
                }, null);
            }

            var functions = root.Nodes.Add("functions");
            foreach (var sym_ in syms.Entries)
            {
                var sym = sym_;
                if (sym.Scope != SymScope.Global)
                    continue;
                if (sym.Ident != SymKind.Function)
                    continue;
                var node = functions.Nodes.Add(sym.Name);
                renderDebugFunction(syms, node, sym);
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
0
        private void renderDebugFunction(SmxDebugSymbolsTable syms, TreeNode root, DebugSymbolEntry fun)
        {
            root.Tag = new NodeData(delegate()
            {
                renderSymbolDetail(fun);
            }, null);

            var args = new List<DebugSymbolEntry>();
            var locals = new List<DebugSymbolEntry>();
            foreach (var sym_ in syms.Entries)
            {
                var sym = sym_;
                if (sym.Scope == SymScope.Global)
                    continue;
                if (sym.CodeStart < fun.CodeStart || sym.CodeEnd > fun.CodeEnd)
                    continue;
                if (sym.Address < 0)
                    locals.Add(sym);
                else
                    args.Add(sym);
            }

            args.Sort(delegate (DebugSymbolEntry e1, DebugSymbolEntry e2)
            {
                return e1.Address.CompareTo(e2.Address);
            });
            foreach (var sym_ in args)
            {
                var sym = sym_;
                var node = root.Nodes.Add(sym.Name);
                node.Tag = new NodeData(delegate()
                {
                    renderSymbolDetail(sym);
                }, null);
            }

            locals.Sort(delegate (DebugSymbolEntry e1, DebugSymbolEntry e2)
            {
                return e1.CodeStart.CompareTo(e2.CodeStart);
            });
            foreach (var sym_ in locals)
            {
                var sym = sym_;
                var node = root.Nodes.Add(sym.Name);
                node.Tag = new NodeData(delegate()
                {
                    renderSymbolDetail(sym);
                }, null);
            }
        }
Exemplo n.º 5
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();
        }