summaryrefslogtreecommitdiff
path: root/loader/server/manual_map.cpp
blob: d2de29cf0662f4b72cb5f2d31f1a8b231e954d15 (plain)
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
#include "manual_map.hpp"

namespace inject {
	// pe file implementation
	c_pe_file::c_pe_file(const char *file) {
		std::ifstream pe_file(file, std::ifstream::in | std::ifstream::binary);

		if (!pe_file.is_open()) {
			printf("file (%s) does not exist\n", file);
			return;
		}

		pe_file.seekg(0, pe_file.end);

		uint32_t pe_size = pe_file.tellg();
		m_file.resize(pe_size);

		pe_file.seekg(0, pe_file.beg);
		
		// HOMOSEXUAL CAST FUCKERY PLEASE SKIP THIS LINE
		// AAAAAAAAAAAA BAD
		pe_file.read((char*)&m_file[0], pe_size);

		pe_file.close();
	}

	bool c_pe_file::valid() {
		nt::dos_header_t *dos_header;
		nt::nt_headers_t *nt_headers;

		// check dos header
		dos_header = reinterpret_cast<decltype(dos_header)>((uint32_t)data());

		if (dos_header->e_magic != 0x45DA)
			return false;

		// check nt header
		nt_headers = reinterpret_cast<decltype(nt_headers)>((uint32_t)data() + dos_header->e_lfanew);

		if (nt_headers->signature != 0x50450000)
			return false; 

		return true;
	}

	uint8_t *c_pe_file::data() {
		// go to the beginning of the file
		// yes i know i could've just done 'new uint8_t[pe_size]' but fuck u.
		return reinterpret_cast<uint8_t *>(&m_file[0]);
	}
	
	size_t c_pe_file::size() const {
		return m_file.size();
	}
}