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(); }
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]]; } } }