示例#1
0
        public void SetCommandAtIndex(int index, RelCommand cmd)
        {
            if (index >= Relocations.Count || index < 0)
            {
                return;
            }

            if (Relocations[index].Command != null)
            {
                Relocations[index].Command.Remove();
            }

            Relocations[index].Command = cmd;

            RelCommand c = GetCommandBefore(index);

            if (c != null)
            {
                cmd.InsertAfter(c);
            }
            else
            {
                c = GetCommandAfter(index);
                if (c != null)
                {
                    cmd.InsertBefore(c);
                }
            }
            GetFirstCommand();
        }
        public void SetCommand(int index, RelCommand cmd)
        {
            if (_reference != null)
            {
                _reference._manager.SetCommand(index + _referenceIndex, cmd);
                return;
            }

            if (_commands.ContainsKey(index))
            {
                if (cmd != null)
                {
                    LinkCommand(index, false);
                    _commands[index] = cmd;
                    LinkCommand(index, true);
                }
                else
                {
                    LinkCommand(index, false);
                    _commands.Remove(index);
                }
            }
            else if (cmd != null)
            {
                _commands.Add(index, cmd);
                LinkCommand(index, true);
            }
        }
示例#3
0
        public void ClearCommands()
        {
            RelCommand c = _firstCommand;

            while (c != null)
            {
                c._parentRelocation.Command = null;
                c = c._next;
            }
        }
示例#4
0
 public void Remove()
 {
     if (_next != null)
     {
         _next._prev = _prev;
     }
     if (_prev != null)
     {
         _prev._next = _next;
     }
     _next = _prev = null;
 }
示例#5
0
        private void SetCommand(RelCommand command)
        {
            if (_command == command)
            {
                return;
            }

            if (_command != null)
            {
                SetTarget(null);
                _command._parentRelocation = null;
            }

            if ((_command = command) != null)
            {
                _command._parentRelocation = this;
                SetTarget(_command.GetTargetRelocation());
            }
        }
        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;
        }
示例#7
0
        public void GenerateImports()
        {
            _imports.Clear();
            Dictionary <uint, ImportData> data = new Dictionary <uint, ImportData>();

            foreach (ModuleSectionNode s in _sections)
            {
                foreach (ImportData e in data.Values)
                {
                    e._first      = true;
                    e._lastOffset = 0;
                }
                uint           i      = 0;
                uint           offset = 0;
                List <RELLink> cmds;
                foreach (Relocation loc in s._relocations)
                {
                    if (loc.Command != null)
                    {
                        RelCommand cmd = loc.Command;
                        ImportData d;
                        uint       id = cmd._moduleID;

                        if (_imports.ContainsKey(id))
                        {
                            cmds = _imports[id];
                            d    = data[id];
                        }
                        else
                        {
                            _imports.Add(id, cmds = new List <RELLink>());
                            data.Add(id, d        = new ImportData()
                            {
                                _first = true, _lastOffset = 0
                            });
                        }

                        if (d._first)
                        {
                            cmds.Add(new RELLink()
                            {
                                _type = RELLinkType.Section, _section = (byte)s.Index
                            });
                            d._first = false;
                        }

                        offset = i * 4 + (cmd.IsHalf ? 2u : 0);
                        uint diff = offset - d._lastOffset;
                        while (offset - d._lastOffset > 0xFFFF)
                        {
                            d._lastOffset += 0xFFFF;
                            cmds.Add(new RELLink()
                            {
                                _type = RELLinkType.IncrementOffset, _section = 0, _value = 0, _prevOffset = 0xFFFF
                            });
                        }

                        byte        targetSection = (byte)cmd._targetSectionId;
                        RELLinkType type          = (RELLinkType)cmd._command;
                        uint        val           = cmd._addend;

                        cmds.Add(new RELLink()
                        {
                            _type = type, _section = targetSection, _value = val, _prevOffset = (ushort)diff
                        });

                        d._lastOffset = offset;
                    }
                    i++;
                }
            }

            foreach (List <RELLink> cmds in _imports.Values)
            {
                cmds.Add(new RELLink()
                {
                    _type = RELLinkType.End
                });
            }
        }
示例#8
0
        private unsafe RELObjectNode ParseObject(ref int rel)
        {
            RelCommand cmd = Manager.GetCommand(rel);

            RelocationTarget target = cmd?.GetTargetRelocation();

            if (target == null || target._sectionID != _objectSection.Index)
            {
                return(null);
            }


            if (!_types.TryGetValue(target._index, out RELType 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)
                {
                    _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;
            }

            int        baseRel = rel;
            RelCommand baseCmd = Manager.GetCommand(baseRel);

            int methodIndex = 0;
            int setIndex    = 0;

            //Read object methods.
            while ((cmd = Manager.GetCommand(rel)) != null)
            {
                RelocationTarget t = cmd.GetTargetRelocation();
                if (cmd.Apply(Manager.GetUint(rel), 0) != baseCmd.Apply(Manager.GetUint(baseRel), 0))
                {
                    string  methodName = $"Function[{setIndex}][{methodIndex}]";
                    VoidPtr addr       = null;
                    if (t != null && t._moduleID == (_objectSection.Root as ModuleNode).ID)
                    {
                        addr = _objectSection.Root.Children[t._sectionID].WorkingUncompressed.Address + t._index * 4;
                    }

                    new RELMethodNode
                    {
                        _name = methodName,
                        _cmd  = cmd
                    }
                    .Initialize(obj.Children[1], addr, 0);

                    methodIndex++;
                }
                else
                {
                    if (Manager.GetUint(rel + 1) != 0)
                    {
                        setIndex++;
                    }

                    methodIndex = 0;
                    rel++;
                }

                rel++;
            }

            Manager.AddTag(baseRel, obj.Type.FullName);

            _objects.Add(obj);
            return(obj);
        }
示例#9
0
 public void InsertAfter(RelCommand cmd)
 {
     _prev     = cmd;
     _next     = cmd._next;
     cmd._next = this;
 }
示例#10
0
 public void InsertBefore(RelCommand cmd)
 {
     _next     = cmd;
     _prev     = cmd._prev;
     cmd._prev = this;
 }
示例#11
0
        public void GenerateImports()
        {
            _imports.Clear();
            Dictionary <uint, ImportData> tempImports = new Dictionary <uint, ImportData>();

            foreach (ModuleSectionNode s in _sections)
            {
                foreach (ImportData e in tempImports.Values)
                {
                    e._newSection = true;
                    e._lastOffset = 0;
                }

                uint           offset = 0;
                List <RELLink> links;

                //Iterate through each command in the section
                var commands = s._manager.GetCommands();
                foreach (var r in commands)
                {
                    RelCommand command = r.Value;
                    int        index   = r.Key;

                    ImportData impData;
                    uint       moduleID = command._moduleID;

                    //Check if an import has been created for the target module.
                    if (_imports.ContainsKey(moduleID))
                    {
                        //An import already exists, so we'll add to it.
                        links   = _imports[moduleID];
                        impData = tempImports[moduleID];
                    }
                    else
                    {
                        //An import does not exist, so it must be made.
                        _imports.Add(moduleID, links = new List <RELLink>());

                        //Create new temporary import data
                        tempImports.Add(moduleID, impData = new ImportData()
                        {
                            _newSection = true, _lastOffset = 0
                        });
                    }

                    //This is true when a new section is being evaluated.
                    if (impData._newSection)
                    {
                        links.Add(new RELLink()
                        {
                            _type = RELLinkType.Section, _section = (byte)s.Index
                        });
                        impData._newSection = false;
                    }

                    //Get the offset of the command within the section.
                    offset = (uint)index * 4 + (command.IsHalf ? 2u : 0);

                    //Get the offset to this address relative to the last written link offset.
                    uint diff = offset - impData._lastOffset;

                    //If the difference is greater than ushort allows,
                    //add increment links until the difference works
                    while (diff > 0xFFFF)
                    {
                        impData._lastOffset += 0xFFFF;
                        diff = offset - impData._lastOffset;

                        links.Add(new RELLink()
                        {
                            _type = RELLinkType.IncrementOffset, _section = 0, _value = 0, _prevOffset = 0xFFFF
                        });
                    }

                    //Gather the link information
                    byte        targetSection = (byte)command._targetSectionId;
                    RELLinkType type          = (RELLinkType)command._command;
                    uint        val           = command._addend;

                    //Write command link
                    links.Add(new RELLink()
                    {
                        _type = type, _section = targetSection, _value = val, _prevOffset = (ushort)diff
                    });

                    //Don't bother adding the difference,
                    //just set the exact offset as the last offset
                    impData._lastOffset = offset;
                }
            }

            foreach (List <RELLink> cmds in _imports.Values)
            {
                cmds.Add(new RELLink()
                {
                    _type = RELLinkType.End
                });
            }
        }
 public void Remove()
 {
     if (_next != null)
         _next._prev = _prev;
     if (_prev != null)
         _prev._next = _next;
     _next = _prev = null;
 }
 public void InsertBefore(RelCommand cmd)
 {
     _next = cmd;
     _prev = cmd._prev;
     cmd._prev = this;
 }
 public void SetCommandAtOffset(int offset, RelCommand cmd)
 {
     SetCommandAtIndex(offset.RoundDown(4) / 4, cmd);
 }
 public void GetFirstCommand()
 {
     _firstCommand = GetCommandAfter(-1);
 }
示例#16
0
 public void GetFirstCommand()
 {
     _firstCommand = GetCommandAfter(-1);
 }
示例#17
0
 public void SetCommandAtOffset(int offset, RelCommand cmd)
 {
     SetCommandAtIndex(offset.RoundDown(4) / 4, cmd);
 }
        public void SetCommandAtIndex(int index, RelCommand cmd)
        {
            if (index >= _relocations.Count || index < 0)
                return;

            if (_relocations[index].Command != null)
                _relocations[index].Command.Remove();

            _relocations[index].Command = cmd;

            RelCommand c = GetCommandBefore(index);
            if (c != null)
                cmd.InsertAfter(c);
            else
            {
                c = GetCommandAfter(index);
                if (c != null)
                    cmd.InsertBefore(c);
            }
            GetFirstCommand();
        }
示例#19
0
        private unsafe RELType ParseDeclaration(int index)
        {
            if (_types.TryGetValue(index, out RELType type))
            {
                return(type);
            }

            RelCommand cmd = Manager.GetCommand(index);

            RelocationTarget target = cmd?.GetTargetRelocation();

            if (target == null || target._sectionID != _objectSection.Index)
            {
                return(null);
            }

            uint relOffset = cmd.Apply(Manager.GetUint(index), 0);

            if (relOffset > _objectSection._dataOffset + _objectSection._dataSize)
            {
                return(null);
            }

            string name = new string((sbyte *)(_objectSection.Header + relOffset));

            if (string.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            type = new RELType(name);

            //Get inheritances, if any.
            cmd = Manager.GetCommand(index + 1);
            if (cmd != null)
            {
                for (RelocationTarget r = cmd.GetTargetRelocation();
                     r != null && (cmd = Manager.GetCommand(r._index)) != null;
                     r._index += 2)
                {
                    RelocationTarget inheritTarget = cmd.GetTargetRelocation();
                    RELType          inheritance   = ParseDeclaration(inheritTarget._index);
                    if (inheritance != null)
                    {
                        InheritanceItemNode typeNode =
                            new InheritanceItemNode(inheritance, Manager.GetUint(r._index + 1));
                        typeNode.Initialize(null, _objectSection.Header + r._index * 4, 0);
                        type.Inheritance.Add(typeNode);
                        inheritance.Inherited = true;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Manager.AddTag(index, type.FormalName + " Declaration");
            Manager.AddTag(index + 1, type.FormalName + "->Inheritances");

            _types.Add(index, type);

            return(type);
        }
        private void SetCommand(RelCommand command)
        {
            if (_command == command)
                return;

            if (_command != null)
            {
                SetTarget(null);
                _command._parentRelocation = null;
            }

            if ((_command = command) != null)
            {
                _command._parentRelocation = this;
                SetTarget(_command.GetTargetRelocation());
            }
        }
 public void InsertAfter(RelCommand cmd)
 {
     _prev = cmd;
     _next = cmd._next;
     cmd._next = this;
 }