📄 protelcryptodlg.cpp
字号:
// ProtelCryptoDlg.cpp : 实现文件
//
#include "stdafx.h"
#include <windows.h>
#include <Winbase.h>
#include <CStringt.h>
#include ".\Cpryto.h"
#include "ProtelCrypto.h"
#include "ProtelCryptoDlg.h"
#include ".\protelcryptodlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//typedef CStringT< TCHAR, StrTraitATL< TCHAR > > CAtlString;
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// 对话框数据
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
// 实现
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CProtelCryptoDlg 对话框
CProtelCryptoDlg::CProtelCryptoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProtelCryptoDlg::IDD, pParent)
, strAltiumVerify(_T(""))
, strProduceLicense(_T(""))
, language(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
CCpryto CCpry=CCpryto();
}
void CProtelCryptoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT1, mCEdit);
DDX_Control(pDX, IDC_RADIO1, cbtChinese);
DDX_Control(pDX, IDOK, butVerifySignature);
DDX_Control(pDX, IDC_RADIO2, cbtEnglish);
DDX_Control(pDX, IDC_gboxLanguage, gboxLanguage);
DDX_Control(pDX, IDC_LicenseVerify, gboxLicenseVerify);
DDX_Control(pDX, IDC_BUTTON3, butIwesunLicense);
DDX_Control(pDX, IDC_ProduceLicense, gboxProduceLicense);
DDX_Control(pDX, IDC_BUTTON5, butImport);
DDX_Control(pDX, IDC_BUTTON2, butExport);
DDX_Control(pDX, IDC_KeyManage, gboxKeyManage);
DDX_Control(pDX, IDC_BUTTON9, butFlieVerify);
DDX_Control(pDX, IDC_BUTTON4, butKeyReplace);
DDX_Control(pDX, IDC_BUTTON6, butKeyComeback);
DDX_Control(pDX, IDC_BUTTON1, butGoodLuck);
DDX_Control(pDX, IDCANCEL, butBye);
DDX_Control(pDX, IDC_ProducteName, txtboxProducteName);
DDX_Control(pDX, IDC_LanBo, txtboxLanBo);
DDX_Radio(pDX, IDC_RADIO1, language);
}
BEGIN_MESSAGE_MAP(CProtelCryptoDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_EN_UPDATE(IDC_EDIT1, OnEnUpdateEdit1)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnBnClickedButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnBnClickedButton5)
ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio2)
ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio1)
ON_BN_CLICKED(IDC_BUTTON9, OnBnClickedButton9)
ON_BN_CLICKED(IDC_BUTTON6, OnBnClickedButton6)
END_MESSAGE_MAP()
// CProtelCryptoDlg 消息处理程序
BOOL CProtelCryptoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 将\“关于...\”菜单项添加到系统菜单中。
// IDM_ABOUTBOX 必须在系统命令范围内。
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
if(language==0)
strAboutMenu.LoadString(IDS_About);
else
strAboutMenu.LoadString(IDS_AboutEn);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
// 执行此操作
SetIcon(m_hIcon, TRUE); // 设置大图标
SetIcon(m_hIcon, FALSE); // 设置小图标
//cbtChinese.Attach
// TODO: 在此添加额外的初始化代码
SetReadme(0);
return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
}
void CProtelCryptoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
void CProtelCryptoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用于绘制的设备上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使图标在工作矩形中居中
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// 绘制图标
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CProtelCryptoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CProtelCryptoDlg::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
OnCancel();
}
void CProtelCryptoDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
char szFilters[]= "Protel 原版许可协议文件 (*.alf)|*.alf|All Files (*.*)|*.*||";
CFile LicenseFile;
CFileException fileException;
CString text;
DWORD len;
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "Protel2004", "*.alf", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
//CString pathName = fileDlg.GetPathName();
CString fileName = fileDlg.GetFileName () ;
// Implement opening and reading file in here.
//...
if ( LicenseFile.Open( fileName,CFile::modeRead, &fileException ) )
{
if(LicenseFile.GetLength()>0)
{
CCpry.oriText.length = LicenseFile.Read(CCpry.oriText.buffer, 4096);
LicenseFile.Close();
if(CCpry.Process(true))
{
if(language==0)text="这个文件可以能通过 Altium 认证,协议有效!\r\n";
else text="This file can pass the Altium Signature Verify,it is a Altium valid License!\r\n";
}
else
{
if(language==0)text="这个文件不能通过 Altium 认证,协议无效!\r\n";
else text="This file can't pass the Altium Signature Verify,it is a Altium invalid License!\r\n";
}
len=(CCpry.midText.buffer[3]<<24)|(CCpry.midText.buffer[2]<<16)|(CCpry.midText.buffer[1]<<8)|(CCpry.midText.buffer[0]);
//CCpry.midText.buffer[4+len]=0;
text+=CString((char*)&CCpry.midText.buffer[4],(int)len);
mCEdit.SetWindowText(text);
}
}else
{
TRACE( "Can't open file %s, error = %u\n",
fileName, fileException.m_cause );
}
//Change the window's title to the opened file's title.
SetWindowText(fileName);
}
//OnOK();
}
void CProtelCryptoDlg::OnEnUpdateEdit1()
{
// TODO: 如果该控件是 RICHEDIT 控件,则它将不会
// 发送该通知,除非重写 CDialog::OnInitDialog()
// 函数,将 EM_SETEVENTMASK 消息发送到控件,
// 同时将 ENM_UPDATE 标志“或”运算到 lParam 掩码中。
// TODO: 在此添加控件通知处理程序代码
}
void CProtelCryptoDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
void CProtelCryptoDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
int i,j;
CFile fileKeyText;
CFileException fileException;
CString txtbuffer;
CString fileName;
char sgn[]="[IWESUN]\r\nIWESUN DXP2004 License File by iwesun@hotmail.com\r\n";
char szFilters[]= "IWESUN License File (*.alf)|*.alf|All Files (*.*)|*.*||";
j=sizeof(sgn)-1;
for(i=0;i<j;i++)CCpry.oriText.buffer[4+i]=sgn[i];
i=mCEdit.GetWindowText((LPTSTR)&(CCpry.oriText.buffer[4+j]),4096)+j;
if(i>0)
{
CCpry.oriText.buffer[0]=i &0xff;
CCpry.oriText.buffer[1]=(i>>8) &0xff;
CCpry.oriText.buffer[2]=(i>>16) &0xff;
CCpry.oriText.buffer[3]=(i>>24) &0xff;
i=i+4;
if((CCpry.oriText.buffer[i-2]!=0x0d)||(CCpry.oriText.buffer[i-1]!=0x0a))
{
if(CCpry.oriText.buffer[i-1]==0x0d)
{
CCpry.oriText.buffer[i]=0x0a;i++;
}else if(CCpry.oriText.buffer[i-1]==0x0a)
{
CCpry.oriText.buffer[i-1]=0x0d;
CCpry.oriText.buffer[i]=0x0a;i++;
}else
{
CCpry.oriText.buffer[i]=0x0d;i++;
CCpry.oriText.buffer[i]=0x0a;i++;
}
}
CCpry.oriText.buffer[i]=0x0;CCpry.oriText.length =i;
mCEdit.SetWindowText(CString(&CCpry.oriText.buffer[4]));
txtbuffer=CCpry.Process3();
if(txtbuffer.GetLength()>0)
{
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (false, "IWESUN2004", "*.alf", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
if( fileDlg.DoModal ()==IDOK )
{ //CString pathName = fileDlg.GetPathName();
fileName = fileDlg.GetFileName () ;
if(fileKeyText.Open(fileName,CFile::modeCreate|CFile::modeWrite,&fileException))
{
fileKeyText.Write(txtbuffer,txtbuffer.GetLength());
fileKeyText.Close();
MessageBox(fileName +" License file Succeed! ",MB_OK);
}else
{
//显示错误信息
MessageBox(fileName +" License file false! ",MB_OK);
}
}
}else
{
//显示错误信息
MessageBox(fileName +" File is empty! ",MB_OK);
}
}else
{
MessageBox("Data is empty! ","Error",MB_OK|MB_ICONERROR);
}
}
void CProtelCryptoDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
char szFilters[]= "IWESUN License Files (*.alf)|*.alf|All Files (*.*)|*.*||";
CFile LicenseFile;
CFileException fileException;
CString text;
DWORD len;
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "IWESUN2004", "*.alf", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
//CString pathName = fileDlg.GetPathName();
CString fileName = fileDlg.GetFileName () ;
// Implement opening and reading file in here.
//...
if ( LicenseFile.Open( fileName,CFile::modeRead|CFile::shareDenyNone , &fileException ) )
{
if(LicenseFile.GetLength()>0)
{
CCpry.oriText.length = LicenseFile.Read(CCpry.oriText.buffer, 4096);
LicenseFile.Close();
if(CCpry.Process(false))
{
if(language==0)text="这个文件可以能通过 IWESUN 认证,协议有效!\r\n";
else text="This File can pass the IWESUN Signature Verify,it is a Altium valid License!\r\n";
}
else
{
if(language==0)text="这个文件不能通过 IWESUN 认证,协议无效!\r\n";
else text="This File can't pass the IWESUN Signature Verify,it is a Altium invalid License!\r\n";
}
len=(CCpry.midText.buffer[3]<<24)|(CCpry.midText.buffer[2]<<16)|(CCpry.midText.buffer[1]<<8)|(CCpry.midText.buffer[0]);
CCpry.midText.buffer[4+len]=0;
text+=CString((char*)&CCpry.midText.buffer[4],(int)len);
mCEdit.SetWindowText(text);
}
}else
{
TRACE( "Can't open file %s, error = %u\n",
fileName, fileException.m_cause );
}
//Change the window's title to the opened file's title.
SetWindowText(fileName);
}
}
void CProtelCryptoDlg::OnBnClickedButton4()
{
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
// TODO: 在此添加控件通知处理程序代码
// szFilters is a text string that includes two file name filters:
// "*.my" for "MyType Files" and "*.*' for "All Files."
char szFilters[]= "Protel DXP Exe Files (*.exe)|*.exe|All Files (*.*)|*.*||";
CFile exeFile;
CFileException fileException;
CString strFile;
BYTE *fileData;
DWORD flieLength;
DWORD it;
//int flieLength;
int i,type;
bool flag;
DWORD address;
CString fileName;
CString fileName2;
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "C:\\Program Files\\Altium2004\\DXP.exe", "*.exe", OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
//CString pathName = fileDlg.GetPathName();
fileName = fileDlg.GetFileName () ;
// Implement opening and reading file in here.
//...
if ( exeFile.Open( fileName,CFile::modeReadWrite|CFile::typeBinary|CFile::shareDenyWrite,&fileException ) )
{
flieLength=exeFile.GetLength();
if(flieLength!=0)
{
//--------------------------------------------------------------------
// 检查 fileData 空间.
if(fileData = (BYTE*)malloc(flieLength))
{
TRACE("fileData 空间允许. \n");
flieLength =exeFile.Read(fileData,flieLength);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -