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