Пример #1
0
/**
 * @brief Handle dialog closing with OK button (and applying the changes).
 * @param [in] hDlg Handle 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 EncodeDecodeDialog::OnOK(HWND hDlg, WPARAM wParam, LPARAM lParam)
{
	MEMORY_CODING mc;
	TCHAR szBuffer[1024];
	GetDlgItemText(hDlg, IDC_ENCODE_ARGS, szBuffer, sizeof(szBuffer));
	mc.bEncode = IsDlgButtonChecked(hDlg, IDC_ENCODE_ENC);
	mc.lpszArguments = szBuffer;
	HWND hListbox = GetDlgItem(hDlg, IDC_ENCODE_LIST);
	int nCurSel = SendMessage(hListbox, LB_GETCURSEL, 0, 0);
	if (nCurSel < 0)
		return TRUE;
	mc.fpEncodeFunc = (LPFNEncodeMemoryFunction) SendMessage(hListbox, LB_GETITEMDATA, nCurSel, 0);
	int lower = 0;
	int upper = m_dataArray.GetUpperBound();
	if (bSelected)
	{
		lower = iGetStartOfSelection();
		upper = iGetEndOfSelection();
	}
	mc.lpbMemory = &m_dataArray[lower];
	mc.dwSize = upper - lower + 1;
	mc.fpEncodeFunc(&mc);
	iFileChanged = TRUE;
	bFilestatusChanged = true;
	repaint();
	EndDialog(hDlg, wParam);
	return TRUE;
}
Пример #2
0
/**
 * @brief Initialize the dialog.
 * @param [in] hDlg Handle to the dialog.
 */
BOOL CopyHexdumpDlg::OnInitDialog(HWindow *pDlg)
{
	int iCopyHexdumpDlgStart, iCopyHexdumpDlgEnd;
	if (!bSelected)
	{
		// Assume whole file is to be hexdumped. (except the last line (if incomplete))
		iCopyHexdumpDlgStart = 0;
		iCopyHexdumpDlgEnd = m_dataArray.GetUpperBound() / iBytesPerLine * iBytesPerLine;
	}
	else
	{
		// Assume selected area is to be hexdumped.
		// Make sure end of selection is greater than start of selection.
		iCopyHexdumpDlgStart = iGetStartOfSelection();
		iCopyHexdumpDlgEnd = iGetEndOfSelection();
	}
	TCHAR buf[16];
	_stprintf(buf, _T("0x%x"), iCopyHexdumpDlgStart);
	pDlg->SetDlgItemText(IDC_HEXDUMP_OFFSET, buf);
	_stprintf(buf, _T("0x%x"), iCopyHexdumpDlgEnd);
	pDlg->SetDlgItemText(IDC_HEXDUMP_OFFSET2, buf);
	pDlg->CheckDlgButton(iCopyHexdumpMode ? IDC_HEXDUMP_EXPORTCLIPB :
			IDC_HEXDUMP_EXPORTFILE, BST_CHECKED);
	pDlg->CheckDlgButton(iCopyHexdumpType, BST_CHECKED);
	return TRUE;
}
Пример #3
0
//-------------------------------------------------------------------
// SimpleString replacedata contains data to replace with.
bool ReplaceDlg::replace_selected_data(HWindow *pDlg)
{
    if (!bSelected)
    {
        MessageBox(pDlg, GetLangString(IDS_REPL_NO_DATA), MB_ICONERROR);
        return false;
    }
    int i = iGetStartOfSelection();
    int n = iGetEndOfSelection() - i + 1;
    SimpleArray<BYTE> olddata(n, &m_dataArray[i]);
    if (strReplaceWithData.IsEmpty())
    {
        // Selected data is to be deleted, since replace-with data is empty string.
        if (!m_dataArray.Replace(i, n, 0, 0))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_CANT_DELETE), MB_ICONERROR);
            return FALSE;
        }
        push_undorecord(i, olddata, olddata.GetLength(), NULL, 0);
        bSelected = false;
        iCurByte = iStartOfSelection;
    }
    else if (bPasteAsText)
    {
        // Replace with non-zero-length data.
        if (!m_dataArray.Replace(i, n, (const BYTE *)(const char *)strReplaceWithData, strReplaceWithData.StrLen()))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_FAILED), MB_ICONERROR);
            return false;
        }
        push_undorecord(i, olddata, olddata.GetLength(), (const BYTE *)(const char *)strReplaceWithData, strReplaceWithData.StrLen());
        iEndOfSelection = iStartOfSelection + strReplaceWithData.StrLen() - 1;
    }
    else
    {
        // Input string contains special-syntax-coded binary data.
        SimpleArray<BYTE> out;
        if (!transl_text_to_binary(out))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_CANNOT_CONVERT), MB_ICONERROR);
            return false;
        }
        if (!m_dataArray.Replace(i, n, out, out.GetLength()))
        {
            MessageBox(pDlg, GetLangString(IDS_REPL_FAILED), MB_ICONERROR);
            return false;
        }
        push_undorecord(i, olddata, olddata.GetLength(), out, out.GetLength());
        iEndOfSelection = iStartOfSelection + out.GetLength() - 1;
    }
    bFilestatusChanged = true;
    return true;
}
Пример #4
0
/**
 * @brief Initialize the dialog.
 * @param [in] hDlg Handle to the dialog.
 * @return TRUE
 */
BOOL CutDlg::OnInitDialog(HWND hDlg)
{
	int iStart = iGetStartOfSelection();
	int iEnd = iGetEndOfSelection();
	TCHAR buf[OffsetLen + 1] = {0};

	_stprintf(buf, _T("0x%x"), iStart);
	SetDlgItemText(hDlg, IDC_CUT_STARTOFFSET, buf);
	_stprintf(buf, _T("0x%x"), iEnd);

	CheckDlgButton(hDlg, IDC_CUT_INCLUDEOFFSET, BST_CHECKED);
	SetDlgItemText(hDlg, IDC_CUT_ENDOFFSET, buf);
	SetDlgItemInt(hDlg, IDC_CUT_NUMBYTES, iEnd - iStart + 1, TRUE);

	return TRUE;
}
Пример #5
0
/**
 * @brief Initialize the dialog.
 * @param [in] hDlg Handle to the dialog.
 * @return TRUE.
 */
BOOL CopyDlg::OnInitDialog(HWindow* pDlg)
{
	int iStart = iGetStartOfSelection();
	int iEnd = iGetEndOfSelection();
	TCHAR buf[32];
	_stprintf(buf, _T("0x%x"), iStart);
	pDlg->SetDlgItemText(IDC_COPY_STARTOFFSET, buf);
	_stprintf(buf, _T("0x%x"), iEnd);
	pDlg->SetDlgItemText(IDC_COPY_OFFSETEDIT, buf);
	pDlg->SetDlgItemInt(IDC_COPY_BYTECOUNT, iEnd - iStart + 1, TRUE);
	pDlg->CheckDlgButton(IDC_COPY_OFFSET, BST_CHECKED);
	// Limit edit text lengths
	pDlg->SendDlgItemMessage(IDC_COPY_STARTOFFSET, EM_SETLIMITTEXT, MaxTextLen);
	pDlg->SendDlgItemMessage(IDC_COPY_OFFSETEDIT, EM_SETLIMITTEXT, MaxTextLen);
	pDlg->SendDlgItemMessage(IDC_COPY_BYTECOUNT, EM_SETLIMITTEXT, MaxTextLen);
	return TRUE;
}
Пример #6
0
/**
 * @brief Initialize the dialog.
 * @param [in] hDlg Handle to the dialog.
 */
BOOL MoveCopyDlg::OnInitDialog(HWND hw)
{
	TCHAR buf[30] = {0};
	int iMove1stEnd = iGetStartOfSelection();
	int iMove2ndEndorLen = iGetEndOfSelection();
	_sntprintf(buf, RTL_NUMBER_OF(buf) - 1, _T("0x%x"), iMove1stEnd);
	SetDlgItemText (hw, IDC_1STOFFSET, buf);
	_sntprintf(buf, RTL_NUMBER_OF(buf) - 1, _T("0x%x"), iMove2ndEndorLen);
	SetDlgItemText (hw, IDC_2NDDELIM, buf);
	CheckDlgButton (hw, IDC_OTHEREND, BST_CHECKED);
	_sntprintf(buf, RTL_NUMBER_OF(buf) - 1, _T("0x%x"), iMovePos);
	SetDlgItemText(hw, IDC_MOVEMENT, buf);
	CheckDlgButton(hw, IDC_FPOS, BST_CHECKED);
	if (iMoveOpTyp == OPTYP_MOVE)
		CheckDlgButton(hw, IDC_MOVE, BST_CHECKED);
	else if (iMoveOpTyp == OPTYP_COPY)
		CheckDlgButton(hw, IDC_COPY, BST_CHECKED);
	return TRUE;
}
Пример #7
0
//-------------------------------------------------------------------
bool ReplaceDlg::find_and_select_data(int finddir, bool case_sensitive)
{
    BYTE *tofind;
    // Create a translation from bytecode to char array of finddata.
    int destlen = create_bc_translation(&tofind, strToReplaceData,
                                        strToReplaceData.StrLen(), iCharacterSet, iBinaryMode);
    int i = iGetStartOfSelection();
    int n = iGetEndOfSelection() - i + 1;
    int j;
    if (finddir >= 0)
    {
        i += finddir * n;
        // Find forward.
        j = findutils_FindBytes(&m_dataArray[i],
                                m_dataArray.GetLength() - i - 1,
                                tofind,	destlen, 1, case_sensitive);
        if (j != -1)
            i += j;
    }
    else
    {
        // Find backward.
        j = findutils_FindBytes(&m_dataArray[0],
                                min(iCurByte + (destlen - 1), m_dataArray.GetLength()),
                                tofind, destlen, -1, case_sensitive);
        if (j != -1)
            i = j;
    }
    bool done = false;
    if (j != -1)
    {
        // NEW: Select found interval.
        bSelected = true;
        iStartOfSelection = iCurByte = i;
        iEndOfSelection = iStartOfSelection + destlen - 1;
        done = true;
    }
    delete [] tofind;
    return done;
}
Пример #8
0
/**
 * @brief Handle dialog messages.
 * @param [in] hDlg Handle to the dialog.
 * @param [in] iMsg The message.
 * @param [in] wParam The command in the message.
 * @param [in] lParam The optional parameter for the command.
 * @return TRUE if the message was handled, FALSE otherwise.
 */
INT_PTR ReplaceDlg::DlgProc(HWindow *pDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    switch (iMsg)
    {
    case WM_INITDIALOG:
        // If there is selected data then make it the data to find.
        if (bSelected)
        {
            int sel_start = iGetStartOfSelection();
            int select_len = iGetEndOfSelection() - sel_start + 1;
            if (!transl_binary_to_text(&m_dataArray[sel_start], select_len))
            {
                MessageBox(pDlg, GetLangString(IDS_REPL_BAD_SELECT), MB_OK);
                pDlg->EndDialog(IDCANCEL);
                return TRUE;
            }
        }
        if (bPasteAsText)
            pDlg->CheckDlgButton(IDC_USETRANSLATION_CHECK, BST_UNCHECKED);
        else
            pDlg->CheckDlgButton(IDC_USETRANSLATION_CHECK, BST_CHECKED);
        if (char *pstr = strToReplaceData)
            pDlg->SetDlgItemTextA(IDC_TO_REPLACE_EDIT, pstr);
        if (char *pstr = strReplaceWithData)
            pDlg->SetDlgItemTextA(IDC_REPLACEWITH_EDIT, pstr);
        return TRUE;

    case WM_COMMAND:
        switch (wParam)
        {
        case IDCANCEL:
            bPasteAsText = pDlg->IsDlgButtonChecked(IDC_USETRANSLATION_CHECK) == BST_UNCHECKED;
            pDlg->EndDialog(wParam);
            return TRUE;

        case IDC_FINDNEXT_BUTTON:
            find_directed(pDlg, 1);
            break;

        case IDC_FINDPREVIOUS_BUTTON:
            find_directed(pDlg, -1);
            break;

        case IDC_FOLLOCC_BUTTON:
            replace_directed(pDlg, 1, true);
            break;

        case IDC_PREVOCC_BUTTON:
            replace_directed(pDlg, -1, true);
            break;

        case IDC_REPLACE_BUTTON:
            replace_directed(pDlg, 0, false);
            break;
        }
        break;

    case WM_HELP:
        OnHelp(pDlg);
        break;
    }
    return FALSE;
}
Пример #9
0
/**
 * @brief Paste the bytes.
 * @param [in] hDlg Handle to dialog.
 * @return TRUE if paste succeeded, FALSE if failed.
 */
BOOL PasteDlg::Apply(HWindow *pDlg)
{
	bPasteAsText = pDlg->IsDlgButtonChecked(IDC_PASTE_BINARY) == BST_CHECKED;
	iPasteTimes = pDlg->GetDlgItemInt(IDC_PASTE_TIMES);
	if (iPasteTimes <= 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_ATLEAST_ONCE), MB_ICONERROR);
		return FALSE;
	}
	iPasteSkip = pDlg->GetDlgItemInt(IDC_PASTE_SKIPBYTES);
	HEdit *pwndEdit1 = static_cast<HEdit *>(pDlg->GetDlgItem(IDC_PASTE_CLIPBOARD));
	int destlen = pwndEdit1->GetWindowTextLength() + 1;
	char *pcPastestring = new char[destlen];
	destlen = pwndEdit1->GetWindowTextA(pcPastestring, destlen);
	if (!bPasteAsText)
	{
		char *pc = 0;
		destlen = create_bc_translation((BYTE **)&pc, pcPastestring,
			static_cast<int>(strlen(pcPastestring)), iCharacterSet, iBinaryMode);
		delete [] pcPastestring;
		pcPastestring = pc;
	}
	if (destlen == 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_WAS_EMPTY), MB_ICONERROR);
		delete [] pcPastestring;
		return FALSE;
	}
	WaitCursor wc1;
	SimpleArray<BYTE> olddata;
	if (bSelected || pDlg->IsDlgButtonChecked(IDC_PASTE_INSERT))
	{
		// Insert at iCurByte. Bytes there will be pushed up.
		if (bSelected)
		{
			iCurByte = iGetStartOfSelection();
			int iEndByte = iGetEndOfSelection();
			olddata.AppendArray(&m_dataArray[iCurByte], iEndByte - iCurByte + 1 + (iPasteTimes - 1) * iPasteSkip);
			m_dataArray.RemoveAt(iCurByte, iEndByte - iCurByte + 1);//Remove extraneous data
			bSelected = false; // Deselect
		}
		else
		{
			olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * iPasteSkip);
		}
		int i = iCurByte;
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			if (!m_dataArray.InsertAtGrow(i, (BYTE*)pcPastestring, 0, destlen))
			{
				MessageBox(pDlg, GetLangString(IDS_PASTE_NO_MEM), MB_ICONERROR);
				break;
			}
			i += destlen + iPasteSkip;
		}
		bFilestatusChanged = true;
		resize_window();
	}
	else
	{
		// Overwrite.
		// Enough space for writing?
		// m_dataArray.GetLength()-iCurByte = number of bytes from including curbyte to end.
		if (m_dataArray.GetLength() - iCurByte < (iPasteSkip + destlen) * iPasteTimes)
		{
			MessageBox(pDlg, GetLangString(IDS_PASTE_NO_SPACE), MB_ICONERROR);
			delete [] pcPastestring;
			return TRUE;
		}
		olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
		// Overwrite data.
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			for (int i = 0 ; i < destlen ; i++)
			{
				m_dataArray[iCurByte + k * (iPasteSkip + destlen) + i] = pcPastestring[i];
			}
		}
		bFilestatusChanged = true;
		repaint();
	}
	push_undorecord(iCurByte, olddata, olddata.GetLength(), &m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
	delete [] pcPastestring;
	return TRUE;
}
Пример #10
0
/**
 * @brief Handle dialog messages.
 * @param [in] hDlg Handle to the dialog.
 * @param [in] iMsg The message.
 * @param [in] wParam The command in the message.
 * @param [in] lParam The optional parameter for the command.
 * @return TRUE if the message was handled, FALSE otherwise.
 */
INT_PTR FillWithDialog::DlgProc(HWindow* pDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	switch (iMsg)
	{
	case WM_INITDIALOG:
		{
			HEdit* pEditt = static_cast<HEdit *>(pDlg->GetDlgItem(IDC_HEX));//get the handle to the hex edit box
			pEditt->LimitText(FW_MAX);//limit the amount of text the user can enter
			pEditt->SetWindowText(pcFWText);//init hex text
			pEditt->SetFocus();//give the hex box focus
			pEditt->EnableWindow(!curtyp);
			oldproc = static_cast<LONG_PTR>(pEditt->SetWindowLongPtr(GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(HexProc)));//override the old proc to be HexProc
			EnableDlgItem(pDlg, IDC_HEXSTAT, !curtyp);

			HComboBox* typ = static_cast<HComboBox *>(pDlg->GetDlgItem(IDC_TYPE));
			typ->AddString(_T("Input"));
			typ->AddString(_T("File"));
			typ->SetCurSel(curtyp);//set cursel to previous

			//en/disable filename box and browse button
			HWindow* fn = pDlg->GetDlgItem(IDC_FN);
			fn->SetWindowText(szFWFileName);
			fn->EnableWindow(curtyp);
			EnableDlgItem(pDlg, IDC_BROWSE, curtyp);
			EnableDlgItem(pDlg, IDC_FILESTAT, curtyp);

			hfon = CreateFont(16, 0, 0, 0, FW_NORMAL, 0, 0, 0,
			                  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
			                  DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Symbol"));
			inittxt(pDlg);
			switch (asstyp)
			{
			case 0:
				pDlg->CheckDlgButton(IDC_EQ, BST_CHECKED);
				break;
			case 1:
				pDlg->CheckDlgButton(IDC_OR, BST_CHECKED);
				break;
			case 2:
				pDlg->CheckDlgButton(IDC_AND, BST_CHECKED);
				break;
			case 3:
				pDlg->CheckDlgButton(IDC_XOR, BST_CHECKED);
				break;
			}
			return 0;//stop the system from setting focus to the control handle in (HWND) wParam because we already set focus above
		}
	case WM_COMMAND:
		switch (wParam)
		{
		case IDOK: //ok pressed
			{
				if (curtyp)
				{//1-file
					pDlg->GetDlgItemText(IDC_FN, szFWFileName, _MAX_PATH);//get file name
					FWFile = _topen(szFWFileName, _O_RDONLY | _O_BINARY);
					if (FWFile == -1)
					{//if there is error opening
						MessageBox(pDlg, GetLangString(IDS_ERR_OPENING_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					FWFilelen = _filelength(FWFile);
					if (FWFilelen == 0)
					{//if filelen is zero
						MessageBox(pDlg, GetLangString(IDS_FILL_ZERO_SIZE_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						_close(FWFile);//close file
						return 1;//didn't process this message
					}//if
					else if (FWFilelen == -1)
					{//error returned by _filelength
						MessageBox(pDlg, GetLangString(IDS_ERR_OPENING_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						_close(FWFile);//close file
						return 1;//didn't process this message
					}//elseif
				}
				else
				{//0-input
					if (!buflen)
					{//no hex input
						MessageBox(pDlg, GetLangString(IDS_FILL_ZERO_SIZE_STR), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					int i = pDlg->GetDlgItemText(IDC_HEX, pcFWText, FW_MAX);
					if (i == 0 || i == FW_MAX - 1)
					{//error
						MessageBox(pDlg, GetLangString(IDS_FILL_TOO_MANY_BYTES), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					hexstring2charstring();//just in case
					//pcFWText[(aa?buflen:buflen*2)]='\0';//access violation if i do it in the above function
				}
				if (pDlg->IsDlgButtonChecked(IDC_EQ))
					asstyp = 0;
				else if (pDlg->IsDlgButtonChecked(IDC_OR))
					asstyp = 1;
				else if (pDlg->IsDlgButtonChecked(IDC_AND))
					asstyp = 2;
				else if (pDlg->IsDlgButtonChecked(IDC_XOR))
					asstyp = 3;

				// go ahead
				SetCursor(LoadCursor(nullptr, IDC_WAIT));
				BYTE (*fnc)(int);
				int iStartOfSelSetting;
				int iEndOfSelSetting;
				int iimax;
				if (curtyp)
				{//1-file
					fnc = file;
					iimax = FWFilelen;
				}//if
				else
				{//0-input
					fnc = input;
					iimax = buflen;
				}//else

				if (bSelected)
				{
					iStartOfSelSetting = iGetStartOfSelection();
					iEndOfSelSetting = iGetEndOfSelection();
				}
				else
				{
					iStartOfSelSetting = 0;
					iEndOfSelSetting = m_dataArray.GetUpperBound();
				}

				SimpleArray<BYTE> olddata(iEndOfSelSetting - iStartOfSelSetting + 1, &m_dataArray[iStartOfSelSetting]);
				int i = iStartOfSelSetting;
				int ii = 0;
				switch (asstyp)
				{// use switch instead of pointers to funcs that just call an operator as its faster
				case 0:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] = fnc(ii++);
						ii %= iimax;
					}
					break;
				case 1:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] |= fnc(ii++);
						ii %= iimax;
					}
					break;
				case 2:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] &= fnc(ii++);
						ii %= iimax;
					}
					break;
				case 3:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] ^= fnc(ii++);
						ii %= iimax;
					}
					break;
				}
				push_undorecord(iStartOfSelSetting, olddata, olddata.GetLength(), &m_dataArray[iStartOfSelSetting], olddata.GetLength());
				if (curtyp)
					_close(FWFile);//close file
				SetCursor(LoadCursor(nullptr, IDC_ARROW));
				bFilestatusChanged = true;
				repaint();//you tell me
			}
			// fall through
		case IDCANCEL: //cancel pressed
			DeleteObject(hfon);// won't need till next time
			pDlg->EndDialog(wParam);//tell CMD_fw not to carry out the fill with operation
			return 1;//did process this message
		case MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE):
			//thing to fill selection with changes
			curtyp = static_cast<char>(pDlg->SendDlgItemMessage(IDC_TYPE, CB_GETCURSEL, 0, 0));//get cursel
			EnableDlgItem(pDlg, IDC_FN, curtyp);//en/disable fnamebox and browse button
			EnableDlgItem(pDlg, IDC_BROWSE, curtyp);
			EnableDlgItem(pDlg, IDC_FILESTAT, curtyp);
			curtyp = !curtyp;//flip it for the others
			EnableDlgItem(pDlg, IDC_HEX, curtyp);//en/disable hexboxand relateds
			EnableDlgItem(pDlg, IDC_HEXSTAT, curtyp);
			curtyp = !curtyp;//restore original value -not for below -accurate value needed elsewhere
			//set text in boxes down below
			inittxt(pDlg);
			break;
		case IDC_BROWSE:
			{
				//prepare OPENFILENAME for the file open common dlg box
				szFWFileName[0] = '\0';
				OPENFILENAME ofn;
				ZeroMemory(&ofn, sizeof ofn);
				ofn.lStructSize = sizeof ofn;
				ofn.hwndOwner = pDlg->m_hWnd;
				ofn.lpstrFilter = GetLangString(IDS_OPEN_ALL_FILES);
				ofn.lpstrFile = szFWFileName;
				ofn.nMaxFile = _MAX_PATH ;
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
				//show open dlgbox and if file good save name & path in edit box
				if (GetOpenFileName(&ofn))
					pDlg->SetDlgItemText(IDC_FN, ofn.lpstrFile);
			}
			return TRUE;
		case MAKEWPARAM(IDC_HEX, EN_UPDATE): //hexedit updated
			pDlg->GetDlgItemText(IDC_HEX, pcFWText, FW_MAX);//gettext
			hexstring2charstring();//convert to char string
			//set text in boxes down below
			inittxt(pDlg);
			return TRUE;
		}
		break;

	case WM_HELP:
		OnHelp(pDlg);
		break;
	}
	return FALSE;
}
Пример #11
0
/**
 * @brief Paste the bytes.
 * @param [in] hDlg Handle to dialog.
 * @return TRUE if paste succeeded, FALSE if failed.
 */
BOOL PasteDlg::Apply(HWND hDlg)
{
	bPasteAsText = (IsDlgButtonChecked(hDlg, IDC_PASTE_BINARY) == BST_CHECKED);
	iPasteTimes = GetDlgItemInt(hDlg, IDC_PASTE_TIMES, 0, TRUE);
	if (iPasteTimes <= 0)
	{
		LangString atleastOnce(IDS_PASTE_ATLEAST_ONCE);
		MessageBox(hDlg, atleastOnce, MB_ICONERROR);
		return FALSE;
	}
	iPasteSkip = GetDlgItemInt(hDlg, IDC_PASTE_SKIPBYTES, 0, TRUE);
	HWND hwndEdit1 = GetDlgItem(hDlg, IDC_PASTE_CLIPBOARD);
	int destlen = GetWindowTextLength(hwndEdit1) + 1;
	TCHAR *pcPastestring = new TCHAR[destlen];
	destlen = GetWindowText(hwndEdit1, pcPastestring, destlen);
	if (!bPasteAsText)
	{
		BYTE *pc = 0;
		destlen = create_bc_translation(&pc, pcPastestring,
			_tcslen(pcPastestring), iCharacterSet, iBinaryMode);
		delete [] pcPastestring;
		pcPastestring = (TCHAR *) pc;
	}
	if (destlen == 0)
	{
		LangString zeroLenArray(IDS_PASTE_WAS_EMPTY);
		MessageBox(hDlg, zeroLenArray, MB_ICONERROR);
		delete [] pcPastestring;
		return FALSE;
	}

	// Choose to paste as Unicode text or ansi text regardless of build configuration,
	// TODO: UI not yet implemented.
	// ex) bool bPasteAsUnicode = IsDlgButtonChecked(hDlg, IDC_PASTE_AS_UNICODE))
	bool bPasteAsUnicode = false;
	BYTE *pasteData = (BYTE*) pcPastestring;
	int pasteSize = destlen * sizeof TCHAR;

	if (bPasteAsUnicode)
	{
		pasteData = new BYTE[destlen * sizeof WCHAR];
		pasteSize = WideCharToMultiByte(CP_ACP, 0, pcPastestring, destlen,
				(LPSTR) pasteData, destlen, NULL, NULL);
		if ( pasteSize > 0 ) {
			delete [] pcPastestring;
			pcPastestring = (TCHAR *) pasteData; // delete me later.
		}
	}

	WaitCursor wc1;
	if (bSelected || IsDlgButtonChecked(hDlg, IDC_PASTE_INSERT))
	{
		// Insert at iCurByte. Bytes there will be pushed up.
		if (bSelected)
		{
			iCurByte = iGetStartOfSelection();
			int iEndByte = iGetEndOfSelection();
			m_dataArray.RemoveAt(iCurByte, iEndByte - iCurByte + 1);//Remove extraneous data
			bSelected = false; // Deselect
		}
		int i = iCurByte;
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			if (!m_dataArray.InsertAtGrow(i, pasteData, 0, destlen))
			{
				LangString noMem(IDS_PASTE_NO_MEM);
				MessageBox(hDlg, noMem, MB_ICONERROR);
				break;
			}
			i += destlen + iPasteSkip;
		}
		iFileChanged = TRUE;
		bFilestatusChanged = true;
		resize_window();
	}
	else
	{
		// Overwrite.
		// Enough space for writing?
		// m_dataArray.GetLength()-iCurByte = number of bytes from including curbyte to end.
		if (m_dataArray.GetLength() - iCurByte < (iPasteSkip + destlen) * iPasteTimes)
		{
			LangString noSpace(IDS_PASTE_NO_SPACE);
			MessageBox(hDlg, noSpace, MB_ICONERROR);
			delete [] pcPastestring;
			return TRUE;
		}
		// Overwrite data.
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			for (int i = 0 ; i < destlen ; i++)
			{
				m_dataArray[iCurByte + k * (iPasteSkip + destlen) + i] = pasteData[i];
			}
		}
		iFileChanged = TRUE;
		bFilestatusChanged = true;
		repaint();
	}
	delete [] pcPastestring;
	return TRUE;
}