コード例 #1
0
        public override bool OnInitialize()
        {
            ModuleSectionNode section = Location;

            if (section == null || !Header)
            {
                return(false);
            }

            //Don't make a copy buffer here.
            //Use the original buffer to save memory

            buint * sPtr = (buint *)Header;
            VoidPtr ceil = section.Header + section._dataSize;

            while (!(PowerPC.Disassemble(*sPtr++) is PPCblr) && (int)sPtr < (int)ceil)
            {
                ;
            }

            _codeStart = (int)Header - (int)section.Header;
            _codeLen   = (int)sPtr - (int)Header;

            _manager = new RelocationManager(null);
            _manager.UseReference(section, _codeStart);

            if (_codeLen > 0)
            {
                _manager.AddTag(0, FullName + " Start");
                _manager.AddTag(_codeLen / 4 - 1, FullName + " End");
            }

            return(false);
        }
コード例 #2
0
ファイル: RELNode.cs プロジェクト: 0000duck/brawltools
        public override void OnPopulate()
        {
            _sections = new ModuleSectionNode[_numSections];
            for (int i = 0; i < _numSections; i++)
            {
                RELSectionEntry   entry   = Header->SectionInfo[i];
                ModuleSectionNode section = _sections[i] = new ModuleSectionNode();

                section._isCodeSection = entry.IsCodeSection;
                section._dataOffset    = entry.Offset;
                section._dataSize      = entry._size;

                section.Initialize(this, WorkingUncompressed.Address + Header->SectionInfo[i].Offset, (int)Header->SectionInfo[i]._size);
            }

            ApplyRelocations();
        }
コード例 #3
0
        public override bool OnInitialize()
        {
            ModuleSectionNode section = Location;

            if ((TargetSection == 1 || TargetModule.Equals("main.dol")) && ModuleMapLoader.MapFiles.ContainsKey(TargetModule))
            {
                if (ModuleMapLoader.MapFiles[TargetModule].ContainsKey(TargetOffset))
                {
                    _name = ModuleMapLoader.MapFiles[TargetModule][TargetOffset];
                }
            }

            if (section == null || !Header)
            {
                return(false);
            }

            //Don't make a copy buffer here.
            //Use the original buffer to save memory

            buint * sPtr = (buint *)Header;
            VoidPtr ceil = section.Header + section._dataSize;

            while (!(PowerPC.Disassemble(*sPtr++) is PPCblr) && (int)sPtr < (int)ceil)
            {
                ;
            }

            _codeStart = (int)Header - (int)section.Header;
            _codeLen   = (int)sPtr - (int)Header;

            _manager = new RelocationManager(null);
            _manager.UseReference(section, _codeStart);

            if (_codeLen > 0)
            {
                _manager.AddTag(0, FullName + " Start");
                _manager.AddTag(_codeLen / 4 - 1, FullName + " End");
            }

            return(false);
        }
コード例 #4
0
        public SectionEditor(ModuleSectionNode section)
        {
            InitializeComponent();

            ppcDisassembler1._editor = this;

            if ((_section = section) != null)
            {
                _section._linkedEditor = this;

                Relocation[] temp = new Relocation[_section._relocations.Count];
                _section._relocations.CopyTo(temp);
                _relocations = temp.ToList();
                _firstCommand = _section._firstCommand;
            }
            _openedSections.Add(this);

            Text = String.Format("Module Section Editor - {0}", _section.Name);

            hexBox1.SectionEditor = this;
            chkCodeSection.Checked = _section._isCodeSection;
            chkBSSSection.Checked = _section._isBSSSection;

            if (section.Root is RELNode)
            {
                RELNode r = (RELNode)section.Root;
                if (r._prologReloc != null && r._prologReloc._section == section)
                    _prologReloc = r._prologReloc;
                if (r._epilogReloc != null && r._epilogReloc._section == section)
                    _epilogReloc = r._epilogReloc;
                if (r._unresReloc != null && r._unresReloc._section == section)
                    _unresReloc = r._unresReloc;
                //if (r._nameReloc != null && r._nameReloc._section == section)
                //    _nameReloc = r._nameReloc;
            }

            panel5.Enabled = true;
        }
コード例 #5
0
 public ObjectParser(ModuleSectionNode section)
 {
     _objects = new List<RELObjectNode>();
     _types = new Dictionary<Relocation, RELType>();
     _objectSection = section;
 }
コード例 #6
0
ファイル: RELNode.cs プロジェクト: 0000duck/brawltools
        public void ApplyRelocations()
        {
            foreach (ModuleSectionNode r in Sections)
            {
                r.ClearCommands();
            }

            int offset = 0;
            int i      = 0;

            foreach (uint x in _imports.Keys)
            {
                List <RELLink>    cmds    = _imports[x];
                ModuleSectionNode section = null;
                foreach (RELLink link in cmds)
                {
                    if (link._type == RELLinkType.Section)
                    {
                        offset  = 0;
                        section = Sections[link._section];
                    }
                    else
                    {
                        offset += (int)(ushort)link._prevOffset;

                        if (link._type == RELLinkType.End || link._type == RELLinkType.IncrementOffset)
                        {
                            continue;
                        }

                        if (link._type == RELLinkType.MrkRef)
                        {
                            Console.WriteLine("Mark Ref");
                            continue;
                        }

                        if (section != null)
                        {
                            section.SetCommandAtOffset(offset, new RelCommand(x, section.Index, link));
                        }
                    }
                }
                i++;
            }

            ModuleDataNode s;

            if (_prologReloc == null)
            {
                s      = _sections[Header->_prologSection];
                offset = (int)Header->_prologOffset - (int)s._offset;
            }
            else
            {
                s      = _prologReloc._section;
                offset = _prologReloc._index * 4;
            }
            _prologReloc = s.GetRelocationAtOffset(offset);
            if (_prologReloc != null)
            {
                _prologReloc._prolog = true;
            }

            if (_epilogReloc == null)
            {
                s      = _sections[Header->_epilogSection];
                offset = (int)Header->_epilogOffset - (int)s._offset;
            }
            else
            {
                s      = _epilogReloc._section;
                offset = _epilogReloc._index * 4;
            }
            _epilogReloc = s.GetRelocationAtOffset(offset);
            if (_epilogReloc != null)
            {
                _epilogReloc._epilog = true;
            }

            if (_unresReloc == null)
            {
                s      = _sections[Header->_unresolvedSection];
                offset = (int)Header->_unresolvedOffset - (int)s._offset;
            }
            else
            {
                s      = _unresReloc._section;
                offset = _unresReloc._index * 4;
            }
            _unresReloc = s.GetRelocationAtOffset(offset);
            if (_unresReloc != null)
            {
                _unresReloc._unresolved = true;
            }
        }
コード例 #7
0
        public override void OnPopulate()
        {
            _sections = new ModuleSectionNode[_numSections];
            int prevOffset = RELHeader.Size + RELSectionEntry.Size * (int)_numSections;

            for (int i = 0; i < _numSections; i++)
            {
                RELSectionEntry   entry   = Header->SectionInfo[i];
                ModuleSectionNode section = _sections[i] = new ModuleSectionNode();

                int dataOffset = entry.Offset, dataSize = (int)(uint)entry._size;

                section._isCodeSection = entry.IsCodeSection;
                section._dataOffset    = dataOffset;
                section._dataSize      = entry._size;

                section.Initialize(this, WorkingUncompressed.Address + dataOffset, dataSize);

                if (dataOffset > 0)
                {
                    section._dataAlign = dataOffset - prevOffset;
                    prevOffset         = dataOffset + dataSize;
                }
            }

            //Larger modules may take slightly longer to relocate
            //Use a background worker so the UI thread isn't suspended
            Action <object, DoWorkEventArgs> work = (object sender, DoWorkEventArgs e) =>
            {
                Stopwatch watch = Stopwatch.StartNew();

                ApplyRelocations();

                //Scan for branches, add extra tags
                foreach (ModuleSectionNode s in Sections)
                {
                    if (s.HasCode)
                    {
                        PPCOpCode code;
                        buint *   opPtr = s.BufferAddress;
                        for (int i = 0; i < s._dataBuffer.Length / 4; i++)
                        {
                            if ((code = (uint)*opPtr++) is PPCBranch && !(code is PPCblr || code is PPCbctr))
                            {
                                s._manager.LinkBranch(i, true);
                            }
                        }

                        var cmds = s._manager.GetCommands();
                        foreach (var x in cmds)
                        {
                            RelocationTarget target = x.Value.GetTargetRelocation();
                            string           value  = null;
                            if (target.Section != null && target._sectionID == 5 && !String.IsNullOrEmpty(value = target.Section._manager.GetString(target._index)))
                            {
                                s._manager.AddTag(x.Key, value);
                            }
                        }
                    }
                }

                Sections[5].Populate();

                watch.Stop();
                Console.WriteLine("Took {0} seconds to relocate {1} module", (double)watch.ElapsedMilliseconds / 1000d, Name);
            };

            using (BackgroundWorker b = new BackgroundWorker())
            {
                b.DoWork += new DoWorkEventHandler(work);
                b.RunWorkerAsync();
            }

            // Stage module conversion
            byte *bptr   = (byte *)WorkingUncompressed.Address;
            int   offset = findStageIDOffset();

            _stageID = offset < 0 ? (byte?)null : bptr[offset];

            if (nodeContainsString("stOnlineTrainning"))
            {
                // File must be online training room .rel file
                _itemIDs = new byte[OTrainItemOffsets.Length];
                for (int i = 0; i < OTrainItemOffsets.Length; i++)
                {
                    _itemIDs[i] = bptr[OTrainItemOffsets[i]];
                }
            }
        }
コード例 #8
0
 public ObjectParser(ModuleSectionNode section)
 {
     _objects       = new List <RELObjectNode>();
     _types         = new Dictionary <int, RELType>();
     _objectSection = section;
 }
コード例 #9
0
        public override void OnPopulate()
        {
            _sections = new ModuleSectionNode[_numSections];
            for (int i = 0; i < _numSections; i++)
            {
                RELSectionEntry entry = Header->SectionInfo[i];
                ModuleSectionNode section = _sections[i] = new ModuleSectionNode();

                section._isCodeSection = entry.IsCodeSection;
                section._dataOffset = entry.Offset;
                section._dataSize = entry._size;

                section.Initialize(this, WorkingUncompressed.Address + Header->SectionInfo[i].Offset, (int)Header->SectionInfo[i]._size);
            }

            ApplyRelocations();
        }
コード例 #10
0
        public void ApplyRelocations()
        {
            foreach (ModuleSectionNode r in Sections)
            {
                r._manager.ClearCommands();
            }

            int offset = 0;
            int i      = 0;

            foreach (uint x in _imports.Keys)
            {
                List <RELLink>    cmds    = _imports[x];
                ModuleSectionNode section = null;
                foreach (RELLink link in cmds)
                {
                    if (link._type == RELLinkType.Section)
                    {
                        offset  = 0;
                        section = Sections[link._section];
                    }
                    else
                    {
                        offset += (int)(ushort)link._prevOffset;

                        if (link._type == RELLinkType.End || link._type == RELLinkType.IncrementOffset)
                        {
                            continue;
                        }

                        if (link._type == RELLinkType.MrkRef)
                        {
                            Console.WriteLine("Mark Ref");
                            continue;
                        }

                        if (section != null)
                        {
                            section._manager.SetCommand(offset.RoundDown(4) / 4, new RelCommand(x, section, link));
                        }
                    }
                }
                i++;
            }

            ModuleDataNode s;

            s      = _sections[_prologSection];
            offset = (int)_prologOffset;
            //_prologReloc = s.GetRelocationAtOffset(offset);
            //if (_prologReloc != null)
            //    _prologReloc._prolog = true;


            s      = _sections[_epilogSection];
            offset = (int)_epilogOffset;

            //_epilogReloc = s.GetRelocationAtOffset(offset);
            //if (_epilogReloc != null)
            //    _epilogReloc._epilog = true;


            s      = _sections[_unresolvedSection];
            offset = (int)_unresolvedOffset;

            //_unresReloc = s.GetRelocationAtOffset(offset);
            //if (_unresReloc != null)
            //    _unresReloc._unresolved = true;
        }