private void btnAdd_Click(object sender, EventArgs e) { if (txtAddress.Text == "" || txtData.Text == "") { return; } DetectRule DR = new DetectRule(); DR.address = txtAddress.Text; DR.compare = comboCompare.Text; UInt64 x; HexToUint64(txtData.Text, out x); DR.data = x; DR.group = (ushort)numGroup.Value; DR.grouplogic = comboGroupLogic.Text; DR.xml = comboXML.Text; DetectRules.Add(DR); var item = new ListViewItem(DR.address); item.SubItems.Add(DR.compare); item.SubItems.Add(DR.data.ToString("X")); item.SubItems.Add(DR.group.ToString()); item.SubItems.Add(DR.grouplogic); item.Tag = DetectRules.Count - 1; listRules.Items.Add(item); comboGroupLogic.Enabled = false; LoadXMLList(); }
private void btnReplace_Click(object sender, EventArgs e) { if (txtAddress.Text == "" || txtData.Text == "") { return; } if (listRules.SelectedItems.Count == 0) { return; } DetectRule DR = new DetectRule(); int d = (int)listRules.SelectedItems[0].Tag; DR.address = txtAddress.Text; DR.compare = comboCompare.Text; UInt64 x; HexToUint64(txtData.Text, out x); DR.data = x; DR.group = (ushort)numGroup.Value; DR.grouplogic = comboGroupLogic.Text; DR.xml = comboXML.Text; DetectRules[d] = DR; listRules.SelectedItems[0].SubItems[0].Text = txtAddress.Text; listRules.SelectedItems[0].SubItems[1].Text = comboCompare.Text; listRules.SelectedItems[0].SubItems[2].Text = txtData.Text; listRules.SelectedItems[0].SubItems[3].Text = numGroup.Value.ToString(); listRules.SelectedItems[0].SubItems[4].Text = comboGroupLogic.Text; }
private void btnRenameXML_Click(object sender, EventArgs e) { frmRenameXML frmN = new frmRenameXML(); frmN.txtOldXML.Text = comboXML.Text; frmN.txtNewXML.Text = comboXML.Text; if (frmN.ShowDialog(this) == DialogResult.OK) { for (int d = 0; d < DetectRules.Count; d++) { if (DetectRules[d].xml.ToLower() == frmN.txtOldXML.Text.ToLower()) { DetectRule DR = DetectRules[d]; DR.xml = frmN.txtNewXML.Text; DetectRules[d] = DR; } } InitMe(); if (frmN.txtOldXML.Text == comboXML.Text) { comboXML.Text = frmN.txtNewXML.Text; } SelectXML(); } frmN.Dispose(); }
private bool CheckRule(DetectRule DR, PcmFile PCM) { try { UInt64 Data = 0; uint Addr = 0; if (DR.address == "filesize") { Data = (UInt64) new FileInfo(PCM.FileName).Length; } else { string[] Parts = DR.address.Split(':'); HexToUint(Parts[0].Replace("@", ""), out Addr); if (DR.address.StartsWith("@")) { Addr = BEToUint32(PCM.buf, Addr); } if (Parts[0].EndsWith("@")) { Addr = (uint)PCM.buf.Length - Addr; } if (Parts.Length == 1) { Data = BEToUint16(PCM.buf, Addr); } else { if (Parts[1] == "1") { Data = (uint)PCM.buf[Addr]; } if (Parts[1] == "2") { Data = (uint)BEToUint16(PCM.buf, Addr); } if (Parts[1] == "4") { Data = BEToUint32(PCM.buf, Addr); } if (Parts[1] == "8") { Data = BEToUint64(PCM.buf, Addr); } } } //Logger(DR.xml + ": " + DR.address + ": " + DR.data.ToString("X") + DR.compare + "(" + DR.grouplogic + ") " + " [" + Addr.ToString("X") + ": " + Data.ToString("X") + "]"); if (DR.compare == "==") { if (Data == DR.data) { return(true); } } if (DR.compare == "<") { if (Data < DR.data) { return(true); } } if (DR.compare == ">") { if (Data > DR.data) { return(true); } } if (DR.compare == "!=") { if (Data != DR.data) { return(true); } } //Logger("Not match"); return(false); } catch (Exception ex) { //Something wrong, just skip this part and continue Debug.WriteLine(ex.Message); return(false); } }