⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maindialog.cpp

📁 文件加密解密源代码
💻 CPP
字号:
/*
	Application Main Dialog Implementation.
*/

#include "stdafx.h"
#include "MainDialog.h"
#include "Files/GenFiles.h"
#include "Security/FileWipe.h"
#include "../FileEnc/Processing.h" // FileEnc
#include "Files/SelfExtract.h"

MainDialog::MainDialog()
{
}

MainDialog::~MainDialog()
{
	char garbage[111];
	FillMemory(garbage, 110, 'A');
	garbage[110] = 0;
	
	SetDlgItemText(ID_DECPASSWORD, garbage);
	
	DestroyWindow();
}

LRESULT MainDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	GenLib::SelfExtract selfCheck(0);

	if (!selfCheck.checkSignature()) 
	{
		MessageBox("Self Extract utility do NOT have any content, exitting!", "Error", MB_ICONERROR);
		PostQuitMessage(0);
	}

	return 1;  // Let the system set the focus
}

LRESULT MainDialog::OnCloseDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	PostQuitMessage(0);
	return 1;
}

LRESULT MainDialog::OnBnClickedDecryptButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	// detecting the temporary directory and writing there the encrypted file (temporary).
	char *tempFile = Processing::generateTempFile();

	// extracting file to temporary location
	char *originalFile = writeInternalFile(tempFile);

	if (originalFile == 0)
	{
		MessageBox("Error unpacking internal file", "Error", MB_ICONERROR);
		delete tempFile;
		return 0;
	}

	char resultFile[MAX_PATH];

	// extract filename from exe.
	strcpy(resultFile, originalFile);
	delete originalFile;
	originalFile = 0;

	if (!GenLib::GenFiles::fileDialog(GenLib::GenFiles::SAVE_FILE_DIALOG, m_hWnd, "Chooose Destination File", "All Files (*.*)\0*.*\0\0", resultFile, MAX_PATH))
	{
		GenLib::FileWipe::wipeFile(tempFile);
		delete tempFile;
		return 0;
	}
	
	char password[110];
	GetDlgItemText(ID_DECPASSWORD, password, 110);
	password[109] = 0;

	if (strlen(password) > 56)
	{
		MessageBox("Password length should be maximum 56 characters!", "Error");
		ZeroMemory(password, 110);
		delete tempFile;
		return 0;
	}
	
	if (strlen(password) < 5)
	{
		MessageBox("Password length should be at least 5 characters!", "Error");
		ZeroMemory(password, 110);
		delete tempFile;
		return 0;
	}
	
	Processing processing(DECRYPT_METHOD, resultFile, tempFile, password);
	processing.DoModal();

	GenLib::FileWipe::wipeFile(tempFile);
	ZeroMemory(password, 110);
	
	delete tempFile;
	return 0;
}

LRESULT MainDialog::OnBnClickedQuitButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	PostQuitMessage(0);
	return 0;
}

char *MainDialog::writeInternalFile(const char *filename)
{
	GenLib::SelfExtract detacher(0);
	detacher.detachFile(filename);

	char *originalFile = new char[MAX_PATH];

	strncpy(originalFile, detacher.getDetached(), MAX_PATH);

	return originalFile;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -