fixing bug in relocation that prevented e.g. the use of AuxKlibInitialize

merge-requests/1/head
TomSie 3 years ago
parent 825c4a212b
commit 1d7b85ce19

5
.gitignore vendored

@ -0,0 +1,5 @@
.vs/
drv_example/x64/
HMDM-MSREXEC/x64/
HMDM-VDM/x64/
x64/

@ -54,7 +54,7 @@ namespace drv
return { {}, {} }; return { {}, {} };
resolve_imports(image_mapped); resolve_imports(image_mapped);
fix_relocs(image_mapped); fix_relocs(image_mapped, alloc_base);
if (zero_headers) if (zero_headers)
{ {
@ -83,7 +83,7 @@ namespace drv
}; };
} }
auto hmdm_ctx::fix_relocs(drv_buffer_t& drv_buffer) const -> void auto hmdm_ctx::fix_relocs(drv_buffer_t& drv_buffer, uint8_t* alloc_base) const -> void
{ {
const auto dos_header = const auto dos_header =
reinterpret_cast<PIMAGE_DOS_HEADER>(drv_buffer.data()); reinterpret_cast<PIMAGE_DOS_HEADER>(drv_buffer.data());
@ -128,7 +128,7 @@ namespace drv
const auto rva = reinterpret_cast<std::uintptr_t*>(reloc_base + offset); const auto rva = reinterpret_cast<std::uintptr_t*>(reloc_base + offset);
*rva = reinterpret_cast<std::uintptr_t>( *rva = reinterpret_cast<std::uintptr_t>(
drv_buffer.data() + (*rva - nt_header->OptionalHeader.ImageBase)); alloc_base + (*rva - nt_header->OptionalHeader.ImageBase));
break; break;
} }
default: default:

@ -25,6 +25,6 @@ namespace drv
const kmemcpy_t kmemcpy; const kmemcpy_t kmemcpy;
private: private:
auto resolve_imports(drv_buffer_t& drv_buffer) const -> void; auto resolve_imports(drv_buffer_t& drv_buffer) const -> void;
auto fix_relocs(drv_buffer_t& drv_buffer) const -> void; auto fix_relocs(drv_buffer_t& drv_buffer, uint8_t* alloc_base) const -> void;
}; };
} }

@ -54,7 +54,7 @@ namespace drv
return { {}, {} }; return { {}, {} };
resolve_imports(image_mapped); resolve_imports(image_mapped);
fix_relocs(image_mapped); fix_relocs(image_mapped, alloc_base);
if (zero_headers) if (zero_headers)
{ {
@ -83,7 +83,7 @@ namespace drv
}; };
} }
auto hmdm_ctx::fix_relocs(drv_buffer_t& drv_buffer) const -> void auto hmdm_ctx::fix_relocs(drv_buffer_t& drv_buffer, uint8_t* alloc_base) const -> void
{ {
const auto dos_header = const auto dos_header =
reinterpret_cast<PIMAGE_DOS_HEADER>(drv_buffer.data()); reinterpret_cast<PIMAGE_DOS_HEADER>(drv_buffer.data());
@ -128,7 +128,7 @@ namespace drv
const auto rva = reinterpret_cast<std::uintptr_t*>(reloc_base + offset); const auto rva = reinterpret_cast<std::uintptr_t*>(reloc_base + offset);
*rva = reinterpret_cast<std::uintptr_t>( *rva = reinterpret_cast<std::uintptr_t>(
drv_buffer.data() + (*rva - nt_header->OptionalHeader.ImageBase)); alloc_base + (*rva - nt_header->OptionalHeader.ImageBase));
break; break;
} }
default: default:

@ -25,6 +25,6 @@ namespace drv
const kmemcpy_t kmemcpy; const kmemcpy_t kmemcpy;
private: private:
auto resolve_imports(drv_buffer_t& drv_buffer) const -> void; auto resolve_imports(drv_buffer_t& drv_buffer) const -> void;
auto fix_relocs(drv_buffer_t& drv_buffer) const -> void; auto fix_relocs(drv_buffer_t& drv_buffer, uint8_t* alloc_base) const -> void;
}; };
} }
Loading…
Cancel
Save