MCPcopy Create free account
hub / github.com/armvirus/SinMapper / main

Function main

SinMapper/SinMapper/main.cpp:4–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include "drv_image/drv_image.hpp"
3
4int main(int argument_count, char** argument_array)
5{
6 if (argument_count != 4 || std::filesystem::path(argument_array[1]).extension().string().compare(".sys") || std::filesystem::path(argument_array[2]).extension().string().compare(".sys"))
7 {
8 std::printf("[-] usage: sinmapper.exe driver.sys signed_driver.sys .section_name\n");
9 return -1;
10 }
11
12 if (std::filesystem::exists(argument_array[1]) == false)
13 {
14 std::printf("[-] driver [%s] does not exist\n", argument_array[1]);
15 return -1;
16 }
17
18 if (util::get_module_base(argument_array[2]))
19 {
20 std::printf("[-] signed driver [%s] already loaded\n", argument_array[2]);
21 return -1;
22 }
23
24 std::ifstream drv_buffer_str(argument_array[1], std::ios::binary);
25 std::vector<std::uint8_t>drv_buffer(std::istreambuf_iterator<char>(drv_buffer_str), {});
26
27 const auto nt_headers = portable_executable::get_nt_headers(drv_buffer.data());
28
29 if (nt_headers->Signature != IMAGE_NT_SIGNATURE)
30 {
31 std::printf("[-] invalid nt signature of target file\n");
32 return -1;
33 }
34
35 std::uint32_t image_size = nt_headers->OptionalHeader.SizeOfImage;
36
37 potential_drivers signed_driver = util::get_driver_info(argument_array[2], argument_array[3], image_size);
38
39 if (signed_driver.number_of_sections == 0)
40 {
41 std::printf("[-] failed to get info for potential driver.\n");
42 return -1;
43 }
44
45 NTSTATUS load_status = driver::load(signed_driver.file_path, signed_driver.file_name);
46 std::uintptr_t signed_module_base = util::get_module_base(signed_driver.file_name.c_str());
47
48 if ((load_status != STATUS_SUCCESS && load_status != 0x1) || !signed_module_base)
49 {
50 printf("[-] failed to load [%s] [0x%x]\n", signed_driver.file_name.c_str(), load_status);
51 return -1;
52 }
53
54 std::printf("[+] loaded [%s] at [%p] with result [0x%x]\n", signed_driver.file_name, signed_module_base, load_status);
55
56 std::uintptr_t start_map = signed_module_base + signed_driver.section_offset;
57
58 std::printf("[+] target section [%s] offset [0x%x] size [0x%x] map start [%p]\n\n", argument_array[3], signed_driver.section_offset, signed_driver.section_size, start_map);
59
60 static const auto kernel_base = util::get_module_base("ntoskrnl.exe");
61

Callers

nothing calls this directly

Calls 15

get_module_baseFunction · 0.85
get_nt_headersFunction · 0.85
get_driver_infoFunction · 0.85
loadFunction · 0.85
get_mi_pte_address_fnFunction · 0.85
get_mi_pde_address_fnFunction · 0.85
load_drvFunction · 0.85
get_file_headerFunction · 0.85
unload_drvFunction · 0.85
relocate_image_by_deltaFunction · 0.85
get_relocationsFunction · 0.85
resolve_importsFunction · 0.85

Tested by

no test coverage detected