コード例 #1
0
 private void searchValues_KeyDown(object sender, KeyEventArgs e)
 {
     if (searchBox.Text == "" ||
         searchBox.Text.Length % 2 != 0 ||
         e.KeyData != Keys.Enter)
     {
         return;
     }
     try
     {
         byte[] values = new byte[searchBox.Text.Length / 2];
         for (int i = 0; i < searchBox.Text.Length / 2; i++)
         {
             string ascii = searchBox.Text.Substring(i * 2, 2);
             byte   value = Convert.ToByte(ascii, 16);
             values[i] = value;
         }
         int offset, foundAt;
         offset  = this.offset;
         foundAt = Bits.Find(rom, values, ROMData.SelectionStart / 3 + ROMData.SelectionLength + offset);
         if (foundAt != -1)
         {
             this.offset     = foundAt & 0xFFFFF0;
             selectionStart  = (foundAt & 15) * 3;
             selectionLength = values.Length * 3;
             RefreshHexEditor();
             searchBox.Focus();
         }
         else if (MessageBox.Show("Search string was not found.\n\n" + "Restart from beginning?", "LAZY SHELL",
                                  MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             offset  = this.offset;
             foundAt = Bits.Find(rom, values, 0);
             if (foundAt != -1)
             {
                 this.offset     = foundAt & 0xFFFFF0;
                 selectionStart  = (foundAt & 15) * 3;
                 selectionLength = values.Length * 3;
                 RefreshHexEditor();
                 searchBox.Focus();
             }
             else
             {
                 MessageBox.Show("Search string was not found.");
             }
         }
     }
     catch
     {
         MessageBox.Show("Invalid search string.");
     }
 }