Example #1
0
void CGeneralCRC::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_CRC_BITS, ctl_bits_);
	DDX_Control(pDX, IDC_CRC_SELECT, select_menu_);
	DDX_Control(pDX, IDC_CRC_POLY, ctl_poly_);
	DDX_Control(pDX, IDC_CRC_INITREM, ctl_init_rem_);
	DDX_Control(pDX, IDC_CRC_FINALXOR, ctl_final_xor_);
	DDX_Text(pDX, IDC_CRC_NOTE, note_);
	DDX_CBIndex(pDX, IDC_CRC_BITS, bits_idx_);
	DDX_Check(pDX, IDC_CRC_REFLECTREM, par_.reflect_rem);
	DDX_Check(pDX, IDC_CRC_REFLECTIN, par_.reflect_in);

	// We need to handle DDX for the hex values ourselves as there are now hex DDV routines
	if (pDX->m_bSaveAndValidate)
	{
		CString ss;

		ctl_poly_.GetWindowText(ss);
		par_.poly = ::strtoi64(ss, 16);
		if (par_.poly > max_)
		{
			TaskMessageBox("Truncated Polynomial Too Big",
				"The value must fit within the number of bits specified.");
			pDX->Fail();
		}
		ctl_init_rem_.GetWindowText(ss);
		par_.init_rem = ::strtoi64(ss, 16);
		if (par_.init_rem > max_)
		{
			TaskMessageBox("Initial Remainder Too Big",
				"The value must fit within the number of bits specified.");
			pDX->Fail();
		}
		ctl_final_xor_.GetWindowText(ss);
		par_.final_xor = ::strtoi64(ss, 16);
		if (par_.final_xor > max_)
		{
			TaskMessageBox("Final XOR Value Too Big",
				"The value must fit within the number of bits specified.");
			pDX->Fail();
		}
	}
	else
	{
		CString ss;

		ss.Format(theApp.hex_ucase_ ? "%I64X" : "%I64x", __int64(par_.poly));
		ctl_poly_.SetWindowText(ss);
		ctl_poly_.add_spaces();

		ss.Format(theApp.hex_ucase_ ? "%I64X" : "%I64x", __int64(par_.init_rem));
		ctl_init_rem_.SetWindowText(ss);
		ctl_init_rem_.add_spaces();

		ss.Format(theApp.hex_ucase_ ? "%I64X" : "%I64x", __int64(par_.final_xor));
		ctl_final_xor_.SetWindowText(ss);
		ctl_final_xor_.add_spaces();
	}
}
Example #2
0
void CNewFile::OnOK()
{
	UpdateData();

	switch (fill_.type)
	{
	case FILL_HEX:
		// Make sure at least one hex digit has been entered
		if (strcspn(fill_hex_value_, "0123456789abcdefABCDEF") == fill_hex_value_.GetLength())
		{
			TaskMessageBox("No Hex Data", "Please enter at least one hex digit.");
			ctl_hex_value_.SetFocus();
			return;
		}
		break;
	case FILL_STRING:
		// Make sure the string is not empty
		if (fill_string_value_.IsEmpty())
		{
			TaskMessageBox("Empty String", "Please enter one or more characters.");
			ctl_fill_string_value_.SetFocus();
			return;
		}
		break;
	case FILL_RANDOM:
		{
			range_set<int> rand_rs;    // The range(s) of values for random fills
			std::istringstream str((const char *)(fill_random_range_));
			str >> rand_rs;

			if (rand_rs.empty() || *(rand_rs.begin()) > 255)
			{
				TaskMessageBox("Range Required", "Please enter a byte (decimal) "
							  "value or one or more ranges using values from 0 to 255.");
				ctl_fill_random_range_.SetFocus();
				return;
			}
		}
		// Make sure there is at least one byte between 0 and 255 in the range
		break;
	case FILL_NUMBER:
		// Make sure there is a number
		if (strcspn(fill_number_value_, "0123456789") == fill_number_value_.GetLength())
		{
			TaskMessageBox("Number Required", "Please enter a number.");
			ctl_fill_number_value_.SetFocus();
			return;
		}
		break;
	}

	// Save 40 bit number from fill_size_ (if size_src == 0) or fill_repeat_ (if size_src == 1)
	if (fill_.size_src == 1)
	{
		fill_.size_low = (unsigned long)fill_repeat_;
		fill_.size_high = (unsigned char)(fill_repeat_>>32);
	}
Example #3
0
void CGeneralCRC::OnSave()
{
	if (!UpdateData())
		return;

	// Get the name to save the settings under and check its valid
	CString strName;
	GetDlgItemText(IDC_CRC_NAME, strName);
	if (strName.IsEmpty())
	{
		TaskMessageBox("Invalid Name", "The CRC name cannot be empty");
		return;
	}
	else if (find_name(strName) != -1)
	{
		CString ss;
		ss.Format("The name \"%s\" is already being used.  "
			        "Please choose another name.", strName);
		TaskMessageBox("Name in Use", ss);
		return;
	}

	// Get the current settings to be associated with the name
	CString params = SaveParams();

	// Add the name to the end of the Select menu
	CMenu menu;
	menu.Attach(select_menu_.m_hMenu);
	menu.AppendMenu(MF_STRING, settings_.size(), strName);
	menu.Detach();

	// Add corresponding parameters to the end of settings_
	settings_.push_back(params);

	// Add to the registry (for next time the dialog is opened)
	HKEY hkey;
	if (::RegCreateKey(HKEY_CURRENT_USER, reg_locn, &hkey) == ERROR_SUCCESS)
	{
		::RegSetValueEx(hkey, strName, 0, REG_SZ, (BYTE *)params.GetBuffer(), params.GetLength()+1);
		::RegCloseKey(hkey);
	}

	// Disable Save button as we can't save again with the same name
	GetDlgItem(IDC_CRC_SAVE)->EnableWindow(FALSE);
}
Example #4
0
void CPassword::OnOK()
{
	if (!UpdateData())
		return;

	// Check that the password is the minimum size
	if (m_password.IsEmpty())
	{
		TaskMessageBox("No Password", "Please enter the password");
		ASSERT(GetDlgItem(IDC_PASSWORD_ENTER) != NULL);
		GetDlgItem(IDC_PASSWORD_ENTER)->SetFocus();
		return;
	}
	else if (m_mask && m_reentered.IsEmpty())
	{
		TaskMessageBox("No Password", "Please re-enter the password");
		ASSERT(GetDlgItem(IDC_PASSWORD_REENTER) != NULL);
		GetDlgItem(IDC_PASSWORD_REENTER)->SetFocus();
		return;
	}
	else if (m_mask && m_password != m_reentered)
	{
		TaskMessageBox("Passwords Different", "The passwords are not the same.");
		ASSERT(GetDlgItem(IDC_PASSWORD_ENTER) != NULL);
		GetDlgItem(IDC_PASSWORD_ENTER)->SetFocus();
		return;
	}
	else if (m_password.GetLength() < m_min)
	{
		TaskMessageBox("Password Too Short", "The password is too short");
		ASSERT(GetDlgItem(IDC_PASSWORD_ENTER) != NULL);
		GetDlgItem(IDC_PASSWORD_ENTER)->SetFocus();
		return;
	}

	CHexEditApp *aa = dynamic_cast<CHexEditApp *>(AfxGetApp());
	aa->password_mask_ = m_mask;
	aa->password_min_ = m_min;

	CDialog::OnOK();
}
Example #5
0
bool CDFFDJump::check_data()
{
	// Get values from the controls and validate them
	UpdateData();

	if (!valid_element_)
	{
		TaskMessageBox("JUMP Element Required", "A JUMP element requires exactly one sub-element.  Please add the element of the JUMP.\n");
		ctl_replace_.SetFocus();
		return false;
	}

	// xxx TBD check that the address offset is a valid intger expression

	return true;
}
Example #6
0
void CGeneralCRC::OnDelete()
{
	// First check that we selected from the list (using Select menu)
	// else we don't know what to delete
	if (last_selected_ < last_predefined_ || last_selected_ >= settings_.size())
	{
		assert(0);   // Code should prevent this from happening
		return;
	}

	// Delete from the Select menu
	CMenu menu;
	menu.Attach(select_menu_.m_hMenu);
	CString strName = get_menu_text(&menu, last_selected_);  // save mneu item name - used to delete reg value by name

	CString mess;
	mess.Format("Are you sure you want to delete the settings for %s", strName);
	if (TaskMessageBox("Delete CRC Settings", mess, MB_YESNO) != IDYES)
	{
		menu.Detach();
		return;
	}
	menu.DeleteMenu(last_selected_, MF_BYCOMMAND);  // Delete menu item with selected ID
	menu.Detach();

	// Delete from settings_ (where ID == last_selected_ is the index into the array)
	settings_[last_selected_] = CString("");  // clear but don't delete unused entries (else menu item ID's won't mathc array indices)

	// Remove the setting from the registry
	HKEY hkey;
	if (::RegCreateKey(HKEY_CURRENT_USER, reg_locn, &hkey) == ERROR_SUCCESS)
	{
		::RegDeleteValue(hkey, strName);
		::RegCloseKey(hkey);
	}

	// Disable Delete button now as we just deleted it
	GetDlgItem(IDC_CRC_DELETE)->EnableWindow(FALSE);
}
bool CDFFDUseStruct::check_data()
{
	// Get values from the controls and validate them
	UpdateData();

	// Make sure name is given unless the container is a FOR (whence sub-elements are accessed via array index)
	if (name_.IsEmpty() && parent_type_ != CHexEditDoc::DF_FORV && parent_type_ != CHexEditDoc::DF_FORF)
	{
		TaskMessageBox("No Name", "Please enter a name for this element");
		ctl_name_.SetFocus();
		return false;
	}

	if (!name_.IsEmpty() && !valid_id(name_))
	{
		TaskMessageBox("Invalid STRUCT Name", "Please use alphanumeric characters (or "
						"underscores) and begin the name with an alphabetic character.");
		ctl_name_.SetFocus();
		return false;
	}
	if (name_.CompareNoCase("true") == 0 ||
		name_.CompareNoCase("false") == 0 ||
		name_.CompareNoCase("end") == 0 ||
		expr_eval::func_token(name_) != expr_eval::TOK_NONE)
	{
		TaskMessageBox("Reserved Name", name_ + " is reserved for internal use. Please choose another name.");
		ctl_name_.SetFocus();
		return false;
	}

	if (struct_.IsEmpty())
	{
		TaskMessageBox("No Defined Struct", "Please select a defined struct for this element");
		ctl_struct_.SetFocus();
		return false;
	}
	else if (!valid_id(struct_))
	{
		TaskMessageBox("Invalid Defined Struct Name", "Please use alphanumeric characters "
					  "(or underscore) and start with a alphabetic character.");
		ctl_name_.SetFocus();
		return false;
	}

	// We can only have an empty name if parent is FOR in which case there are no siblings
	ASSERT(!name_.IsEmpty() || pelt_->GetParent().GetNumChildren() == 1);

	// Check that the name is not the same as any siblings
	CXmlTree::CElt ee;

	// First find the actual element whose siblings we want to check (an IF takes the name of its child)
	for (ee = *pelt_; ee.GetParent().GetName() == "if" || ee.GetParent().GetName() == "jump"; ee = ee.GetParent())
		; // empty loop body

	// Check that older siblings don't have the same name
	for (ee--; !ee.IsEmpty(); ee--)
	{
		CXmlTree::CElt ee2;
		for (ee2 = ee; !ee2.IsEmpty() && (ee2.GetName() == "if" || ee2.GetName() == "jump"); ee2 = ee2.GetFirstChild())
			; // nothing here
		if (!ee2.IsEmpty() && ee2.GetAttr("name") == name_)
		{
			TaskMessageBox("Name in use", name_ + " has a sibling with the same name.\n\n"
				           "It is not be possible to differentiate between two elements "
			               "with the same name at the same level (eg, in expressions).");
			ctl_name_.SetFocus();
			return false;
		}
	}

	for (ee = *pelt_; ee.GetParent().GetName() == "if" || ee.GetParent().GetName() == "jump"; ee = ee.GetParent())
		; // empty loop body

	// Check that younger siblings don't have the same name
	for (++ee; !ee.IsEmpty(); ++ee)
	{
		CXmlTree::CElt ee2;
		for (ee2 = ee; !ee2.IsEmpty() && (ee2.GetName() == "if" || ee2.GetName() == "jump"); ee2 = ee2.GetFirstChild())
			; // nothing here
		if (!ee2.IsEmpty() && ee2.GetAttr("name") == name_)
		{
			TaskMessageBox("Name in use", name_ + " has a sibling with the same name.\n\n"
				           "It is not be possible to differentiate between two elements "
			               "with the same name at the same level (eg, in expressions).");
			ctl_name_.SetFocus();
			return false;
		}
	}

	return true;
}
Example #8
0
void CDFFDJump::OnReplace()
{
	// See if we have a subelement to replace (otherwise we just insert)
	CXmlTree::CElt curr_elt(pelt_->GetFirstChild());
	if (!curr_elt.IsEmpty())
	{
		ASSERT(valid_element_);
		CString sub_name = get_name(curr_elt);

		CString mess;
		if (curr_elt.GetFirstChild().IsEmpty())
		{
			mess.Format("This will replace the contents of %s.  "
						"The existing contents will be deleted.\n\n"
						"Are you sure you want to do this?", sub_name);
		}
		else
		{
			mess.Format("This will replace the contents of %s "
						"and all elements below it.  "
						"The existing contents will be deleted.\n\n"
						"Are you sure you want to do this?", sub_name);
		}
		if (TaskMessageBox("Replacing Element", mess, MB_YESNO) != IDYES)
			return;

		pelt_->DeleteChild(curr_elt);         // Remove the replaced node from the tree
	}

	// Work out where to put the dialog
	pos_ = update_posn(this);
	if (first_) orig_ = pos_;
	CPoint pt = get_posn(this, orig_);
	int dlg_ret;
	CXmlTree::CElt ee;

	switch (ctl_replace_.m_nMenuResult)
	{
	case ID_DFFD_INSERT_STRUCT:
		ee = pelt_->InsertNewChild("struct");

		{
			CDFFDStruct dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt,orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_USE_STRUCT:
		ee = pelt_->InsertNewChild("use_struct", NULL);

		{
			CDFFDUseStruct dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt,orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_FOR:
		ee = pelt_->InsertNewChild("for");

		{
			CDFFDFor dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_IF:
		ee = pelt_->InsertNewChild("if");
		ee.SetAttr("test", "true");

		{
			CDFFDIf dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_SWITCH:
		ee = pelt_->InsertNewChild("switch");

		{
			CDFFDSwitch dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	case ID_DFFD_INSERT_DATA:
		ee = pelt_->InsertNewChild("data");
		ee.SetAttr("type", "none");

		{
			CDFFDData dlg(&ee, CHexEditDoc::DF_JUMP, this);
			dlg.SetModified();          // Force validation as it is incomplete
			dlg.SetPosition(pt, orig_);
			dlg_ret = dlg.DoModal();
		}
		break;
	default:
		ASSERT(0);
	}

	if (dlg_ret == IDCANCEL)
	{
		// Restore elts again (remove new element, add back old elt)
		pelt_->DeleteChild(ee);
		if (!curr_elt.IsEmpty())
		{
			ASSERT(valid_element_);
			pelt_->InsertChild(curr_elt, NULL);
		}
		return;
	}

	modified_ = true;
	valid_element_ = true;

	UpdateData(TRUE);
	elt_name_ = get_name(ee);
	UpdateData(FALSE);
}