📄 fx_plc_crackdlg.cpp
字号:
// FX_PLC_CRACKDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FX_PLC_CRACK.h"
#include "FX_PLC_CRACKDlg.h"
#include "SerialComDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFX_PLC_CRACKDlg dialog
CFX_PLC_CRACKDlg::CFX_PLC_CRACKDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFX_PLC_CRACKDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFX_PLC_CRACKDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFX_PLC_CRACKDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFX_PLC_CRACKDlg)
DDX_Control(pDX, IDC_EDIT_KEYWORD, m_edit_keyword);
DDX_Control(pDX, IDC_CB_PLCTYPE, m_cb_plctype);
DDX_Control(pDX, IDC_CB_COMPORT, m_cb_comport);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFX_PLC_CRACKDlg, CDialog)
//{{AFX_MSG_MAP(CFX_PLC_CRACKDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFX_PLC_CRACKDlg message handlers
BOOL CFX_PLC_CRACKDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_cb_comport.SetCurSel(0);
m_cb_plctype.SetCurSel(2);
return TRUE; // return TRUE unless you set the focus to a control
}
void CFX_PLC_CRACKDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFX_PLC_CRACKDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFX_PLC_CRACKDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFX_PLC_CRACKDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
ReadPwd();
}
void CFX_PLC_CRACKDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
BOOL CFX_PLC_CRACKDlg::ReadPwd()
{
m_edit_keyword.SetWindowText("");
CString comport;
/*char PLC_A[] = {0xA2,0x07,0x00,0xFF,0x02,0x05,0xAE,0x00,0x08,0xC3};
char PLC_FX2[] = {0x02,0x30,0x37,0x30,0x30,0x38,0x30,0x38,0x03,0x36,0x41};
char PLC_FX2N[] = {0x02,0x30,0x38,0x30,0x30,0x38,0x30,0x38,0x03,0x36,0x42};
*/
//char sendStr[16]={0};
CString sendStr;
m_cb_comport.GetWindowText(comport);
int type= m_cb_plctype.GetCurSel();
switch(type){
case 0://A
sendStr="\xA2\x07\x00\xFF\x02\x05\xAE\x00\x08\xC3";
//strcpy(sendStr, PLC_A);
break;
case 1://FX2
sendStr="\x02\x30\x37\x30\x30\x38\x30\x38\x03\x36\x41";
//sendStr="\STX0700808\ETX6A";
//strcpy(sendStr, PLC_FX2);
break;
case 2://FX1N/2N/1X/1S...
default:
sendStr="\x02\x30\x38\x30\x30\x38\x30\x38\x03\x36\x42";
//sendStr="\STX0800808\ETX6B";
//strcpy(sendStr, PLC_FX2N);
}
int ret=0;
if(!comport.IsEmpty()){
HANDLE hcom=Open((char*)(const char*) comport);
if(hcom!=NULL){
//setup comport
if(Setup(hcom, 9600,EVENPARITY, 7, ONESTOPBIT)<0) return FALSE;
//send string
ret= Write(hcom, (char*)(const char*)sendStr, strlen(sendStr));
//receive string
if(ret>0){
Sleep(200); //wait receive
char key[20]={0}, retkey[20]={0};
ret= Read(hcom, key);
if(ret>8){
if(type==0) //A
{
bool start= false;
int k=0, i=ret;
//char retkey[20]={0};
while(i>0)
{
if(key[i]==0xA4)//start password
{
start= true;
++i;
}
while(start){
retkey[k++]= key[i]&0xf;
retkey[k++]= (key[i]&0xf0)>>4;
}
if(key[i]==0xBB)//end password
break;
--i;
}
if(strlen(retkey)>0)
{
}
}
else //FX..
{
//char* retkey= ConvertHexToString(key, 20);
strcpy(retkey, ConvertHexToString(key, 20));
}
if(strlen(retkey)>0) {
m_edit_keyword.SetWindowText(retkey);
AfxMessageBox("Read Keyword Successfully!");
}
else
AfxMessageBox("Read Keyword Fail!");
}
else{
AfxMessageBox("Read Keyword Fail!");
}
}
else{
AfxMessageBox("Communication Fail!");
}
//close comport
Close(&hcom);
}
return TRUE;
}
return FALSE;
}
char* CFX_PLC_CRACKDlg::ConvertHexToString(char *str, int len)
{
char* retStr= new char[20];
memset(retStr, 0, 20);
int k=0;
for(int i=1; i<len; i+=2)
{
if(str[i]==03) break;
if(str[i]>=30 && str[i]<=92
&& str[i+1]>=30 && str[i+1]<=92)
{
retStr[k++]=(str[i]-0x30)*0x10+(str[i+1]-0x30);
}
}
return retStr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -