-
Notifications
You must be signed in to change notification settings - Fork 11
/
util.h
130 lines (96 loc) · 2.68 KB
/
util.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
util.cpp
Purpose: miscellaneous utility library
@author Austin J
@version 1.1 4/26/2016
*/
#ifndef UTIL_H
#define UTIL_H
#include <Windows.h>
#include <stdio.h>
#include <string>
#include <vector>
#include <sstream>
#include <fstream>
#include <TlHelp32.h>
#define DLURL_SUCCESS 0
#define DLURL_FAILED_REQUEST 1
#define DLURL_FAILED_CERT_QUERY 2
#define DLURL_FAILED_CERT_CHECK 3
// athread
namespace util {
class athread {
private:
HANDLE thread;
int threadID;
public:
athread(void* func, void* args);
int terminate();
int wait();
HANDLE getThread();
int getExitCode();
int getThreadId();
int running();
};
class timer {
private:
unsigned __int64 _starting_tick;
unsigned __int64 _finish_tick;
public:
timer() { Reset(); }
/* resets the timer */
void Reset() {
_starting_tick = 0;
_finish_tick = 0;
}
/* starts the timer */
void Start() {
Reset();
_starting_tick = GetTickCount64();
}
/* stops the timer and returns the elapsed time */
double Stop() {
_finish_tick = GetTickCount64();
return GetElapsedTime();
}
/* returns elapsed time */
double GetElapsedTime() {
if (_starting_tick & _finish_tick)
return (_finish_tick - _starting_tick) / 1000.0;
return 0.0;
}
};
template <typename T>
class singleton {
private:
static T* _instance;
public:
static T* instance() {
if (_instance)
return _instance;
_instance = new T;
return _instance;
}
singleton(singleton const&) = delete;
void operator=(singleton const&) = delete;
};
// other
void GetFile(const char* dllName, const char* fileName, char* buffer, int bfSize);
long int GetFileSize(FILE* ifile);
int DownloadURL(const std::string& server, const std::string& path, const std::string& params, std::string& out, unsigned char useSSL, unsigned char dontCache, unsigned char direct);
int ReadFile(const std::string& path, std::string& out, unsigned char binary);
int WriteFile(const std::string& path, std::string data, unsigned char binary);
std::vector<std::string> GetArguments(std::string input);
int GetProcessByImageName(const char* imageName);
std::string lowercase(std::string& input);
std::wstring s2ws(const std::string& str);
std::string ws2s(const std::wstring& wstr);
std::string GetRawStringAtDelim(std::string input, int arg, char delim);
void GetFilesInDirectory(std::vector<std::string> &out, const std::string &directory, unsigned char includePath);
int GetEIP();
void pause();
namespace registry {
int ReadString(HKEY key, const char* value, std::string& out);
}
};
#endif