summaryrefslogtreecommitdiff
path: root/sysmap/src/main.cpp
blob: d775e6c24eb5ea2bb8c8ecbfbb14b194b829ba3f (plain) (blame)
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
#include "include.h"
#include "io.h"
#include "mapper/util.h"
#include "mapper/pe.h"

#include "context.h"

#include "mapper/syscalls.h"
#include "mapper/apiset.h"

#include "mapper/process.h"

mapper_context_t g_ctx;
syscalls_t g_syscalls;
apiset_t g_apiset;


int main(int argc, char* argv[]) {
	std::vector<std::string> args;
	
	for (int i = 1; i < argc; ++i) {
		args.emplace_back(argv[i]);
	}

	if (args.size() < 2) {
		io::log<critical>("Invalid arguments specified.");
		std::cin.get();

		return 0;
	}

	for (auto& arg : args) {
		if (arg == "--debug") {
			spdlog::set_level(spdlog::level::debug);
		}
	}

	spdlog::set_pattern("[%^%l%$] %v");
	spdlog::set_level(spdlog::level::debug);

	g_ctx.local_modules = std::move(util::get_modules());

	auto ntdll = g_ctx.local_modules[1];

	g_ctx.win_path = ntdll.full_path.substr(0, ntdll.full_path.size() - ntdll.name.size());

	g_syscalls.init();

	io::log<info>("waiting for {}", args[0]);

	auto buf = io::read_file(args[1]);
	if (buf.empty()) {
		io::log<critical>("failed to read file.");
		std::cin.get();

		return 0;
	}

	process::process_x64_t proc;
	if (NT_SUCCESS(proc.attach(args[0]))) {
		io::log<info>("attached!");

		proc.modules = proc.get_modules();

		proc.map(buf);

		proc.close(proc.handle);
	}

	std::cin.get();
	return 0;
}