コード例 #1
0
 public void SetTargetRelocation(Relocation e)
 {
     if (e != null)
     {
         _addend = (uint)e._index * 4;
     }
 }
コード例 #2
0
 public DialogResult ShowDialog(Relocation relocation, SectionEditor mainWindow)
 {
     _mainWindow = mainWindow;
     _targetRelocation = relocation;
     oldValue = _targetRelocation.RawValue;
     propertyGrid1.SelectedObject = _code = _targetRelocation.Code;
     label3.Text = "0x" + (_targetRelocation._index * 4).ToString("X");
     return base.ShowDialog();
 }
コード例 #3
0
 public void Update(Relocation r)
 {
     if (r == null)
         return;
     int index = _relocations.IndexOf(r);
     if (index < 0)
         return;
     UpdateRow(index);
 }
コード例 #4
0
 public Color GetStatusColor(Relocation c)
 {
     if (c.Code is PPCblr)
     {
         return(clrBlr);
     }
     if (c.Command == null)
     {
         return(clrNotRelocated);
     }
     return(clrRelocated);
 }
コード例 #5
0
        private unsafe RELType ParseDeclaration(Relocation rel)
        {
            RELType type = null;

            if (_types.TryGetValue(rel, out type))
            {
                return(type);
            }

            if (rel.Command == null || rel.Command._targetRelocation._section != _objectSection)
            {
                return(null);
            }

            string name = new string((sbyte *)(rel._section.BaseAddress + rel.RelOffset));

            if (String.IsNullOrEmpty(name))
            {
                return(null);
            }

            type = new RELType(name);

            //Get inheritances, if any.
            if (rel.Next.Command != null)
            {
                for (Relocation r = rel.Next.Command._targetRelocation;
                     r != null && r.Command != null;
                     r = r.NextAt(2))
                {
                    RELType inheritance = ParseDeclaration(r.Command._targetRelocation);
                    if (inheritance != null)
                    {
                        type.Inheritance.Add(new InheritanceItemNode(inheritance, r.Next.RawValue));
                        inheritance.Inherited = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            rel.Tags.Add(type.FormalName + " Declaration");
            rel.Next.Tags.Add(type.FormalName + "->Inheritances");

            _types.Add(rel, type);

            return(type);
        }
コード例 #6
0
        public unsafe void Parse()
        {
            if (_objectSection == null)
            {
                return;
            }

            for (Relocation rel = _objectSection[0]; rel != null; rel = rel.Next)
            {
                ParseDeclaration(rel);
            }

            for (Relocation rel = _objectSection[0]; rel != null; rel = rel.Next)
            {
                ParseObject(ref rel);
            }
        }
コード例 #7
0
        private void SetTarget(Relocation target)
        {
            if (_target == target)
            {
                return;
            }

            if (_target != null)
            {
                _target.Unlink(this);
            }

            _target = target;

            if (_target != null)
            {
                _target.Link(this);
            }
        }
コード例 #8
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;
        }
コード例 #9
0
        private unsafe RELType ParseDeclaration(Relocation rel)
        {
            RELType type = null;
            if (_types.TryGetValue(rel, out type))
                return type;

            if (rel.Command == null || rel.Command._targetRelocation._section != _objectSection)
                return null;

            string name = new string((sbyte*)(rel._section.BaseAddress + rel.RelOffset));

            if (String.IsNullOrEmpty(name))
                return null;

            type = new RELType(name);

            //Get inheritances, if any.
            if (rel.Next.Command != null)
                for (Relocation r = rel.Next.Command._targetRelocation;
                     r != null && r.Command != null;
                     r = r.NextAt(2))
                {
                    RELType inheritance = ParseDeclaration(r.Command._targetRelocation);
                    if (inheritance != null)
                    {
                        type.Inheritance.Add(new InheritanceItemNode(inheritance, r.Next.RawValue));
                        inheritance.Inherited = true;
                    }
                    else break;
                }

            rel.Tags.Add(type.FormalName + " Declaration");
            rel.Next.Tags.Add(type.FormalName + "->Inheritances");

            _types.Add(rel, type);

            return type;
        }
コード例 #10
0
        private unsafe RELObjectNode ParseObject(ref Relocation rel)
        {
            if (rel.Command == null || rel.Command._targetRelocation._section != _objectSection)
                return null;

            RELType declaration = null;

            if (!_types.TryGetValue(rel.Command.TargetRelocation, out declaration) || declaration.Inherited)
                return null;

            RELObjectNode obj = null;
            foreach (RELObjectNode node in _objects)
                if (node._name == declaration.FullName)
                {
                    obj = node;
                    break;
                }

            if (obj == null)
            {
                obj = new RELObjectNode(declaration);
                obj._parent = _objectSection;
                _objectSection._children.Add(obj);
                new RELGroupNode() { _name = "Inheritance" }.Parent = obj;
                foreach (InheritanceItemNode n in declaration.Inheritance)
                    n.Parent = obj.Children[0];
                new RELGroupNode() { _name = "Functions" }.Parent = obj;
            }

            Relocation baseRel = rel;

            int methodIndex = 0;
            int setIndex = 0;

            // Read object methods.
            while (rel.Command != null && (rel.Command._targetRelocation._section != _objectSection || rel.SectionOffset == baseRel.SectionOffset))
            {
                if (rel.SectionOffset != baseRel.SectionOffset)
                {
                    new RELMethodNode() { _name = String.Format("Function[{0}][{1}]", setIndex, methodIndex) }.Initialize(obj.Children[1], rel.Target.Address, 0);
                    methodIndex++;
                }
                else
                {
                    if (rel.Next.RawValue != 0)
                        setIndex++;

                    methodIndex = 0;
                    rel = rel.Next;
                }
                rel = rel.Next;
            }

            baseRel.Tags.Add(obj.Type.FullName);

            _objects.Add(obj);
            return obj;
        }
コード例 #11
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;
            }
        }
コード例 #12
0
 public void SetTargetRelocation(Relocation e)
 {
     if (e != null)
         _addend = (uint)e._index * 4;
 }
コード例 #13
0
        private void SetTarget(Relocation target)
        {
            if (_target == target)
                return;

            if (_target != null)
                _target.Unlink(this);

            _target = target;

            if (_target != null)
                _target.Link(this);
        }
コード例 #14
0
        private unsafe RELObjectNode ParseObject(ref Relocation rel)
        {
            if (rel.Command == null || rel.Command._targetRelocation._section != _objectSection)
            {
                return(null);
            }

            RELType declaration = null;

            if (!_types.TryGetValue(rel.Command.TargetRelocation, out declaration) || declaration.Inherited)
            {
                return(null);
            }

            RELObjectNode obj = null;

            foreach (RELObjectNode node in _objects)
            {
                if (node._name == declaration.FullName)
                {
                    obj = node;
                    break;
                }
            }

            if (obj == null)
            {
                obj         = new RELObjectNode(declaration);
                obj._parent = _objectSection;
                _objectSection._children.Add(obj);
                new RELGroupNode()
                {
                    _name = "Inheritance"
                }.Parent = obj;
                foreach (InheritanceItemNode n in declaration.Inheritance)
                {
                    n.Parent = obj.Children[0];
                }
                new RELGroupNode()
                {
                    _name = "Functions"
                }.Parent = obj;
            }

            Relocation baseRel = rel;

            int methodIndex = 0;
            int setIndex    = 0;

            // Read object methods.
            while (rel.Command != null && (rel.Command._targetRelocation._section != _objectSection || rel.SectionOffset == baseRel.SectionOffset))
            {
                if (rel.SectionOffset != baseRel.SectionOffset)
                {
                    new RELMethodNode()
                    {
                        _name = String.Format("Function[{0}][{1}]", setIndex, methodIndex)
                    }.Initialize(obj.Children[1], rel.Target.Address, 0);
                    methodIndex++;
                }
                else
                {
                    if (rel.Next.RawValue != 0)
                    {
                        setIndex++;
                    }

                    methodIndex = 0;
                    rel         = rel.Next;
                }
                rel = rel.Next;
            }

            baseRel.Tags.Add(obj.Type.FullName);

            _objects.Add(obj);
            return(obj);
        }
コード例 #15
0
 private void FixRelocation(Relocation w, int amt, long offset)
 {
     foreach (Relocation l in w.Linked)
         if (l.Command != null)
             if (l.Command.TargetSectionID == _section.Index && l.Command._addend >= offset)
                 l.Command._addend = (uint)((int)l.Command._addend + amt * 4);
 }
コード例 #16
0
        protected override void OnClosed(EventArgs e)
        {
            Apply();

            _openedSections.Remove(this);
            if (_section != null)
                _section._linkedEditor = null;

            TargetRelocation = null;

             	        base.OnClosed(e);
        }
コード例 #17
0
 public void SetRelocationAtIndex(int index, Relocation value)
 {
     _relocations[index] = value;
 }
コード例 #18
0
 public Color GetStatusColor(Relocation c)
 {
     if (c.Code is PPCblr)
         return ModuleDataNode.clrBlr;
     if (c.Command == null)
         return ModuleDataNode.clrNotRelocated;
     return ModuleDataNode.clrRelocated;
 }
コード例 #19
0
        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;
        }
コード例 #20
0
 public void SetRelocationAtOffset(int offset, Relocation value)
 {
     this[offset.RoundDown(4) / 4] = value;
 }
コード例 #21
0
 public void SetRelocationAtIndex(int index, Relocation value)
 {
     this[index] = value;
 }
コード例 #22
0
        public void OpenRelocation(Relocation target)
        {
            if (target == null)
                return;

            if (target._section != _section)
            {
                foreach (SectionEditor r in _openedSections)
                    if (r._section == target._section)
                    {
                        r.Position = target._index * 4;
                        r.Focus();
                        r.hexBox1.Focus();
                        return;
                    }

                SectionEditor x = new SectionEditor(target._section as ModuleSectionNode);
                x.Show();

                x.Position = target._index * 4;
                x.hexBox1.Focus();
            }
            else
            {
                Position = target._index * 4;
                hexBox1.Focus();
            }
        }
コード例 #23
0
 internal void Link(Relocation r)
 {
     _linked.Add(r);
     //CheckStructors();
 }
コード例 #24
0
 public void SetRelocationAtOffset(int offset, Relocation value)
 {
     SetRelocationAtOffset(offset.RoundDown(4) / 4, value);
 }
コード例 #25
0
 internal void Unlink(Relocation r)
 {
     _linked.Remove(r);
     //CheckStructors();
 }
コード例 #26
0
        private void Apply()
        {
            if (hexBox1.ByteProvider == null)
                return;

            try
            {
                if (_section._isBSSSection != chkBSSSection.Checked || _section._isCodeSection != chkCodeSection.Checked)
                {
                    _section._isBSSSection = chkBSSSection.Checked;
                    _section._isCodeSection = chkCodeSection.Checked;
                    _section.SignalPropertyChange();
                }

                if (_section.Root is RELNode)
                {
                    RELNode r = _section.Root as RELNode;

                    if (r._prologReloc != _prologReloc && _prologReloc != null)
                    {
                        if (r._prologReloc != null)
                            r._prologReloc._prolog = false;

                        r._prologReloc = _prologReloc;
                        r.SignalPropertyChange();
                    }

                    if (r._epilogReloc != _epilogReloc && _epilogReloc != null)
                    {
                        if (r._epilogReloc != null)
                            r._epilogReloc._epilog = false;

                        r._epilogReloc = _epilogReloc;
                        r.SignalPropertyChange();
                    }

                    if (r._unresReloc != _unresReloc && _unresReloc != null)
                    {
                        if (r._unresReloc != null)
                            r._unresReloc._unresolved = false;

                        r._unresReloc = _unresReloc;
                        r.SignalPropertyChange();
                    }
                }

                DynamicFileByteProvider d = hexBox1.ByteProvider as DynamicFileByteProvider;
                if (!d.HasChanges())
                    return;

                UnsafeBuffer newBuffer = new UnsafeBuffer((int)d.Length);

                int amt = Math.Min(_section._dataBuffer.Length, newBuffer.Length);
                if (amt > 0)
                {
                    Memory.Move(newBuffer.Address, _section._dataBuffer.Address, (uint)amt);
                    if (newBuffer.Length - amt > 0)
                        Memory.Fill(newBuffer.Address + amt, (uint)(newBuffer.Length - amt), 0);
                }

                if (d._stream != null)
                    d._stream.Dispose();
                d._stream = new UnmanagedMemoryStream((byte*)newBuffer.Address, newBuffer.Length, newBuffer.Length, FileAccess.ReadWrite);

                d.ApplyChanges();

                _section._dataBuffer.Dispose();
                _section._dataBuffer = newBuffer;
                _section.SignalPropertyChange();

                if (_relocationsChanged)
                {
                    Relocation[] temp = new Relocation[_relocations.Count];
                    _relocations.CopyTo(temp);
                    List<Relocation> temp2 = temp.ToList();

                    _section._relocations = temp2;
                    _section._firstCommand = _firstCommand;

                    ResourceNode a = _section.Root;
                    if (a != null && a != _section.Root)
                        a.SignalPropertyChange();
                }

                hexBox1.Invalidate();
                hexBox1.Focus();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                EnableButtons();
            }
        }
コード例 #27
0
 public void SetRelocationAtOffset(int offset, Relocation value)
 {
     this[offset.RoundDown(4) / 4] = value;
 }
コード例 #28
0
        private void chkConstructor_CheckedChanged(object sender, EventArgs e)
        {
            if (_updating || TargetRelocation == null)
                return;

            if (TargetRelocation == _prologReloc)
            {
                if (!(_prologReloc._prolog = chkConstructor.Checked))
                    _prologReloc = null;
            }
            else
            {
                if (chkConstructor.Checked)
                {
                    if (_prologReloc != null)
                        _prologReloc._prolog = false;
                    _prologReloc = TargetRelocation;
                    _prologReloc._prolog = true;
                }
            }
        }
コード例 #29
0
 internal void Link(Relocation r)
 {
     _linked.Add(r);
     //CheckStructors();
 }
コード例 #30
0
        void PosChanged()
        {
            this.toolStripStatusLabel.Text = string.Format("Ln {0}    Col {1}",
                hexBox1.CurrentLine, hexBox1.CurrentPositionInLine);

            long offset = hexBox1.SelectionStart;
            long t = offset.RoundDown(4);

            _updating = true;

            TargetRelocation = (offset < hexBox1.ByteProvider.Length ? GetRelocationAtOffset((int)offset) : null);

            grpValue.Text = "Value @ 0x" + t.ToString("X");
            if (t + 3 < hexBox1.ByteProvider.Length)
            {
                grpValue.Enabled = !_section._isBSSSection;
                byte[] bytes = new byte[]
                {
                    //Read in little endian
                    hexBox1.ByteProvider.ReadByte(t + 3),
                    hexBox1.ByteProvider.ReadByte(t + 2),
                    hexBox1.ByteProvider.ReadByte(t + 1),
                    hexBox1.ByteProvider.ReadByte(t + 0),
                };

                //Reverse byte order to big endian
                txtByte1.Text = bytes[3].ToString("X2");
                txtByte2.Text = bytes[2].ToString("X2");
                txtByte3.Text = bytes[1].ToString("X2");
                txtByte4.Text = bytes[0].ToString("X2");

                //BitConverter converts from little endian
                float f = BitConverter.ToSingle(bytes, 0);
                float z;
                if (float.TryParse(txtFloat.Text, out z))
                {
                    if (z != f)
                        txtFloat.Text = f.ToString();
                }
                else
                    txtFloat.Text = f.ToString();

                int i = BitConverter.ToInt32(bytes, 0);
                int w;
                if (int.TryParse(txtInt.Text, out w))
                {
                    if (w != i)
                    {
                        txtInt.Text = i.ToString();
                        if (_section.HasCode && ppcDisassembler1.Visible)
                            ppcDisassembler1.Update(TargetRelocation);
                    }
                }
                else
                    txtInt.Text = i.ToString();

                string bin = ((Bin32)(uint)i).ToString();
                string[] bins = bin.Split(' ');

                txtBin1.Text = bins[0];
                txtBin2.Text = bins[1];
                txtBin3.Text = bins[2];
                txtBin4.Text = bins[3];
                txtBin5.Text = bins[4];
                txtBin6.Text = bins[5];
                txtBin7.Text = bins[6];
                txtBin8.Text = bins[7];
            }
            else
                grpValue.Enabled = false;

            OffsetToolStripStatusLabel.Text = String.Format("Offset: 0x{0}", offset.ToString("X"));

            if (_section.HasCode && ppcDisassembler1.Visible && TargetRelocation != null && !ppcDisassembler1._updating)
            {
                int i = ppcDisassembler1._relocations.IndexOf(TargetRelocation);
                if (i >= 0)
                {
                    ppcDisassembler1.grdDisassembler.ClearSelection();
                    ppcDisassembler1.grdDisassembler.Rows[i].Selected = true;
                    ppcDisassembler1.grdDisassembler.FirstDisplayedScrollingRowIndex = i;
                    //ppcDisassembler1.grdDisassembler.CurrentCell = ppcDisassembler1.grdDisassembler.Rows[i].Cells[0];
                }
            }

            _updating = false;
        }
コード例 #31
0
 internal void Unlink(Relocation r)
 {
     _linked.Remove(r);
     //CheckStructors();
 }