#map #pe #client-server #manual-map

bin+lib mmap-loader

A Portable Executable manual map loader

15 releases

0.5.1 Apr 6, 2024
0.4.6 Aug 6, 2022
0.4.5 Mar 23, 2022
0.4.2 Oct 25, 2021

#4 in #pe

Download history 3/week @ 2024-02-23 2/week @ 2024-03-01 2/week @ 2024-03-08 2/week @ 2024-03-15 10/week @ 2024-03-29 203/week @ 2024-04-05

215 downloads per month

Custom license

110KB
1.5K SLoC

Contains (Windows DLL, 11KB) test/Foo.dll, (DOS exe, 2KB) test/baddos.exe, (DOS exe, 2KB) test/badentry.exe, (DOS exe, 6KB) test/badmod.exe, (DOS exe, 6KB) test/badproc.exe, (DOS exe, 2KB) test/badsection.exe and 3 more.

mmap-loader-rs

A Windows Portable Executable Manual Map Loader that supports both executable and DLL types. Written in Rust

Crate | Documentation (excl TLS)

Requirements

  • A 1.77.1+ stable compiler.

Features

  • Supports both DLL and EXE types
  • Remote or local PDB server for parsing out internal Windows functions
  • Supports C++ exceptions, vectored exception handling, and structured exception handling
  • Adds the entry to the loader structures, allowing support for functions such as GetModuleHandle, GetModuleFileName, and more
  • Allows for a module to be treated as a primary, resulting in calls to GetModuleHandle(null) to resolve to the mapped module
  • Unmaps the file and cleans up OS structures upon destruction for ephemeral executables
  • MSVC recognizes mapped executables and debugging of children is fully supported with symbols
  • Supports lazy execution, where multiple PE files can be loaded before any are executed
  • Returns control flow to the calling function after execution is complete

Feature Flags

  • server
    • enables a separate server component
  • tls
    • enables tls support for the client and server

Support

Let me know if something doesn't work by opening an issue. It has only been tested on Windows 10 20H2, and likely won't work on Windows 7 and prior. To see if it works on your system, run cargo test

Known Limitations

  • Docs.rs building with TLS support is broken due to this issue. Build docs locally with a compliant C compiler using cargo doc to view full documentation
  • 32-bit environments are not supported
  • GetModuleInformation and related functions will not find the loaded module. This is because the linked lists that are used to find the module for these functions are sanity checked and protected by the kernel, and the first access after modifying these structures would result in a fatal OS exception. A suggested alternative is to use VirtualQuery to get the size of allocation

Usage

Check out the examples

Dependencies

~11–24MB
~364K SLoC