Exemplo n.º 1
0
        public SaveForm(NSE_Framework.Write write, byte[] Data, int Offset, int OrigonalLength)
        {
            InitializeComponent();

            if (Program.MainForm.Read.FileLength > 0x1000000)
            {
                TextBox1.MaxLength = 7;
            }


            if (Offset != -1)
            {
                TextBox1.Text = Offset.ToString("X2");
            }
            else
            {
                NSE_Framework.Find find = new NSE_Framework.Find(Program.MainForm.Filename);
                int f = find.FindFreeSpace(0, Data.Length);
                if (f != -1)
                {
                    TextBox1.Text = f.ToString("X2");
                }
            }
            Label3.Text = OrigonalLength.ToString();

            this.OrigonalOffset = Offset;
            this.Data           = Data;
            this.OrigonalLength = OrigonalLength;
            this.write          = write;
        }
Exemplo n.º 2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            NSE_Framework.Find find = new NSE_Framework.Find(Program.MainForm.Filename);
            int f = find.FindFreeSpace(int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber), Data.Length, Program.MainForm.SafetyRepointing);

            if (f != -1)
            {
                TextBox1.Text = f.ToString("X2");
            }
        }
Exemplo n.º 3
0
        public InsertForm(NSE_Framework.Write write, byte[] Data)
        {
            InitializeComponent();

            if (Program.MainForm.Read.FileLength > 0x1000000)
            {
                TextBox1.MaxLength = 7;
            }

            NSE_Framework.Find find = new NSE_Framework.Find(Program.MainForm.Filename);
            TextBox1.Text = find.FindFreeSpace(0X800000, Data.Length, true).ToString("X2");
            Label3.Text   = Data.Length.ToString();

            this.Data  = Data;
            this.write = write;
        }
Exemplo n.º 4
0
        private void OK_Button_Click(object sender, EventArgs e)
        {
            if (int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber) < Program.MainForm.Read.FileLength - 512)
            {
                this.SaveOffset = int.Parse(TextBox1.Text, System.Globalization.NumberStyles.HexNumber);



                if (Program.MainForm.SafetyRepointing && this.SaveOffset % 4 == 0 || !Program.MainForm.SafetyRepointing)
                {
                    byte[] ExistingData = Program.MainForm.Read.ReadBytes(SaveOffset, Data.Length);

                    if (IsFreeSpace(ExistingData, SaveOffset, OrigonalOffset, OrigonalLength) || !CheckBoxAbort.Checked)
                    {
                        write.WriteBytes(Data, this.SaveOffset);


                        Program.MainForm.LogWriter.LogMessage("Saved Data 0x" + OrigonalOffset.ToString("X") + " to 0x" + SaveOffset.ToString("X"));


                        if (CheckBoxPointers.Checked && SaveOffset != OrigonalOffset && OrigonalOffset != -1)
                        {
                            byte[] _old = BitConverter.GetBytes(OrigonalOffset);
                            _old = new byte[] { _old[0], _old[1], _old[2], (byte)(_old[3] + 0x8) };

                            byte[] _new = BitConverter.GetBytes(this.SaveOffset);
                            _new = new byte[] { _new[0], _new[1], _new[2], (byte)(_new[3] + 0x8) };

                            NSE_Framework.Find find            = new NSE_Framework.Find(Program.MainForm.Filename);
                            List <int>         ReplacedOffsets = new List <int>();

                            if (!Program.MainForm.AdvancedRepointing)
                            {
                                find.SearchAndReplace(_old, _new, out ReplacedOffsets);

                                if (ReplacedOffsets.Count != 0)
                                {
                                    string mes = "";
                                    foreach (int i in ReplacedOffsets)
                                    {
                                        mes = mes + " 0x" + i.ToString("X2");
                                    }

                                    MessageBox.Show(this, "Replaced the pointers at offsets:\n\n" + mes, "Notice.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                                    Program.MainForm.LogWriter.LogMessage("Replaced pointers at offsets: " + mes);
                                    this.Close();
                                }
                                else
                                {
                                    this.Close();
                                }
                            }
                            else
                            {
                                ReplacedOffsets = find.Search(_old);
                                if (ReplacedOffsets.Count != 0)
                                {
                                    NSE2.SelectOffsets so = new SelectOffsets(ReplacedOffsets);
                                    so.ShowDialog(this);
                                    if (so.DialogResult == System.Windows.Forms.DialogResult.OK)
                                    {
                                        ReplacedOffsets = so.SelectedOffsets;

                                        if (ReplacedOffsets.Count != 0)
                                        {
                                            foreach (int o in ReplacedOffsets)
                                            {
                                                write.WriteBytes(_new, o);
                                            }

                                            string mes = "";
                                            foreach (int i in ReplacedOffsets)
                                            {
                                                mes = mes + " 0x" + i.ToString("X2");
                                            }

                                            MessageBox.Show(this, "Replaced the pointers at offsets:\n\n" + mes, "Notice.", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                                            Program.MainForm.LogWriter.LogMessage("Replaced pointers at offsets: " + mes);

                                            this.Close();
                                        }
                                        else
                                        {
                                            this.Close();
                                        }
                                    }
                                    else if (so.DialogResult == System.Windows.Forms.DialogResult.Cancel)
                                    {
                                        this.Close();
                                    }
                                }
                                else
                                {
                                    this.Close();
                                }
                            }
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, Data.Length.ToString() + " bytes is too long for this offset, Aborting", "Abort", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SaveOffset = -1;
                    }
                }
                else
                {
                    MessageBox.Show(this, "Aborted:\n\t0x" + this.SaveOffset.ToString("X") + " is not a PointerSafe offset.\nPointerSafe offsets end in 0, 4, 8, or C.\n\nTo disable SafetyRepointing, un-check Options>Safety Repointing.", "Safety Repointing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                TextBox1.Text = (Program.MainForm.Read.FileLength - 513).ToString("X");
            }
        }