Exemple #1
0
/**
 * @brief Handle dialog commands.
 * @param [in] hDlg Hanle to the dialog.
 * @param [in] wParam The command to handle.
 * @param [in] lParam Optional parameter for the command.
 * @return TRUE if the command was handled, FALSE otherwise.
 */
BOOL CopyHexdumpDlg::OnCommand(HWindow *pDlg, WPARAM wParam, LPARAM lParam)
{
	int iCopyHexdumpDlgStart, iCopyHexdumpDlgEnd;
	const int bufSize = 16;
	TCHAR buf[bufSize + 1];
	switch (wParam)
	{
	case IDOK:
		if (pDlg->GetDlgItemText(IDC_HEXDUMP_OFFSET, buf, bufSize) &&
			offset_parse(buf, iCopyHexdumpDlgStart) &&
			pDlg->GetDlgItemText(IDC_HEXDUMP_OFFSET2, buf, bufSize) &&
			offset_parse(buf, iCopyHexdumpDlgEnd))
		{
			iCopyHexdumpMode = pDlg->IsDlgButtonChecked(IDC_HEXDUMP_EXPORTCLIPB);
			if (pDlg->IsDlgButtonChecked(IDC_EXPORTDISPLAY))
				iCopyHexdumpType = IDC_EXPORTDISPLAY;
			else if (pDlg->IsDlgButtonChecked(IDC_EXPORTDIGITS))
				iCopyHexdumpType = IDC_EXPORTDIGITS;
			else if (pDlg->IsDlgButtonChecked(IDC_EXPORTRTF))
				iCopyHexdumpType = IDC_EXPORTRTF;

			pDlg->EndDialog(wParam);
			WaitCursor w1;
			CMD_copy_hexdump(iCopyHexdumpMode, iCopyHexdumpType, iCopyHexdumpDlgStart, iCopyHexdumpDlgEnd);
			return TRUE;
		}
		break;
	case IDCANCEL:
		pDlg->EndDialog(wParam);
		return TRUE;
	}
	return FALSE;
}
Exemple #2
0
/**
 * @brief Copy the bytes.
 * @param [in] hDlg Handle to the dialog.
 * @return TRUE if bytes were copied, FALSE otherwise.
 */
BOOL CopyDlg::Apply(HWindow* pDlg)
{
	const int bufSize = 64;
	TCHAR buf[bufSize + 1] = {0};
	int iOffset;
	int iNumberOfBytes;
	if (pDlg->GetDlgItemText(IDC_COPY_STARTOFFSET, buf, bufSize) &&
		!offset_parse(buf, iOffset))
	{
		MessageBox(pDlg, GetLangString(IDS_OFFSET_START_ERROR), MB_ICONERROR);
		return FALSE;
	}
	if (pDlg->IsDlgButtonChecked(IDC_COPY_OFFSET))
	{
		if (pDlg->GetDlgItemText(IDC_COPY_OFFSETEDIT, buf, bufSize) &&
			!offset_parse(buf, iNumberOfBytes))
		{
			MessageBox(pDlg, GetLangString(IDS_OFFSET_END_ERROR), MB_ICONERROR);
			return FALSE;
		}
		iNumberOfBytes = iNumberOfBytes - iOffset + 1;
	}
	else
	{// Get number of bytes.
		if (pDlg->GetDlgItemText(IDC_COPY_BYTECOUNT, buf, bufSize) &&
			_stscanf(buf, _T("%d"), &iNumberOfBytes) == 0)
		{
			MessageBox(pDlg, GetLangString(IDS_BYTES_NOT_KNOWN), MB_ICONERROR);
			return FALSE;
		}
	}
	// Can requested number be cut?
	// DataArray.GetLength ()-iCutOffset = number of bytes from current pos. to end.
	if (m_dataArray.GetLength() - iOffset < iNumberOfBytes)
	{
		MessageBox(pDlg, GetLangString(IDS_COPY_TOO_MANY), MB_ICONERROR);
		return FALSE;
	}
	// Transfer to clipboard.
	int destlen = Text2BinTranslator::iBytes2BytecodeDestLen(&m_dataArray[iOffset], iNumberOfBytes);
	HGLOBAL hGlobal = GlobalAlloc(GHND, destlen);
	if (hGlobal == 0)
	{
		// Not enough memory for clipboard.
		MessageBox(pDlg, GetLangString(IDS_COPY_NO_MEM), MB_ICONERROR);
		return FALSE;
	}
	WaitCursor wc;
	char* pd = (char *)GlobalLock(hGlobal);
	Text2BinTranslator::iTranslateBytesToBC(pd, &m_dataArray[iOffset], iNumberOfBytes);
	GlobalUnlock(hGlobal);
	pwnd->OpenClipboard();
	EmptyClipboard();
	SetClipboardData(CF_TEXT, hGlobal);
	CloseClipboard();
	return TRUE;
}
Exemple #3
0
/**
 * @brief Go to offset user gave to the dialog.
 * @param [in] hDlg Handle of Goto-dialog.
 * @return TRUE if new offset was applied, FALSE for invalid offset.
 */
BOOL GoToDlg::Apply(HWindow *pDlg)
{
	TCHAR buffer[EditLen + 1];
	int offset, i = 0, r = 0;
	pDlg->GetDlgItemText(IDC_GOTO_OFFSET, buffer, RTL_NUMBER_OF(buffer));
	// For a relative jump, read offset from 2nd character on.
	if (buffer[0] == '+' || buffer[0] == '-')
		r = 1;
	if (!offset_parse(buffer + r, offset))
	{
		MessageBox(pDlg, GetLangString(IDS_OFFSET_ERROR), MB_ICONERROR);
		return FALSE;
	}
	if (r)
	{
		// Relative jump.
		if (buffer[0] == '-' )
			offset = -offset;
		offset += iCurByte;
	}
	
	// Absolute jump.
	// Check limits and jump to begin/end if out of limits
	if (offset < 0)
		offset = 0;
	if (offset >= m_dataArray.GetLength())
		offset = m_dataArray.GetLength() - 1;

	iCurByte = offset;
	snap_caret();
	return TRUE;
}
/**
 * @brief Read end offset value from the dialog.
 * @param [in] hDlg Handle to the dialog.
 * @param [out] value Value read from the dialog.
 * @return true if the value was read, false if value could not be read.
 */
bool MoveCopyDlg::ReadEndOffset(HWND hDlg, int & value)
{
	TCHAR buf[30] = {0};
	HWND cntrl = GetDlgItem(hDlg, IDC_2NDDELIM);
	GetWindowText(cntrl, buf, RTL_NUMBER_OF(buf));
	int i = 0;
	if (buf[i] == '-')
	{
		if (!IsDlgButtonChecked(hDlg, IDC_LEN))
		{
			LangString negativeOffset(IDS_CM_NEGATIVE_OFFSET);
			MessageBox(hDlg, negativeOffset, MB_ICONERROR);
			return false;
		}
		// Relative jump. Read offset from next character on.
		i++;
	}
	
	// Skip the '-' if present
	if (!offset_parse(&buf[i], value))
	{
		LangString endOffsetErr(IDS_OFFSET_END_ERROR);
		MessageBox(hDlg, endOffsetErr, MB_ICONERROR);
		return false;
	}
	if (buf[0] == '-')
		value = -value; // Negate
	return true;
}
Exemple #5
0
/**
 * @brief Handle dialog commands.
 * @param [in] hDlg Hanle to the dialog.
 * @param [in] wParam The command to handle.
 * @param [in] lParam Optional parameter for the command.
 * @return TRUE if the command was handled, FALSE otherwise.
 */
BOOL SelectBlockDlg::OnCommand(HWindow *pDlg, WPARAM wParam, LPARAM lParam)
{
	TCHAR buf[128];
	int iStartOfSelSetting = 0;
	int iEndOfSelSetting =  0;
	int maxb;
	switch (wParam)
	{
	case IDOK:
		if (pDlg->GetDlgItemText(IDC_BLOCKSEL_OFFSET, buf, 128) &&
			!offset_parse(buf, iStartOfSelSetting))
		{
			MessageBox(pDlg, GetLangString(IDS_OFFSET_START_ERROR), MB_ICONERROR);
			return TRUE;
		}
		if (pDlg->GetDlgItemText(IDC_BLOCKSEL_OFFSETEND, buf, 128) &&
			!offset_parse(buf, iEndOfSelSetting))
		{
			MessageBox(pDlg, GetLangString(IDS_OFFSET_END_ERROR), MB_ICONERROR);
			return TRUE;
		}
		//make the selection valid if it is not
		maxb = m_dataArray.GetUpperBound();
		if (iStartOfSelSetting < 0)
			iStartOfSelSetting = 0;
		if (iStartOfSelSetting > maxb)
			iStartOfSelSetting = maxb;
		if (iEndOfSelSetting < 0)
			iEndOfSelSetting = 0;
		if (iEndOfSelSetting > maxb)
			iEndOfSelSetting = maxb;
		iStartOfSelection = iStartOfSelSetting;
		iEndOfSelection = iEndOfSelSetting;
		bSelected = true;
		adjust_view_for_selection();
		repaint();
		// fall through
	case IDCANCEL:
		pDlg->EndDialog(wParam);
		return TRUE;
	}
	return FALSE;
}
/**
 * @brief Read start offset value from the dialog.
 * @param [in] hDlg Handle to the dialog.
 * @param [out] value Value read from the dialog.
 * @return true if the value was read, false if value could not be read.
 */
bool MoveCopyDlg::ReadStartOffset(HWND hDlg, int & value)
{
	TCHAR buf[30] = {0};
	HWND cntrl = GetDlgItem(hDlg, IDC_1STOFFSET);
	GetWindowText(cntrl, buf, RTL_NUMBER_OF(buf));

	if (buf[0] == '-')
	{
		LangString negativeOffset(IDS_CM_NEGATIVE_OFFSET);
		MessageBox(hDlg, negativeOffset, MB_ICONERROR);
		return false;
	}

	if (!offset_parse(&buf[0], value))
	{
		LangString startOffsetErr(IDS_OFFSET_START_ERROR);
		MessageBox(hDlg, startOffsetErr, MB_ICONERROR);
		return false;
	}
	return true;
}
Exemple #7
0
/**
 * @brief Cut the data.
 * This function cuts the data based on values user entered to the dialog.
 * @param [in] hDlg Handle to the dialog.
 * @return TRUE if the cutting succeeded, FALSE otherwise.
 */
BOOL CutDlg::Apply(HWND hDlg)
{
	TCHAR buf[OffsetLen + 1] = {0};
	int iOffset;
	int iNumberOfBytes;

	if (GetDlgItemText(hDlg, IDC_CUT_STARTOFFSET, buf, OffsetLen) &&
		!offset_parse(buf, iOffset))
	{
		LangString startOffsetErr(IDS_OFFSET_START_ERROR);
		MessageBox(hDlg, startOffsetErr, MB_ICONERROR);
		return FALSE;
	}

	if (IsDlgButtonChecked(hDlg, IDC_CUT_INCLUDEOFFSET))
	{
		if (GetDlgItemText(hDlg, IDC_CUT_ENDOFFSET, buf, OffsetLen) &&
			!offset_parse(buf, iNumberOfBytes))
		{
			LangString endOffsetErr(IDS_OFFSET_END_ERROR);
			MessageBox(hDlg, endOffsetErr, MB_ICONERROR);
			return FALSE;
		}
		iNumberOfBytes = iNumberOfBytes - iOffset + 1;
	}
	else
	{// Get number of bytes.
		if (GetDlgItemText(hDlg, IDC_CUT_NUMBYTES, buf, OffsetLen) &&
			_stscanf(buf, _T("%d"), &iNumberOfBytes) == 0)
		{
			LangString notRecognized(IDS_BYTES_NOT_KNOWN);
			MessageBox(hDlg, notRecognized, MB_ICONERROR);
			return FALSE;
		}
	}

	// Can requested number be cut?
	// DataArray.GetLength ()-iCutOffset = number of bytes from current pos. to end.
	if (m_dataArray.GetLength() - iOffset < iNumberOfBytes)
	{
		LangString tooMany(IDS_CUT_TOO_MANY);
		MessageBox(hDlg, tooMany, MB_ICONERROR);
		return FALSE;
	}

	// Transfer to cipboard.
	int destlen = Text2BinTranslator::iBytes2BytecodeDestLen(&m_dataArray[iOffset], iNumberOfBytes);
	HGLOBAL hGlobal = GlobalAlloc(GHND, destlen);
	if (hGlobal == 0)
	{
		// Not enough memory for clipboard.
		LangString noMem(IDS_CUT_NO_MEM);
		MessageBox(hDlg, noMem, MB_ICONERROR);
		return FALSE;
	}
	WaitCursor wc;
	TCHAR *pd = (TCHAR *)GlobalLock(hGlobal);
	Text2BinTranslator::iTranslateBytesToBC(pd, &m_dataArray[iOffset], iNumberOfBytes);
	GlobalUnlock(hGlobal);
	OpenClipboard(hwnd);
	EmptyClipboard();
	SetClipboardData(CF_TEXT, hGlobal);
	CloseClipboard();

	// Delete data.
	if (!m_dataArray.RemoveAt(iOffset, iNumberOfBytes))
	{
		LangString cutFailed(IDS_CUT_FAILED);
		MessageBox(hDlg, cutFailed, MB_ICONERROR);
		return FALSE;
	}
	iCurByte = iOffset;
	if (iCurByte > m_dataArray.GetUpperBound())
		iCurByte = m_dataArray.GetUpperBound();
	if (iCurByte < 0)
		iCurByte = 0;
	iFileChanged = TRUE;
	bFilestatusChanged = true;
	bSelected = false;
	resize_window();
	return TRUE;
}