-
Notifications
You must be signed in to change notification settings - Fork 1
/
shell_code.hpp
50 lines (43 loc) · 1.11 KB
/
shell_code.hpp
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
#pragma once
#include <iostream>
#include <Windows.h>
class shell_code {
private:
uint8_t* buffer{};
size_t buffer_size = 0;
public:
shell_code() {
buffer = reinterpret_cast<uint8_t*>(VirtualAlloc(nullptr, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));
}
~shell_code() {
VirtualFree(buffer, 0, MEM_RELEASE);
}
template<typename T>
void make(const T& v) {
if constexpr (std::is_same<T, int>::value) {
*reinterpret_cast<uint8_t*>(buffer + buffer_size) = *reinterpret_cast<const uint8_t*>(&v);
buffer_size += sizeof(uint8_t);
}
else {
*reinterpret_cast<T*>(buffer + buffer_size) = v;
buffer_size += sizeof(T);
}
}
template<typename F, typename... R>
void make(const F& first, const R&... rest)
{
make(first);
make(rest...);
}
void get(uint8_t* getter) {
for (size_t i = 0; i < buffer_size; i++) {
getter[i] = buffer[i];
}
}
void* get() {
return buffer;
}
size_t size() {
return buffer_size;
}
};